diff --git a/Cargo.toml b/Cargo.toml index 030f97a..9505287 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,9 @@ once_cell = "1.12.0" num_cpus = "1.13.1" ultraviolet = "0.9.0" crossbeam = "0.8.1" +rand = "0.8.5" [dev-dependencies] -rand = "0.8.5" wide = "0.7.4" [profile.dev] diff --git a/README.md b/README.md index bef232f..1d261bd 100644 --- a/README.md +++ b/README.md @@ -96,5 +96,5 @@ Take a look at [benchmarks](benches) for numbers. Take a look at * [examples/simple.rs](examples/simple.rs) for an idea of simple usage. -* [examples/tracking.rs](examples/track_merge.rs) for an idea of intra-cam track merging. +* [examples/tracking.rs](examples/track_merging) for an idea of intra-cam track merging. diff --git a/examples/track_merge.rs b/examples/track_merging.rs similarity index 94% rename from examples/track_merge.rs rename to examples/track_merging.rs index 7739bd8..a6f9d4d 100644 --- a/examples/track_merge.rs +++ b/examples/track_merging.rs @@ -2,13 +2,10 @@ use crate::Gender::{Female, Male}; use anyhow::Result; use itertools::Itertools; use once_cell::sync::OnceCell; -use rand::distributions::Uniform; -use rand::rngs::ThreadRng; -use rand::Rng; use similari::current_time_ms; use similari::distance::euclidean; use similari::store::TrackStore; -use similari::test_stuff::vec2; +use similari::test_stuff::FeatGen2; use similari::track::notify::NoopNotifier; use similari::track::{ Metric, ObservationSpec, ObservationsDb, TrackAttributes, TrackAttributesUpdate, TrackStatus, @@ -186,39 +183,9 @@ fn cam_tracking_attributes_update_test() { assert!(update.apply(&mut attrs).is_err()); } -struct FeatGen2 { - x: f32, - y: f32, - gen: ThreadRng, - dist: Uniform, -} - -impl FeatGen2 { - pub fn new(x: f32, y: f32, drift: f32) -> Self { - Self { - x, - y, - gen: rand::thread_rng(), - dist: Uniform::new(-drift, drift), - } - } -} - -impl Iterator for FeatGen2 { - type Item = ObservationSpec; - - fn next(&mut self) -> Option { - self.x += self.gen.sample(&self.dist); - self.y += self.gen.sample(&self.dist); - Some(ObservationSpec( - self.gen.sample(&self.dist) + 0.7, - vec2(self.x, self.y), - )) - } -} - #[test] fn feat_gen() { + use similari::test_stuff::FeatGen2; use std::ops::Sub; use ultraviolet::f32x8; diff --git a/src/test_stuff.rs b/src/test_stuff.rs index d7a4757..62e5339 100644 --- a/src/test_stuff.rs +++ b/src/test_stuff.rs @@ -5,6 +5,9 @@ use crate::track::{ TrackAttributesUpdate, TrackStatus, }; use anyhow::Result; +use rand::distributions::Uniform; +use rand::prelude::ThreadRng; +use rand::Rng; use thiserror::Error; #[derive(Debug, Error)] @@ -133,3 +136,34 @@ pub fn vec2(x: f32, y: f32) -> Observation { impl ObservationAttributes for f32 {} impl ObservationAttributes for () {} + +pub struct FeatGen2 { + x: f32, + y: f32, + gen: ThreadRng, + dist: Uniform, +} + +impl FeatGen2 { + pub fn new(x: f32, y: f32, drift: f32) -> Self { + Self { + x, + y, + gen: rand::thread_rng(), + dist: Uniform::new(-drift, drift), + } + } +} + +impl Iterator for FeatGen2 { + type Item = ObservationSpec; + + fn next(&mut self) -> Option { + self.x += self.gen.sample(&self.dist); + self.y += self.gen.sample(&self.dist); + Some(ObservationSpec( + self.gen.sample(&self.dist) + 0.7, + vec2(self.x, self.y), + )) + } +}