geometry: rewrite Coordinates trait into a concrete struct, pass coords by reference to shaders, and add a Rectangle type

This commit is contained in:
2024-11-16 11:31:45 +01:00
parent a23b2e8e94
commit e329a56c90
4 changed files with 89 additions and 32 deletions

View File

@@ -21,8 +21,8 @@ struct IdleShader {
}
impl Shader for IdleShader {
fn draw(&self, coords: VirtualCoordinates) -> RGB8 {
Hsv::new_srgb(self.frame.wrapping_add(coords.x()).wrapping_add(coords.y()), 255, 255).into_rgb8()
fn draw(&self, coords: &VirtualCoordinates) -> RGB8 {
Hsv::new_srgb(self.frame.wrapping_add(coords.x).wrapping_add(coords.y), 255, 255).into_rgb8()
}
}
@@ -84,15 +84,15 @@ struct TestShader {
}
impl Shader for TestShader {
fn draw(&self, coords: VirtualCoordinates) -> RGB8 {
fn draw(&self, coords: &VirtualCoordinates) -> RGB8 {
match self.pattern {
Pattern::Red => RGB8::new(255, 0, 0),
Pattern::Green => RGB8::new(0, 255, 0),
Pattern::Blue => RGB8::new(0, 0, 255),
Pattern::White => RGB8::new(255, 255, 255),
Pattern::RGB => RGB8::new(coords.x(), coords.y(), 255 - (coords.x() / 2 + coords.y() / 2)),
Pattern::HSV => Hsv::new_srgb(coords.x(), coords.y(), 255 - (coords.x() / 2 + coords.y() / 2)).into_rgb8(),
Pattern::Outline => match (coords.x(), coords.y()) {
Pattern::RGB => RGB8::new(coords.x, coords.y, 255 - (coords.x / 2 + coords.y / 2)),
Pattern::HSV => Hsv::new_srgb(coords.x, coords.y, 255 - (coords.x / 2 + coords.y / 2)).into_rgb8(),
Pattern::Outline => match (coords.x, coords.y) {
(0, 0) => RGB8::new(255, 255, 255),
(0, _) => RGB8::new(255, 0, 0),
(_, 0) => RGB8::new(0, 255, 0),