summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-07-06 23:04:10 -0400
committerTavian Barnes <tavianator@tavianator.com>2020-08-24 11:10:13 -0400
commit6ba084db4ba375eacaa1677fd75de318c12170c7 (patch)
tree9122e889fcc47d8f6ebd71717a8cb35a98ebafdb
parent39c0348c9f98b4dd29bd112a0a2a42faa67c92d4 (diff)
downloadkd-forest-6ba084db4ba375eacaa1677fd75de318c12170c7.tar.xz
Bump acap to 0.2.0
This requires adapting to the new k-d trees, which are significantly faster.
-rw-r--r--Cargo.lock9
-rw-r--r--Cargo.toml2
-rw-r--r--src/color.rs39
-rw-r--r--src/frontier.rs18
-rw-r--r--src/frontier/image.rs10
-rw-r--r--src/frontier/mean.rs15
-rw-r--r--src/frontier/min.rs15
-rw-r--r--src/main.rs5
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 <tavianator@tavianator.com>"]
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<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);