From fffdf4a6dd69f16176698f8b42db7dfe2a054e26 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Thu, 4 Feb 2021 21:57:09 +0100 Subject: Fix crash when drawing rect with no area --- src/math/rect.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/math') diff --git a/src/math/rect.rs b/src/math/rect.rs index a8326bc..288c19d 100644 --- a/src/math/rect.rs +++ b/src/math/rect.rs @@ -3,6 +3,7 @@ use super::{ExactSurface, LineSegment, Polygon, Vec2}; //use alga::general::{Additive, Identity}; use nalgebra::{RealField, Scalar}; +use num_traits::sign::{self, Signed}; use num_traits::{NumCast, ToPrimitive, Zero}; use serde::{Deserialize, Serialize}; use std::ops::{Add, AddAssign, Sub}; @@ -147,6 +148,14 @@ impl Rect { Vec2::new(T::zero(), move_y) } } + + /// Calculate the area of the rectangle. + pub fn area(&self) -> T + where + T: Signed, + { + sign::abs(self.w) * sign::abs(self.h) + } } impl ExactSurface for Rect -- cgit v1.2.3-70-g09d2