Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lchuv support #223

Merged
merged 3 commits into from May 12, 2021
Merged

Add Lchuv support #223

merged 3 commits into from May 12, 2021

Conversation

masonium
Copy link
Contributor

Round two! This branch implements the CIELCHuv color space.

I also cleaned up the Uniform*Hue implementation in hues.rs to use a macro to save on some repetitive typing.

pub fn run_luv_to_lchuv_tests() {
for (_, v) in TEST_DATA.iter() {
let mut to_lchuv: Lchuv<D65, f64> = v.luv.into_color_unclamped();
if to_lchuv.chroma < 1e-8 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a worth a comment.
In the implementation that generates the examples, chroma values below a certain threshold are a treated as 0.0, so the hue is set as 0 rather than using whatever comes out of atan (and probably isn't all that meaningful). My implementation matches the existing Lab -> Luv implementation and only does this if u* and v* are strictly 0. I can change my implementation to use a threshold on chroma instead, or we can leave this tweak in place in the test.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's going to be a point where the hue is almost just noise from the floating point operations. This was mentioned just yesterday in #107. I'm ok with a cut-off point like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, do you want the cut-off point in the code itself for hue calculation, or just the tests?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, sorry. Let's have it only in the test for now.

@@ -20,7 +20,7 @@ macro_rules! make_hues {
/// number (like `f32`). This makes many calculations easier, but may
/// also have some surprising effects if it's expected to act as a
/// linear number.
#[derive(Clone, Copy, Debug, Default)]
#[derive(Clone, Copy, Debug, Default)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo fmt does weird indenting here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, what is this? Maybe some bug. You can try to shuffle the attributes around, but if this is what it want to do, then so be it. 🤷‍♂️

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw some other odd thing further down, so maybe it's not a big fan of macros at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Playing around with it more, it seems to just be not opinionated inside the macro. If I manually correct the indentation, rustfmt doesn't "fix" it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect it to not want to do too much with macro code, considering it's much more free form. 🤔 Just do your best to make it look nice.

@masonium
Copy link
Contributor Author

The benchmark is failing for some pretty inscrutable reason, even though the CI build passed.

@Ogeon
Copy link
Owner

Ogeon commented May 12, 2021

You can ignore the benchmarks they are not working for PRs from forks at the moment.

rustfmt is unopionated inside macros for now, so this commit manually adjusts
some indentation to make it look better.
@Ogeon
Copy link
Owner

Ogeon commented May 12, 2021

Hah, simple but effective. And the implementation looks great! Thank you!

bors r+

@bors
Copy link
Contributor

bors bot commented May 12, 2021

Build succeeded:

@bors bors bot merged commit 5a8c4c6 into Ogeon:master May 12, 2021
@Ogeon Ogeon changed the title Feature/lchuv Add Lchuv support Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants