diff --git a/color-module/src/schemes/swatch_style/swatch.rs b/color-module/src/schemes/swatch_style/swatch.rs index a445cec..e90e392 100644 --- a/color-module/src/schemes/swatch_style/swatch.rs +++ b/color-module/src/schemes/swatch_style/swatch.rs @@ -24,28 +24,26 @@ impl Swatch { } } - fn find_interval(&self) -> (usize, usize) { + fn find_interval(&self) -> usize { if !self.include_primary { - return (0, 0); + return 0; } if self.primary_key.l == self.min_key { - return (0, 1); + return 0; } if self.primary_key.l == self.max_key { - return (self.color_amount - 2, self.color_amount - 1); + return self.color_amount - 1; } let step = (self.max_key - self.min_key) / (self.color_amount - 1) as f32; - let index = ((self.primary_key.l - self.min_key) / step) as usize; - - (index, index + 1) + ((self.primary_key.l - self.min_key) / step).ceil() as usize } pub fn swatch(&self) -> Vec { let mut swatch = Vec::new(); if self.include_primary { - let (_, primary_index) = self.find_interval(); + let primary_index = self.find_interval(); if primary_index > 0 { - let step = (self.max_key - self.min_key) / primary_index as f32; + let step = (self.primary_key.l - self.min_key) / (primary_index - 1) as f32; for i in 0..primary_index { let lightness = self.min_key + step * i as f32; swatch.push(Oklch { @@ -55,8 +53,8 @@ impl Swatch { } } if primary_index < self.color_amount - 1 { - let step = - (self.max_key - self.min_key) / (self.color_amount - primary_index) as f32; + let step = (self.max_key - self.primary_key.l) + / (self.color_amount - primary_index - 1) as f32; for i in primary_index..self.color_amount { let lightness = self.min_key + step * i as f32; swatch.push(Oklch { diff --git a/src/color_functions/color_module_bg.wasm b/src/color_functions/color_module_bg.wasm index 64de917..615a4ff 100644 Binary files a/src/color_functions/color_module_bg.wasm and b/src/color_functions/color_module_bg.wasm differ