Skip to content

Commit

Permalink
Rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Beinsezii committed Jan 28, 2024
1 parent 325125b commit ac09f4d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
51 changes: 35 additions & 16 deletions examples/quantiles.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use colcon::{Space, convert_space_chunked};
use colcon::{convert_space_chunked, Space};

fn main() {
const QUANTILES: [usize; 8] = [0, 1, 5, 10, 90, 95, 99, 100];
Expand All @@ -18,11 +18,28 @@ fn main() {
(Space::JZCZHZ, "Space::JZCZHZ"),
];

assert!(Space::ALL.iter().all(|s| spaces.iter().map(|(sp, _st)| sp).find(|sp| sp == &s).is_some()));

let srgb = (0..=STEPS).map(move |a| (0..=STEPS).map(move |b| (0..=STEPS).map(move |c|
[a as f32 / stepsf, b as f32 / stepsf, c as f32 / stepsf]
).collect::<Vec<[f32; 3]>>()).collect::<Vec<Vec<[f32; 3]>>>()).collect::<Vec<Vec<Vec<[f32; 3]>>>>().into_iter().flatten().flatten().collect::<Vec<[f32; 3]>>().into_boxed_slice();
assert!(Space::ALL.iter().all(|s| spaces
.iter()
.map(|(sp, _st)| sp)
.find(|sp| sp == &s)
.is_some()));

let srgb = (0..=STEPS)
.map(move |a| {
(0..=STEPS)
.map(move |b| {
(0..=STEPS)
.map(move |c| [a as f32 / stepsf, b as f32 / stepsf, c as f32 / stepsf])
.collect::<Vec<[f32; 3]>>()
})
.collect::<Vec<Vec<[f32; 3]>>>()
})
.collect::<Vec<Vec<Vec<[f32; 3]>>>>()
.into_iter()
.flatten()
.flatten()
.collect::<Vec<[f32; 3]>>()
.into_boxed_slice();

assert_eq!(srgb.len() / 100 * 100, srgb.len() - 1);

Expand All @@ -41,15 +58,15 @@ fn main() {
for (qn, q) in QUANTILES.iter().enumerate() {
quantiles[qn][c] = channel[channel.len() / 100 * q]
}

}

// disable hue and enforce 0 chroma floor
if Space::UCS_POLAR.contains(space) {
quantiles.iter_mut().for_each(|q| q[2] = f32::INFINITY);
quantiles[0][1] = 0.0;
} else if space == &Space::HSV {
quantiles.iter_mut().for_each(|q| q[0] = f32::INFINITY)
}
else if space == &Space::HSV { quantiles.iter_mut().for_each(|q| q[0] = f32::INFINITY) }

// enforce 0 lightness floor
if Space::UCS.contains(space) || Space::UCS_POLAR.contains(space) {
Expand All @@ -62,21 +79,23 @@ fn main() {
let mut formatted = String::new();

for (qn, q) in QUANTILES.iter().enumerate() {
formatted += &format!(
"
formatted += &format!("
/// Retrieves the {} quantile for mapping a given Space back to SRGB.
/// This is useful for things like creating adjustable values in Space
/// that represent most of the SRGB range without clipping.
/// Wrapping Hue values are set to f32::INFINITY
pub const fn srgb_quant{}(&self) -> [f32; 3] {{
match self {{", q, q);
match self {{",
q, q
);
for (n, (_space, space_str)) in spaces.iter().enumerate() {
formatted += &format!(
"
&{} => {:?},", space_str, results[n][qn]).replace("inf", "f32::INFINITY");
formatted += &format!("
&{} => {:?},",
space_str, results[n][qn]
)
.replace("inf", "f32::INFINITY");
}
formatted +=
"
formatted += "
}
}"
}
Expand Down
25 changes: 16 additions & 9 deletions examples/spectrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@ fn main() {
(Space::OKLCH, "oklab"),
(Space::JZCZHZ, "jzazbz"),
] {
let mut data: Vec<[f32; 3]> = (0..HEIGHT).map(|h|
(0..WIDTH).map(|w| [
match space {
Space::OKLCH => 0.70,
Space::JZCZHZ => 0.50,
_ => 0.65,
},
1.0 - h as f32 / 100.0, w as f32 ]
).collect::<Vec<[f32; 3]>>())
let mut data: Vec<[f32; 3]> = (0..HEIGHT)
.map(|h| {
(0..WIDTH)
.map(|w| {
[
match space {
Space::OKLCH => 0.70,
Space::JZCZHZ => 0.50,
_ => 0.65,
},
1.0 - h as f32 / 100.0,
w as f32,
]
})
.collect::<Vec<[f32; 3]>>()
})
.flatten()
.collect();

Expand Down

0 comments on commit ac09f4d

Please sign in to comment.