diff -r b2feb190e4bc -r 133f648c5fbd rust/integral-geometry/src/lib.rs --- a/rust/integral-geometry/src/lib.rs Fri Nov 02 20:30:22 2018 +0100 +++ b/rust/integral-geometry/src/lib.rs Fri Nov 02 22:41:11 2018 +0300 @@ -247,6 +247,10 @@ ) } + pub fn at_origin(size: Size) -> Self { + Rect::from_size(Point::zero(), size) + } + #[inline] pub fn size(&self) -> Size { Size::new(self.width as usize, self.height as usize) @@ -283,6 +287,16 @@ } #[inline] + pub fn bottom_right(&self) -> Point { + Point::new(self.right(), self.bottom()) + } + + #[inline] + pub fn center(&self) -> Point { + (self.top_left() + self.bottom_right()) / 2 + } + + #[inline] pub fn with_margin(&self, margin: i32) -> Self { Rect::from_box( self.left() + margin, @@ -323,6 +337,17 @@ && self.top() <= other.bottom() && self.bottom() >= other.top() } + + #[inline] + pub fn split_at(&self, point: Point) -> [Rect; 4] { + assert!(self.contains_inside(point)); + [ + Rect::from_box(self.left(), point.x, self.top(), point.y), + Rect::from_box(point.x, self.right(), self.top(), point.y), + Rect::from_box(self.left(), point.x, point.y, self.bottom()), + Rect::from_box(point.x, self.right(), point.y, self.bottom()) + ] + } } pub struct Polygon {