use super::*; use core::{mem, ops::Range}; pub struct Rect { position: Vec2, size: Vec2, color: Color, } impl Rect { #[must_use] pub fn new(position: Vec2, size: Vec2, color: Color) -> Self { Self { position, size, color, } } } impl Draw for Rect { fn draw(&self, canvas: &mut impl Canvas) { for dy in sorted(self.position.y..self.position.y + self.size.y) { for dx in sorted(self.position.x..self.position.x + self.size.x) { canvas.blit_pixel(dx, dy, self.color); } } } } trait Sorted { fn sorted(self) -> Self; } impl Sorted for Range { fn sorted(self) -> Self { let Self { mut start, mut end } = self; if start > end { mem::swap(&mut start, &mut end); } Self { start, end } } } fn sorted(x: T) -> T { x.sorted() }