From 6ba084db4ba375eacaa1677fd75de318c12170c7 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 6 Jul 2020 23:04:10 -0400 Subject: Bump acap to 0.2.0 This requires adapting to the new k-d trees, which are significantly faster. --- Cargo.lock | 9 ++++----- Cargo.toml | 2 +- src/color.rs | 39 ++++----------------------------------- src/frontier.rs | 18 ++++-------------- src/frontier/image.rs | 10 ++++++++-- src/frontier/mean.rs | 15 ++++++++++++--- src/frontier/min.rs | 15 ++++++++++++--- src/main.rs | 5 ++++- 8 files changed, 49 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e3eaa1d..780d715 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,11 @@ # It is not intended for manual editing. [[package]] name = "acap" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881ff84781a207a949e7663c7990fe98b9826bb961a2389f8672986c34177da9" +checksum = "db6a9cbe22aa4d86f22bb1e4bd33bd371d3ee6057d52e8121b5ea2cf9ef9176d" dependencies = [ "num-traits", - "rand", ] [[package]] @@ -362,9 +361,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" dependencies = [ "autocfg", ] diff --git a/Cargo.toml b/Cargo.toml index c1a4bc6..cf42171 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Tavian Barnes "] edition = "2018" [dependencies] -acap = "0.1.0" +acap = "0.2.0" clap = "2.33.1" image = "0.23.6" rand = "0.7.3" diff --git a/src/color.rs b/src/color.rs index ff113a7..81d9689 100644 --- a/src/color.rs +++ b/src/color.rs @@ -3,7 +3,7 @@ pub mod order; pub mod source; -use acap::coords::{Coordinates, CoordinateMetric, CoordinateProximity}; +use acap::coords::Coordinates; use acap::distance::{Metric, Proximity}; use acap::euclid::{EuclideanDistance, euclidean_distance}; @@ -15,10 +15,9 @@ use std::ops::Index; pub type Rgb8 = Rgb; /// A [color space](https://en.wikipedia.org/wiki/Color_space). -pub trait ColorSpace: Copy + From - + Coordinates - + Metric - + CoordinateMetric<::Value, Distance = ::Distance> +pub trait ColorSpace: Copy + From + Coordinates + Metric +where + Self::Value: PartialOrd, { /// Compute the average of the given colors. fn average>(colors: I) -> Self; @@ -68,16 +67,6 @@ impl Proximity for RgbSpace { impl Metric for RgbSpace {} -impl CoordinateProximity for RgbSpace { - type Distance = EuclideanDistance; - - fn distance_to_coords(&self, other: &[f64]) -> Self::Distance { - euclidean_distance(&self.0, other) - } -} - -impl CoordinateMetric for RgbSpace {} - impl ColorSpace for RgbSpace { fn average>(colors: I) -> Self { let mut sum = [0.0, 0.0, 0.0]; @@ -194,16 +183,6 @@ impl Proximity for LabSpace { impl Metric for LabSpace {} -impl CoordinateProximity for LabSpace { - type Distance = EuclideanDistance; - - fn distance_to_coords(&self, other: &[f64]) -> Self::Distance { - euclidean_distance(&self.0, other) - } -} - -impl CoordinateMetric for LabSpace {} - impl ColorSpace for LabSpace { fn average>(colors: I) -> Self { let mut sum = [0.0, 0.0, 0.0]; @@ -280,16 +259,6 @@ impl Proximity for LuvSpace { impl Metric for LuvSpace {} -impl CoordinateProximity for LuvSpace { - type Distance = EuclideanDistance; - - fn distance_to_coords(&self, other: &[f64]) -> Self::Distance { - euclidean_distance(&self.0, other) - } -} - -impl CoordinateMetric for LuvSpace {} - impl ColorSpace for LuvSpace { fn average>(colors: I) -> Self { let mut sum = [0.0, 0.0, 0.0]; diff --git a/src/frontier.rs b/src/frontier.rs index 74c7398..ccc3efa 100644 --- a/src/frontier.rs +++ b/src/frontier.rs @@ -4,10 +4,10 @@ pub mod image; pub mod mean; pub mod min; -use crate::color::{ColorSpace, Rgb8}; +use crate::color::Rgb8; use crate::soft::SoftDelete; -use acap::coords::{Coordinates, CoordinateMetric, CoordinateProximity}; +use acap::coords::Coordinates; use acap::distance::{Proximity, Metric}; use std::cell::Cell; @@ -40,7 +40,7 @@ struct Pixel { deleted: Cell, } -impl Pixel { +impl Pixel { fn new(x: u32, y: u32, color: C) -> Self { Self { pos: (x, y), @@ -58,7 +58,7 @@ impl Pixel { #[derive(Clone, Debug)] struct RcPixel(Rc>); -impl RcPixel { +impl RcPixel { fn new(x: u32, y: u32, color: C) -> Self { Self(Rc::new(Pixel::new(x, y, color))) } @@ -136,16 +136,6 @@ impl Coordinates for Target { } } -impl> CoordinateProximity for Target { - type Distance = C::Distance; - - fn distance_to_coords(&self, coords: &[T]) -> Self::Distance { - self.0.distance_to_coords(coords) - } -} - -impl> CoordinateMetric for Target {} - impl Proximity for RcPixel { type Distance = C::Distance; diff --git a/src/frontier/image.rs b/src/frontier/image.rs index 18bf620..8b4c233 100644 --- a/src/frontier/image.rs +++ b/src/frontier/image.rs @@ -19,7 +19,10 @@ pub struct ImageFrontier { deleted: usize, } -impl ImageFrontier { +impl ImageFrontier +where + C::Value: PartialOrd, +{ /// Create an ImageFrontier from an image. pub fn new(img: &RgbImage) -> Self { let width = img.width(); @@ -39,7 +42,10 @@ impl ImageFrontier { } } -impl Frontier for ImageFrontier { +impl Frontier for ImageFrontier +where + C::Value: PartialOrd, +{ fn width(&self) -> u32 { self.width } diff --git a/src/frontier/mean.rs b/src/frontier/mean.rs index 3c441b8..e59e45c 100644 --- a/src/frontier/mean.rs +++ b/src/frontier/mean.rs @@ -17,7 +17,10 @@ enum MeanPixel { Filled(C), } -impl MeanPixel { +impl MeanPixel +where + C::Value: PartialOrd, +{ fn filled_color(&self) -> Option { match self { Self::Filled(color) => Some(*color), @@ -37,7 +40,10 @@ pub struct MeanFrontier { deleted: usize, } -impl MeanFrontier { +impl MeanFrontier +where + C::Value: PartialOrd, +{ /// Create a MeanFrontier with the given dimensions and initial pixel location. pub fn new(width: u32, height: u32, x0: u32, y0: u32) -> Self { let size = (width as usize) * (height as usize); @@ -117,7 +123,10 @@ impl MeanFrontier { } } -impl Frontier for MeanFrontier { +impl Frontier for MeanFrontier +where + C::Value: PartialOrd, +{ fn width(&self) -> u32 { self.width } diff --git a/src/frontier/min.rs b/src/frontier/min.rs index 95b3321..5c298e7 100644 --- a/src/frontier/min.rs +++ b/src/frontier/min.rs @@ -16,7 +16,10 @@ struct MinPixel { filled: bool, } -impl MinPixel { +impl MinPixel +where + C::Value: PartialOrd, +{ fn new() -> Self { Self { pixel: None, @@ -39,7 +42,10 @@ pub struct MinFrontier { deleted: usize, } -impl MinFrontier { +impl MinFrontier +where + C::Value: PartialOrd, +{ /// Create a MinFrontier with the given dimensions and initial pixel location. pub fn new(rng: R, width: u32, height: u32, x0: u32, y0: u32) -> Self { let size = (width as usize) * (height as usize); @@ -122,7 +128,10 @@ impl MinFrontier { } } -impl Frontier for MinFrontier { +impl Frontier for MinFrontier +where + C::Value: PartialOrd, +{ fn width(&self) -> u32 { self.width } diff --git a/src/main.rs b/src/main.rs index ce54939..ae8c35d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -355,7 +355,10 @@ impl App { } } - fn paint(&mut self, colors: Vec) -> AppResult<()> { + fn paint(&mut self, colors: Vec) -> AppResult<()> + where + C::Value: PartialOrd, + { let width = self.width.unwrap(); let height = self.height.unwrap(); let x0 = self.args.x0.unwrap_or(width / 2); -- cgit v1.2.3