Skip to content

Commit

Permalink
Add set_color () method to Triangle
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Egger <[email protected]>
  • Loading branch information
therealprof committed Mar 12, 2022
1 parent 8f06e4f commit 1c19673
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/math/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ impl<const D: usize> Triangle<D> {
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> {
Expand Down Expand Up @@ -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]);
}
}

0 comments on commit 1c19673

Please sign in to comment.