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

Color improvements #77

Merged
merged 6 commits into from
Jul 28, 2019
Merged

Color improvements #77

merged 6 commits into from
Jul 28, 2019

Conversation

PvdBerg1998
Copy link
Contributor

Fixes #74.

@hecrj
Copy link
Owner

hecrj commented Jul 28, 2019

Thank you! Feel free to add the assertions too!

@PvdBerg1998
Copy link
Contributor Author

That would require the check float >= 1.0, which is non trivial to do. Are you okay with adding a dependency on approx? Or do you know another solution

@hecrj
Copy link
Owner

hecrj commented Jul 28, 2019

What's wrong with float <= 1.0?

@PvdBerg1998
Copy link
Contributor Author

Exact equality is not possible with floats, it won't even compile in rust since floats only implement PartialEq

@hecrj
Copy link
Owner

hecrj commented Jul 28, 2019

Hmm... My compiler doesn't seem to complain about this:

assert!(0.0 >= r, r <= 1.0);
assert!(0.0 >= g, g <= 1.0);
assert!(0.0 >= b, b <= 1.0);
assert!(0.0 >= a, a <= 1.0);

I understand precision issues are a thing, but I am not sure if we should be worrying about that here. AFAIK, both 0.0 and 1.0 should be perfectly representable.

@PvdBerg1998
Copy link
Contributor Author

Oh that's weird? I have no idea why that is the case. Maybe 1.0 is special cased?

@hecrj
Copy link
Owner

hecrj commented Jul 28, 2019

A type implementing only PartialEq still allows to check for equality. Eq is basically PartialEq but with reflexiveness (in the case of floats: NaN != NaN). Also, the relevant trait for <= is PartialOrd.

@PvdBerg1998
Copy link
Contributor Author

Should from_rgb_u32 check for values larger than 0xFFFFFF too? Or just ignore those?

src/graphics/color.rs Outdated Show resolved Hide resolved
@hecrj hecrj added the feature New feature or request label Jul 28, 2019
@hecrj hecrj added this to the 0.4.0 milestone Jul 28, 2019
Copy link
Owner

@hecrj hecrj left a comment

Choose a reason for hiding this comment

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

Great! Thank you 🎉

@hecrj hecrj merged commit c800657 into hecrj:master Jul 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Color improvements
2 participants