added From<Vec3>, From<Vec4> for Color
+use crate::math::vec3::Vec3;
use crate::{
math::vec4::Vec4,
visitor::{Visit, VisitResult, Visitor},
@@ -25,6 +26,28 @@ impl Into<u32> for Color {
}
}
+impl From<Vec3> for Color {
+ fn from(v: Vec3) -> Self {
+ Self {
+ r: (v.x.max(0.0).min(1.0) * 255.0) as u8,
+ g: (v.y.max(0.0).min(1.0) * 255.0) as u8,
+ b: (v.z.max(0.0).min(1.0) * 255.0) as u8,
+ a: 255,
+ }
+ }
+}
+
+impl From<Vec4> for Color {
+ fn from(v: Vec4) -> Self {
+ Self {
+ r: (v.x.max(0.0).min(1.0) * 255.0) as u8,
+ g: (v.y.max(0.0).min(1.0) * 255.0) as u8,
+ b: (v.z.max(0.0).min(1.0) * 255.0) as u8,
+ a: (v.w.max(0.0).min(1.0) * 255.0) as u8,
+ }
+ }
+}
+
impl Color {
pub const WHITE: Self = Self {
r: 255,
