From 7e1dba1acf97ada6a456fefd2a59814bf8e03691 Mon Sep 17 00:00:00 2001 From: James Waples Date: Sat, 22 May 2021 12:18:45 +0100 Subject: [PATCH 1/3] Migrate rectangle intersection from examples repo --- .../examples/rectangle-intersection.rs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 debug-tools/examples/rectangle-intersection.rs diff --git a/debug-tools/examples/rectangle-intersection.rs b/debug-tools/examples/rectangle-intersection.rs new file mode 100644 index 0000000..9dcdbd6 --- /dev/null +++ b/debug-tools/examples/rectangle-intersection.rs @@ -0,0 +1,64 @@ +use embedded_graphics::{ + pixelcolor::Rgb888, + prelude::*, + primitives::{PrimitiveStyle, Rectangle}, +}; +use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window}; +use framework::prelude::*; + +struct RectangleIntersection { + top_left: Point, + bottom_right: Point, +} + +impl App for RectangleIntersection { + type Color = Rgb888; + const DISPLAY_SIZE: Size = Size::new(200, 200); + + fn new() -> Self { + Self { + top_left: Point::new(80, 80), + bottom_right: Point::new(150, 150), + } + } + + fn parameters(&mut self) -> Vec { + vec![ + Parameter::new("top-left", &mut self.top_left), + Parameter::new("bottom-right", &mut self.bottom_right), + ] + } + + fn draw( + &self, + display: &mut SimulatorDisplay, + ) -> Result<(), std::convert::Infallible> { + let base_rectangle = Rectangle::with_corners(Point::new(20, 20), Point::new(100, 100)); + let moving_rectangle = Rectangle::with_corners(self.top_left, self.bottom_right); + + base_rectangle + .into_styled(PrimitiveStyle::with_fill(Rgb888::RED)) + .draw(display)?; + + moving_rectangle + .into_styled(PrimitiveStyle::with_fill(Rgb888::GREEN)) + .draw(display)?; + + let intersection = base_rectangle.intersection(&moving_rectangle); + + if intersection.size != Size::zero() { + intersection + .into_styled(PrimitiveStyle::with_fill(Rgb888::BLUE)) + .draw(display)?; + } + + Ok(()) + } +} + +fn main() { + let settings = OutputSettingsBuilder::new().scale(3).build(); + let window = Window::new("Line debugger", &settings); + + RectangleIntersection::run(window); +} From 77a5a5e49c11aeaafeacb0cd1a5686234bba7319 Mon Sep 17 00:00:00 2001 From: James Waples Date: Mon, 24 May 2021 15:06:07 +0100 Subject: [PATCH 2/3] Update debug-tools/examples/rectangle-intersection.rs Co-authored-by: Ralf Fuest --- debug-tools/examples/rectangle-intersection.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug-tools/examples/rectangle-intersection.rs b/debug-tools/examples/rectangle-intersection.rs index 9dcdbd6..5c4770b 100644 --- a/debug-tools/examples/rectangle-intersection.rs +++ b/debug-tools/examples/rectangle-intersection.rs @@ -58,7 +58,7 @@ impl App for RectangleIntersection { fn main() { let settings = OutputSettingsBuilder::new().scale(3).build(); - let window = Window::new("Line debugger", &settings); + let window = Window::new("Rectangle intersection", &settings); RectangleIntersection::run(window); } From 1d7e9b335f3746822150a65c7ccb4eed54bdf753 Mon Sep 17 00:00:00 2001 From: James Waples Date: Mon, 24 May 2021 15:37:20 +0100 Subject: [PATCH 3/3] Remove unnecessary zero size check Co-authored-by: Ralf Fuest --- debug-tools/examples/rectangle-intersection.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/debug-tools/examples/rectangle-intersection.rs b/debug-tools/examples/rectangle-intersection.rs index 5c4770b..09f91a3 100644 --- a/debug-tools/examples/rectangle-intersection.rs +++ b/debug-tools/examples/rectangle-intersection.rs @@ -46,11 +46,9 @@ impl App for RectangleIntersection { let intersection = base_rectangle.intersection(&moving_rectangle); - if intersection.size != Size::zero() { - intersection - .into_styled(PrimitiveStyle::with_fill(Rgb888::BLUE)) - .draw(display)?; - } + intersection + .into_styled(PrimitiveStyle::with_fill(Rgb888::BLUE)) + .draw(display)?; Ok(()) }