From ca4c1e4febe75cb952d45edb850d4bf66ab31643 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:39:09 +0000 Subject: [PATCH 1/2] build(deps): update rust crate colorgrad to 0.7.0 --- Cargo.lock | 8 ++++---- lcat/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f70dc0f..e4986bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,9 +168,9 @@ checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "colorgrad" -version = "0.6.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a5f405d474b9d05e0a093d3120e77e9bf26461b57a84b40aa2a221ac5617fb6" +checksum = "7b8d55c12145df1b7c4b9a5e8741101c405461f9025add91fd9a54223711cba2" dependencies = [ "csscolorparser", ] @@ -202,9 +202,9 @@ dependencies = [ [[package]] name = "csscolorparser" -version = "0.6.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb2a7d3066da2de787b7f032c736763eb7ae5d355f81a68bab2675a96008b0bf" +checksum = "46f9a16a848a7fb95dd47ce387ac1ee9a6df879ba784b815537fcd388a1a8288" [[package]] name = "darling" diff --git a/lcat/Cargo.toml b/lcat/Cargo.toml index 9d9f40d..5eea69a 100644 --- a/lcat/Cargo.toml +++ b/lcat/Cargo.toml @@ -15,7 +15,7 @@ default = ["clap"] [dependencies] bstr = "1.10.0" clap = { version = "4.5.13", features = ["derive", "wrap_help"], optional = true } -colorgrad = { version = "0.6.2", default-features = false } +colorgrad = { version = "0.7.0", default-features = false } fastrand = "2.1.0" unicode-segmentation = "1.11.0" unicode-width = "0.1.13" From cd190e5c1a12ba503f413de7fc6e0894adff21cf Mon Sep 17 00:00:00 2001 From: David Knaack Date: Wed, 7 Aug 2024 19:17:36 +0200 Subject: [PATCH 2/2] chore: amend for api changes in colorgrad --- lcat/Cargo.toml | 2 +- lcat/src/rainbow.rs | 34 +++++++++++++++++----------------- lcat/src/rainbow_cmd.rs | 12 ++++++------ 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lcat/Cargo.toml b/lcat/Cargo.toml index 5eea69a..c11e6bb 100644 --- a/lcat/Cargo.toml +++ b/lcat/Cargo.toml @@ -15,7 +15,7 @@ default = ["clap"] [dependencies] bstr = "1.10.0" clap = { version = "4.5.13", features = ["derive", "wrap_help"], optional = true } -colorgrad = { version = "0.7.0", default-features = false } +colorgrad = { version = "0.7.0", default-features = false, features = ["preset"] } fastrand = "2.1.0" unicode-segmentation = "1.11.0" unicode-width = "0.1.13" diff --git a/lcat/src/rainbow.rs b/lcat/src/rainbow.rs index 5f0fcbb..9a8c4d0 100644 --- a/lcat/src/rainbow.rs +++ b/lcat/src/rainbow.rs @@ -7,11 +7,11 @@ use unicode_width::UnicodeWidthChar; use crate::ok::{Hsv, Lab, LinRgb, Rgb}; pub trait Grad { - fn color_at(&self, pos: f64) -> (u8, u8, u8); + fn color_at(&self, pos: f32) -> (u8, u8, u8); } -impl Grad for colorgrad::Gradient { - fn color_at(&self, pos: f64) -> (u8, u8, u8) { +impl Grad for T { + fn color_at(&self, pos: f32) -> (u8, u8, u8) { let [r, g, b, _] = self.at(pos).to_rgba8(); (r, g, b) } @@ -21,9 +21,9 @@ pub struct HsvGrad {} impl Grad for HsvGrad { #[allow(clippy::cast_possible_truncation)] - fn color_at(&self, pos: f64) -> (u8, u8, u8) { + fn color_at(&self, pos: f32) -> (u8, u8, u8) { let Rgb { r, g, b } = Rgb::from(&LinRgb::from(&Lab::from(&Hsv { - h: pos as f32, + h: pos, s: 1.0, v: 1.0, }))); @@ -34,9 +34,9 @@ impl Grad for HsvGrad { pub struct Rainbow { current_row: usize, current_col: usize, - shift_col: f64, - shift_row: f64, - position: f64, + shift_col: f32, + shift_row: f32, + position: f32, gradient: Box, invert: bool, } @@ -45,9 +45,9 @@ impl Rainbow { #[must_use] pub fn new( gradient: Box, - start: f64, - shift_col: f64, - shift_row: f64, + start: f32, + shift_col: f32, + shift_row: f32, invert: bool, ) -> Self { Self { @@ -63,25 +63,25 @@ impl Rainbow { pub fn step_row(&mut self, n_row: usize) { self.current_row += n_row; - self.position += n_row as f64 * self.shift_row; + self.position += n_row as f32 * self.shift_row; } pub fn step_col(&mut self, n_col: usize) { self.current_col += n_col; - self.position += n_col as f64 * self.shift_col; + self.position += n_col as f32 * self.shift_col; } pub fn reset_row(&mut self) { - self.position -= self.current_row as f64 * self.shift_row; + self.position -= self.current_row as f32 * self.shift_row; self.current_row = 0; } pub fn reset_col(&mut self) { - self.position -= self.current_col as f64 * self.shift_col; + self.position -= self.current_col as f32 * self.shift_col; self.current_col = 0; } - fn get_position(&mut self) -> f64 { + fn get_position(&mut self) -> f32 { if self.position < 0.0 || self.position > 1.0 { self.position -= self.position.floor(); } @@ -193,7 +193,7 @@ mod tests { use super::*; fn create_rb() -> Rainbow { - Rainbow::new(Box::new(colorgrad::rainbow()), 0.0, 0.1, 0.2, false) + Rainbow::new(Box::new(colorgrad::preset::rainbow()), 0.0, 0.1, 0.2, false) } #[test] diff --git a/lcat/src/rainbow_cmd.rs b/lcat/src/rainbow_cmd.rs index c2ada71..1e0a3d0 100644 --- a/lcat/src/rainbow_cmd.rs +++ b/lcat/src/rainbow_cmd.rs @@ -13,11 +13,11 @@ pub enum RainbowStyle { pub struct RainbowCmd { /// How many degrees to shift text color hue for every column #[clap(short = 'C', long, default_value = "1.6")] - shift_col: f64, + shift_col: f32, /// How many degrees to shift text color hue for every row #[clap(short = 'R', long, default_value = "3.2")] - shift_row: f64, + shift_row: f32, /// Don't randomize sign of col and row shift values #[clap(short = 'n', long)] @@ -25,7 +25,7 @@ pub struct RainbowCmd { /// Sets initial hue of text color in degress [default: random] #[clap(short = 'H', long)] - hue: Option, + hue: Option, /// Rainbow mode #[clap(short, long, value_enum, default_value = "rainbow")] @@ -58,11 +58,11 @@ impl From for Rainbow { -cmd.shift_row } / 360.; - let start = cmd.hue.map_or_else(fastrand::f64, |hue| hue / 360.); + let start = cmd.hue.map_or_else(fastrand::f32, |hue| hue / 360.); let grad: Box = match cmd.style { - RainbowStyle::Rainbow => Box::new(colorgrad::rainbow()), - RainbowStyle::Sinebow => Box::new(colorgrad::sinebow()), + RainbowStyle::Rainbow => Box::new(colorgrad::preset::rainbow()), + RainbowStyle::Sinebow => Box::new(colorgrad::preset::sinebow()), RainbowStyle::OkHsv => Box::new(HsvGrad {}), };