aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorArne Dußin2021-02-04 21:57:09 +0100
committerArne Dußin2021-02-04 21:57:09 +0100
commitfffdf4a6dd69f16176698f8b42db7dfe2a054e26 (patch)
tree44d3852efbfa781e80cbb422f62607891052e5ac /src/math
parentf77418497c141f2b12942002756612c5fdbe6f28 (diff)
downloadgraf_karto-net.tar.gz
graf_karto-net.zip
Fix crash when drawing rect with no areanet
Diffstat (limited to 'src/math')
-rw-r--r--src/math/rect.rs9
1 files changed, 9 insertions, 0 deletions
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<T: Scalar + Copy> Rect<T> {
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<T: Scalar + Copy> ExactSurface<T> for Rect<T>