From 6e08f479551315e072ec40853290d699220c9ba8 Mon Sep 17 00:00:00 2001 From: Emilia Date: Fri, 29 Dec 2023 18:01:00 -0500 Subject: [PATCH] Add palette function for ordered ids Given an id and a list of sorted ids, yields a color --- src/components/plates/util.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/components/plates/util.rs b/src/components/plates/util.rs index 34abf68..845d1ae 100644 --- a/src/components/plates/util.rs +++ b/src/components/plates/util.rs @@ -40,6 +40,19 @@ impl ColorPalette { let mut r = SmallRng::seed_from_u64(t.as_u128() as u64); self.get(r.gen_range(0.0..1.0f64)) } + + pub fn get_ordered(&self, t: uuid::Uuid, ordered_uuids: &Vec) + -> [f64; 3] { + let index = ordered_uuids.iter().position(|&x| x == t).expect("uuid must be in list of uuids"); + return self.get(Self::space_evenly(index)) + } + + fn space_evenly(x: usize) -> f64 { + let e: usize = (x.ilog2() + 1) as usize; + let d: usize = (2usize.pow(e as u32)) as usize; + let n: usize = (2*x + 1) % d; + return (n as f64) / (d as f64); + } } #[non_exhaustive]