-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
two-way conversions between Color
-Vec4
and Color
-[f32; 4]
#688
Conversation
…se `impl From` instead of `impl Into`
Congrats on the first-ish pr! This looks good to me and I think its mergeable as-is, but I also think we have an opportunity here to resolve a mismatch in the Color into/from conversions that we introduced in #616. Looks like we forgot to change the Now that the "public" interface Color presents is Srgb, i think it makes sense to make the conversions do to/from conversions to Srgb. For anything converting to Likewise for anything extracting values from color (ex: |
added `impl From<[f32; 4]> for ColorSource` for consistency.
Thanks. I've learnt something new. I've made a new commit - is this what you had in mind? |
Perhaps I should make this comment on #616.
|
Ultimately I think separate types are the right way to go, but that will require slightly smarter gpu data conversions, so I'd rather handle that later. For now, I do think it makes sense to fix the math ops. I think it makes sense to adjust them to use nonlinear srgb everywhere: // crates/bevy_render/src/color.rs
impl Mul<f32> for Color {
type Output = Color;
fn mul(self, rhs: f32) -> Self::Output {
Color::rgba(self.r() * rhs.r(), ...);
}
} |
Ok, I've made those changes. |
Currently you can convert one way from
Vec4
->Color
, and one way fromColor
->[f32; 4]
.Added
From
trait implementations forColor
to allow two-way conversions betweenColor
<->Vec4
andColor
<->[f32; 4]
.As a side note, replaced
impl Into<[f32; 4]> for Color
withimpl From<Color> for [f32; 4]
which is better practice according to Traitstd::convert::From
.This is practically my first PR ever - let me know if there's something I've missed / should have done.