aboutsummaryrefslogtreecommitdiff
path: root/src/math/rect.rs
diff options
context:
space:
mode:
authorArne Dußin2020-11-01 22:53:24 +0100
committerArne Dußin2020-11-01 22:53:24 +0100
commit1ed00daee8f7cb0194d11a2aa32fc8ffc544ae98 (patch)
tree86c31f3bcb28be7d762e5d330e1c8aa195daaef5 /src/math/rect.rs
parent678406b21c14af2d1f1bd955368637f83f049011 (diff)
downloadgraf_karto-1ed00daee8f7cb0194d11a2aa32fc8ffc544ae98.tar.gz
graf_karto-1ed00daee8f7cb0194d11a2aa32fc8ffc544ae98.zip
Add basic deletion tool
Diffstat (limited to 'src/math/rect.rs')
-rw-r--r--src/math/rect.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/math/rect.rs b/src/math/rect.rs
index c126d56..6988b2c 100644
--- a/src/math/rect.rs
+++ b/src/math/rect.rs
@@ -1,7 +1,9 @@
use super::Vec2;
+//use alga::general::{Additive, Identity};
use nalgebra::{RealField, Scalar};
+use num_traits::identities::Zero;
use serde::{Deserialize, Serialize};
-use std::ops::{Add, AddAssign};
+use std::ops::{Add, AddAssign, Sub};
/// Represents a Rectangle with the value type T.
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
@@ -114,6 +116,21 @@ impl<T: Scalar + Copy> Rect<T> {
&& point.y <= self.y + self.h
}
+ /// Returns true if the entire rect is contained inside this rectangle.
+ pub fn contains_rect(&self, rect: Rect<T>) -> bool
+ where
+ T: Add<Output = T> + Sub<Output = T> + PartialOrd + Zero,
+ {
+ /* True, if the rightmost x-coordinate of the called rectangle is further right or the same
+ * as the rightmost coordinate of the given rect.
+ */
+ let x_exceeds = self.x + self.w - rect.x - rect.w >= T::zero();
+ // The same for the y-coordinates
+ let y_exceeds = self.y + self.h - rect.y - rect.h >= T::zero();
+
+ x_exceeds && y_exceeds && self.x <= rect.x && self.y <= rect.y
+ }
+
/// Function to calculate the bounding rectangle that is between two vectors. The order of the
/// vectors is irrelevent for this. As long as they are diagonally opposite of each other, this
/// function will work.