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

Change range for Color red, green, and blue fields #225

Open
sunjay opened this issue Feb 18, 2021 · 0 comments
Open

Change range for Color red, green, and blue fields #225

sunjay opened this issue Feb 18, 2021 · 0 comments
Labels
Milestone

Comments

@sunjay
Copy link
Owner

sunjay commented Feb 18, 2021

When I originally wrote this crate 4 years ago (wow time flies!), I defined a type to represent colors:

turtle/src/color.rs

Lines 211 to 221 in 55ee9c0

#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct Color {
/// Value between 0.0 and 255.0
pub red: f64,
/// Value between 0.0 and 255.0
pub green: f64,
/// Value between 0.0 and 255.0
pub blue: f64,
/// Value between 0.0 and 1.0
pub alpha: f64,
}

I chose the range 0 to 255 for the red, green, and blue fields since that was pretty common but also made them floating point so they could represent a large number of colors. Floating point numbers work better with the rest of the crate since users often use f64 to represent other values in their program for methods like forward, right, etc.

The thing is, most libraries that use 255 as the upper bound for their color ranges do so because they're using u8 to represent the value of that field. 0 to 255 is the valid range for the u8 type. Given that we're using f64 for those fields anyway, it might actually make sense to change the range to something like 0.0 to 1.0 or maybe 0.0 to 100.0 instead.

This is a good candidate for a pre-1.0 change since this is definitely a breaking change.

Any thoughts on what we should do here are welcome. This is probably one of the largest changes I've thought about making to the library. The color type has been there since the very beginning, so there is a lot of code depending on it.

@sunjay sunjay added the bug label Feb 18, 2021
@sunjay sunjay added this to the 1.0.0 - MVP milestone Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant