Skip to content

Commit

Permalink
style: format various files...
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiving committed Mar 25, 2024
1 parent 8d1297e commit 706a5f0
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct Rgb {
/// ```rust
/// use std::str::FromStr;
/// use material_colors::color::Argb;
///
///
/// // from_str can accept any valid HEX color
/// let color = Argb::from_str("abc").unwrap();
/// let color = Argb::from_str("abcabc").unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic_color/variant.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Set of themes supported by Dynamic Color.
/// Instantiate the corresponding subclass, ex. [`SchemeTonalSpot`], to create
/// colors corresponding to the theme.
///
///
/// [`SchemeTonalSpot`]: crate::scheme::variant::SchemeTonalSpot
#[derive(PartialEq, Eq, PartialOrd, Clone)]
pub enum Variant {
Expand Down
3 changes: 2 additions & 1 deletion src/hct/cam16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ impl Cam16 {
let h_sin = h_rad.sin();
let h_cos = h_rad.cos();

let gamma = 23.0 * (p2 + 0.305) * t / (108.0 * t).mul_add(h_sin, 23.0f64.mul_add(p1, 11.0 * t * h_cos));
let gamma = 23.0 * (p2 + 0.305) * t
/ (108.0 * t).mul_add(h_sin, 23.0f64.mul_add(p1, 11.0 * t * h_cos));
let a = gamma * h_cos;
let b = gamma * h_sin;
let r_a = 288.0f64.mul_add(b, 460.0f64.mul_add(p2, 451.0 * a)) / 1403.0;
Expand Down
4 changes: 2 additions & 2 deletions src/hct/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,8 @@ impl HctSolver {
let ac = viewing_conditions.aw
* j_normalized.powf(1.0 / viewing_conditions.c / viewing_conditions.z);
let p2 = ac / viewing_conditions.nbb;
let gamma =
23.0 * (p2 + 0.305) * t / (108.0 * t).mul_add(h_sin, 23.0f64.mul_add(p1, 11.0 * t * h_cos));
let gamma = 23.0 * (p2 + 0.305) * t
/ (108.0 * t).mul_add(h_sin, 23.0f64.mul_add(p1, 11.0 * t * h_cos));
let a = gamma * h_cos;
let b = gamma * h_sin;
let r_a = 288.0f64.mul_add(b, 460.0f64.mul_add(p2, 451.0 * a)) / 1403.0;
Expand Down
2 changes: 1 addition & 1 deletion src/palette/tonal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt;
#[cfg(feature = "serde")]
use serde::Serialize;
use std::fmt;

use crate::{
color::Argb,
Expand Down
5 changes: 4 additions & 1 deletion src/quantize/point_provider_lab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ impl PointProvider for PointProviderLab {

// This relatively minor optimization is helpful because this method is
// called at least once for each pixel in an image.
(one.b - two.b).mul_add(one.b - two.b, (one.l - two.l).mul_add(one.l - two.l, (one.a - two.a).powi(2)))
(one.b - two.b).mul_add(
one.b - two.b,
(one.l - two.l).mul_add(one.l - two.l, (one.a - two.a).powi(2)),
)
}

fn new() -> Self {
Expand Down
6 changes: 4 additions & 2 deletions src/quantize/quantizer_wu.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![allow(clippy::too_many_arguments)]

use std::fmt;
use indexmap::IndexMap;
use std::collections::HashMap;
use std::fmt;

use crate::color::{Argb, Rgb};

Expand Down Expand Up @@ -95,7 +95,9 @@ impl QuantizerWu {
self.moments_b[index] += u32::from(blue) * count;

self.moments[index] += f64::from(count)
* (f64::from(red).mul_add(f64::from(red), f64::from(green).powi(2)) + f64::from(blue)).powi(2);
* (f64::from(red).mul_add(f64::from(red), f64::from(green).powi(2))
+ f64::from(blue))
.powi(2);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/scheme/variant/neutral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ impl SchemeNeutral {
Palette::Secondary => TonalPalette::of(source_color_hct.get_hue(), 8.0),
Palette::Tertiary => TonalPalette::of(source_color_hct.get_hue(), 16.0),
Palette::Error => TonalPalette::of(25.0, 84.0),
Palette::Neutral | Palette::NeutralVariant => TonalPalette::of(source_color_hct.get_hue(), 2.0),
Palette::Neutral | Palette::NeutralVariant => {
TonalPalette::of(source_color_hct.get_hue(), 2.0)
}
}
}
}
15 changes: 12 additions & 3 deletions src/utils/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@ pub fn difference_degrees(a: f64, b: f64) -> f64 {
}

pub fn matrix_multiply(row: [f64; 3], matrix: [[f64; 3]; 3]) -> [f64; 3] {
let a = row[2].mul_add(matrix[0][2], row[0].mul_add(matrix[0][0], row[1] * matrix[0][1]));
let b = row[2].mul_add(matrix[1][2], row[0].mul_add(matrix[1][0], row[1] * matrix[1][1]));
let c = row[2].mul_add(matrix[2][2], row[0].mul_add(matrix[2][0], row[1] * matrix[2][1]));
let a = row[2].mul_add(
matrix[0][2],
row[0].mul_add(matrix[0][0], row[1] * matrix[0][1]),
);
let b = row[2].mul_add(
matrix[1][2],
row[0].mul_add(matrix[1][0], row[1] * matrix[1][1]),
);
let c = row[2].mul_add(
matrix[2][2],
row[0].mul_add(matrix[2][0], row[1] * matrix[2][1]),
);

[a, b, c]
}

0 comments on commit 706a5f0

Please sign in to comment.