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

Merge TaggedColor and CssColor #25

Merged
merged 3 commits into from
Nov 10, 2024
Merged

Merge TaggedColor and CssColor #25

merged 3 commits into from
Nov 10, 2024

Conversation

raphlinus
Copy link
Contributor

As per discussion, the new name is DynamicColor, following the precedent of the image crate.

Also do some renames and add some docstrings.

Closes #21. The rename of Bitset closes #17.

As per discussion, the new name is `DynamicColor`, following the precedent of the `image` crate.

Also do some renames and add some docstrings.

Closes #21. The rename of Bitset closes #17.
Copy link
Collaborator

@waywardmonkeys waywardmonkeys left a comment

Choose a reason for hiding this comment

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

Apart from the rebase error, it seems fine?

A lot of it is just boilerplate change, so hopefully I didn't miss anything in there.

ColorSpaceTag::Oklab
| ColorSpaceTag::Oklch
| ColorSpaceTag::Lab
| ColorSpaceTag::Lch => self.map(|l, c1, c2, a| [f(l), c1, c2, a]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a bad merge, right?

Copy link
Contributor

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

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

Broadly looks good to me. Some comments on the Missing type.

self.0 |= 1 << ix;
}

pub fn single(ix: usize) -> Self {
/// The set containing a single component index.
pub fn singleton(ix: usize) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

singleton seems like a confusing name for this. This usually implies what in Rust would be a static instance. I would prefer the old name of single. Or perhaps an idiomatic rusty name would be with_single_component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've gone back to single, at your suggestion.

Comment on lines -6 to +8
/// A simple bitset, for representing missing components.
/// A simple bitset for representing missing components.
#[derive(Default, Clone, Copy, PartialEq, Eq, Debug)]
pub struct Bitset(u8);
pub struct Missing(u8);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be clearer if this represented present (non-missing) components? 0 to represent "present" and 1 to represent "missing" seems somehow inverted. Presumably this is equivalent on a technical level?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps "missing" semantics make sense because the common case is "no missing components"? If so then perhaps the code could stay the same, but the method could be documented in terms of "which components are present (non-missing)" rather than (or in addition to) "which components are in the set".

e.g. for is_empty:

Returns `true` if the set contains no indices (and therefore all color components are present).

Copy link
Contributor

Choose a reason for hiding this comment

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

Would also appreciate an/some example(s) of when components can be missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add some docs about missing components.

Inverting the boolean sense is equivalent at a technical level. I think the strongest case for this way ("missing") is that the default value of 0 makes sense.

Incidentally, I considered and rejected some other representations for this. In particular, color.js uses NaN. That works in pure Rust, but I have at least two problems with it: it complicates GPU interop, because NaN is almost always a bad thing), and it makes the test for "any missing components" more expensive, because you have to do a finiteness check on all the components, as opposed to comparison with 0 here. The current approach also has no memory cost, DynamicColor is 20 bytes either way.

Rename `Missing::singleton` back to `single`, and add explanation of missing components.
@raphlinus raphlinus added this pull request to the merge queue Nov 10, 2024
Merged via the queue into main with commit 2ca51c9 Nov 10, 2024
15 checks passed
@raphlinus raphlinus deleted the dynamic branch November 10, 2024 00:30
@waywardmonkeys waywardmonkeys added this to the Initial Release milestone Nov 15, 2024
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.

Merge CSSColor and TaggedColor Consider renaming Bitset
3 participants