diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2020-07-06 23:04:10 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2020-08-24 11:10:13 -0400 |
commit | 6ba084db4ba375eacaa1677fd75de318c12170c7 (patch) | |
tree | 9122e889fcc47d8f6ebd71717a8cb35a98ebafdb /src | |
parent | 39c0348c9f98b4dd29bd112a0a2a42faa67c92d4 (diff) | |
download | kd-forest-6ba084db4ba375eacaa1677fd75de318c12170c7.tar.xz |
Bump acap to 0.2.0
This requires adapting to the new k-d trees, which are significantly
faster.
Diffstat (limited to 'src')
-rw-r--r-- | src/color.rs | 39 | ||||
-rw-r--r-- | src/frontier.rs | 18 | ||||
-rw-r--r-- | src/frontier/image.rs | 10 | ||||
-rw-r--r-- | src/frontier/mean.rs | 15 | ||||
-rw-r--r-- | src/frontier/min.rs | 15 | ||||
-rw-r--r-- | src/main.rs | 5 |
6 files changed, 44 insertions, 58 deletions
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<u8>; /// A [color space](https://en.wikipedia.org/wiki/Color_space). -pub trait ColorSpace: Copy + From<Rgb8> - + Coordinates - + Metric - + CoordinateMetric<<Self as Coordinates>::Value, Distance = <Self as Proximity>::Distance> +pub trait ColorSpace: Copy + From<Rgb8> + Coordinates + Metric +where + Self::Value: PartialOrd<Self::Distance>, { /// Compute the average of the given colors. fn average<I: IntoIterator<Item = Self>>(colors: I) -> Self; @@ -68,16 +67,6 @@ impl Proximity for RgbSpace { impl Metric for RgbSpace {} -impl CoordinateProximity<f64> for RgbSpace { - type Distance = EuclideanDistance<f64>; - - fn distance_to_coords(&self, other: &[f64]) -> Self::Distance { - euclidean_distance(&self.0, other) - } -} - -impl CoordinateMetric<f64> for RgbSpace {} - impl ColorSpace for RgbSpace { fn average<I: IntoIterator<Item = Self>>(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<f64> for LabSpace { - type Distance = EuclideanDistance<f64>; - - fn distance_to_coords(&self, other: &[f64]) -> Self::Distance { - euclidean_distance(&self.0, other) - } -} - -impl CoordinateMetric<f64> for LabSpace {} - impl ColorSpace for LabSpace { fn average<I: IntoIterator<Item = Self>>(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<f64> for LuvSpace { - type Distance = EuclideanDistance<f64>; - - fn distance_to_coords(&self, other: &[f64]) -> Self::Distance { - euclidean_distance(&self.0, other) - } -} - -impl CoordinateMetric<f64> for LuvSpace {} - impl ColorSpace for LuvSpace { fn average<I: IntoIterator<Item = Self>>(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<C> { deleted: Cell<bool>, } -impl<C: ColorSpace> Pixel<C> { +impl<C> Pixel<C> { fn new(x: u32, y: u32, color: C) -> Self { Self { pos: (x, y), @@ -58,7 +58,7 @@ impl<C: ColorSpace> Pixel<C> { #[derive(Clone, Debug)] struct RcPixel<C>(Rc<Pixel<C>>); -impl<C: ColorSpace> RcPixel<C> { +impl<C> RcPixel<C> { fn new(x: u32, y: u32, color: C) -> Self { Self(Rc::new(Pixel::new(x, y, color))) } @@ -136,16 +136,6 @@ impl<C: Coordinates> Coordinates for Target<C> { } } -impl<T, C: CoordinateProximity<T>> CoordinateProximity<T> for Target<C> { - type Distance = C::Distance; - - fn distance_to_coords(&self, coords: &[T]) -> Self::Distance { - self.0.distance_to_coords(coords) - } -} - -impl<T, C: CoordinateMetric<T>> CoordinateMetric<T> for Target<C> {} - impl<C: Proximity> Proximity for RcPixel<C> { 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<C> { deleted: usize, } -impl<C: ColorSpace> ImageFrontier<C> { +impl<C: ColorSpace> ImageFrontier<C> +where + C::Value: PartialOrd<C::Distance>, +{ /// Create an ImageFrontier from an image. pub fn new(img: &RgbImage) -> Self { let width = img.width(); @@ -39,7 +42,10 @@ impl<C: ColorSpace> ImageFrontier<C> { } } -impl<C: ColorSpace> Frontier for ImageFrontier<C> { +impl<C: ColorSpace> Frontier for ImageFrontier<C> +where + C::Value: PartialOrd<C::Distance>, +{ 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<C> { Filled(C), } -impl<C: ColorSpace> MeanPixel<C> { +impl<C: ColorSpace> MeanPixel<C> +where + C::Value: PartialOrd<C::Distance>, +{ fn filled_color(&self) -> Option<C> { match self { Self::Filled(color) => Some(*color), @@ -37,7 +40,10 @@ pub struct MeanFrontier<C> { deleted: usize, } -impl<C: ColorSpace> MeanFrontier<C> { +impl<C: ColorSpace> MeanFrontier<C> +where + C::Value: PartialOrd<C::Distance>, +{ /// 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<C: ColorSpace> MeanFrontier<C> { } } -impl<C: ColorSpace> Frontier for MeanFrontier<C> { +impl<C: ColorSpace> Frontier for MeanFrontier<C> +where + C::Value: PartialOrd<C::Distance>, +{ 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<C> { filled: bool, } -impl<C: ColorSpace> MinPixel<C> { +impl<C: ColorSpace> MinPixel<C> +where + C::Value: PartialOrd<C::Distance>, +{ fn new() -> Self { Self { pixel: None, @@ -39,7 +42,10 @@ pub struct MinFrontier<C, R> { deleted: usize, } -impl<C: ColorSpace, R: Rng> MinFrontier<C, R> { +impl<C: ColorSpace, R: Rng> MinFrontier<C, R> +where + C::Value: PartialOrd<C::Distance>, +{ /// 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<C: ColorSpace, R: Rng> MinFrontier<C, R> { } } -impl<C: ColorSpace, R: Rng> Frontier for MinFrontier<C, R> { +impl<C: ColorSpace, R: Rng> Frontier for MinFrontier<C, R> +where + C::Value: PartialOrd<C::Distance>, +{ 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<C: ColorSpace>(&mut self, colors: Vec<Rgb8>) -> AppResult<()> { + fn paint<C: ColorSpace>(&mut self, colors: Vec<Rgb8>) -> AppResult<()> + where + C::Value: PartialOrd<C::Distance>, + { let width = self.width.unwrap(); let height = self.height.unwrap(); let x0 = self.args.x0.unwrap_or(width / 2); |