--- a/rust/integral-geometry/src/lib.rs Sat Mar 23 01:07:23 2019 +0300
+++ b/rust/integral-geometry/src/lib.rs Sat Mar 23 03:44:11 2019 +0300
@@ -109,6 +109,8 @@
}
impl Size {
+ pub const EMPTY: Self = Self::square(0);
+
#[inline]
pub const fn new(width: usize, height: usize) -> Self {
Self { width, height }
@@ -163,6 +165,11 @@
pub fn to_grid_index(&self) -> GridIndex {
GridIndex::new(*self)
}
+
+ #[inline]
+ pub fn contains(&self, other: Self) -> bool {
+ self.width >= other.width && self.height >= other.height
+ }
}
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
@@ -302,6 +309,11 @@
}
impl Rect {
+ pub const EMPTY: Self = Self {
+ top_left: Point::ZERO,
+ bottom_right: Point::ZERO,
+ };
+
#[inline]
pub fn new(top_left: Point, bottom_right: Point) -> Self {
debug_assert!(top_left.x <= bottom_right.x + 1);
@@ -416,6 +428,11 @@
}
#[inline]
+ pub fn contains_rect(&self, other: &Self) -> bool {
+ self.contains(other.top_left()) && self.contains(other.bottom_right())
+ }
+
+ #[inline]
pub fn intersects(&self, other: &Rect) -> bool {
self.left() <= self.right()
&& self.right() >= other.left()
@@ -435,6 +452,16 @@
}
#[inline]
+ pub fn with_margins(&self, left: i32, right: i32, top: i32, bottom: i32) -> Self {
+ Self::from_box(
+ self.left() + left,
+ self.right() + right,
+ self.top() + top,
+ self.bottom() + bottom,
+ )
+ }
+
+ #[inline]
pub fn quotient(self, x: usize, y: usize) -> Point {
self.top_left() + Point::new((x % self.width()) as i32, (y % self.height()) as i32)
}