diff --git a/src/math/triangle.rs b/src/math/triangle.rs index d5c0864a11..c2b26b9025 100644 --- a/src/math/triangle.rs +++ b/src/math/triangle.rs @@ -17,6 +17,11 @@ impl Triangle { pub fn color(&self) -> [u8; 4] { self.color } + + /// Set a new color for the particular triangle + pub fn set_color(&mut self, color: [u8; 4]) { + self.color = color; + } } impl Triangle<3> { @@ -92,4 +97,14 @@ mod tests { let triangle = Triangle::from([a, b, c]); assert_eq!(triangle.color(), [255, 0, 0, 255]); } + + #[test] + fn triangle_set_color() { + let a = Point::from([0.0, 0.0]); + let b = Point::from([1.0, 1.0]); + let c = Point::from([1.0, 2.0]); + let mut triangle = Triangle::from([a, b, c]); + triangle.set_color([1, 2, 3, 4]); + assert_eq!(triangle.color(), [1, 2, 3, 4]); + } }