From 0df085bcb53940215e3a0691e2b0f26082d5eed0 Mon Sep 17 00:00:00 2001 From: Pol Rivero <65060696+pol-rivero@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:45:20 +0100 Subject: [PATCH] Check empty crop size --- src/femtovg_area/imp.rs | 12 ++++-------- src/math.rs | 4 ++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/femtovg_area/imp.rs b/src/femtovg_area/imp.rs index a1946d2..534f433 100644 --- a/src/femtovg_area/imp.rs +++ b/src/femtovg_area/imp.rs @@ -291,15 +291,11 @@ impl FemtoVgAreaMut { .crop_tool .borrow() .get_crop() - .map(|c| rect_ensure_in_bounds(c.get_rectangle(), bounds)) + .map(|c| c.get_rectangle()) + .map(|rect| rect_ensure_in_bounds(rect, bounds)) .map(rect_round) - .unwrap_or(( - Vec2D::zero(), - Vec2D::new( - self.background_image.width() as f32, - self.background_image.height() as f32, - ), - )); + .filter(|(_, size)| !size.is_zero()) + .unwrap_or(bounds); // create render-target let image_id = canvas.create_image_empty( diff --git a/src/math.rs b/src/math.rs index 2cbbb0a..7be1960 100644 --- a/src/math.rs +++ b/src/math.rs @@ -54,6 +54,10 @@ impl Vec2D { Vec2D::new(-a, -b) } } + + pub fn is_zero(&self) -> bool { + self.x.abs() < f32::EPSILON && self.y.abs() < f32::EPSILON + } } impl Add for Vec2D {