From 5f3d80185139a2b744f4f9bfb420c91baf56b186 Mon Sep 17 00:00:00 2001 From: genius Date: Sun, 31 May 2020 11:32:58 +0200 Subject: [PATCH 1/2] Fix pistons scaling of circles --- src/drawing/backend_impl/piston.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/drawing/backend_impl/piston.rs b/src/drawing/backend_impl/piston.rs index 4a579056..80e59cd6 100644 --- a/src/drawing/backend_impl/piston.rs +++ b/src/drawing/backend_impl/piston.rs @@ -150,7 +150,11 @@ impl<'a, 'b> DrawingBackend for PistonBackend<'a, 'b> { style: &S, fill: bool, ) -> Result<(), DrawingErrorKind> { - let rect = circle(center.0 as f64, center.1 as f64, radius as f64); + let rect = circle( + center.0 as f64 * self.scale, + center.1 as f64 * self.scale, + radius as f64 * self.scale, + ); if fill { ellipse( make_piston_rgba(&style.as_color()), From 5244a9fdfe0e47b608dc25f5c7a18e3ba9149384 Mon Sep 17 00:00:00 2001 From: genius Date: Tue, 2 Jun 2020 10:37:43 +0200 Subject: [PATCH 2/2] refactored call to piston_window::circle into make_circle and added unit-test for it --- src/drawing/backend_impl/piston.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/drawing/backend_impl/piston.rs b/src/drawing/backend_impl/piston.rs index 80e59cd6..02605fcb 100644 --- a/src/drawing/backend_impl/piston.rs +++ b/src/drawing/backend_impl/piston.rs @@ -34,6 +34,14 @@ fn make_point_pair(a: BackendCoord, b: BackendCoord, scale: f64) -> [f64; 4] { ] } +fn make_circle(center: BackendCoord, radius: u32, scale: f64) -> [f64; 4] { + circle( + center.0 as f64 * scale, + center.1 as f64 * scale, + radius as f64 * scale, + ) +} + impl<'a, 'b> PistonBackend<'a, 'b> { pub fn new(size: (u32, u32), scale: f64, context: Context, graphics: &'b mut G2d<'a>) -> Self { Self { @@ -150,11 +158,7 @@ impl<'a, 'b> DrawingBackend for PistonBackend<'a, 'b> { style: &S, fill: bool, ) -> Result<(), DrawingErrorKind> { - let rect = circle( - center.0 as f64 * self.scale, - center.1 as f64 * self.scale, - radius as f64 * self.scale, - ); + let rect = make_circle(center, radius, self.scale); if fill { ellipse( make_piston_rgba(&style.as_color()), @@ -208,3 +212,13 @@ pub fn draw_piston_window Result<(), Box