Skip to main content

shape_core/elements/rectangles/rectangle_2d/
arith.rs

1use std::ops::BitOrAssign;
2use super::*;
3
4impl<T> BitOrAssign for Rectangle<T> where T: PartialOrd {
5    /// Returns a larger rectangle that encompasses these two rectangles
6    fn bitor_assign(&mut self, rhs: Self) {
7        if rhs.min.x < self.min.x {
8            self.min.x = rhs.min.x;
9        }
10        if rhs.min.y < self.min.y {
11            self.min.y = rhs.min.y;
12        }
13        if rhs.max.x > self.max.x {
14            self.max.x = rhs.max.x;
15        }
16        if rhs.max.y > self.max.y {
17            self.max.y = rhs.max.y;
18        }
19    }
20}
21
22impl<T> BitAndAssign for Rectangle<T> where T: PartialOrd {
23    /// Returns the intersection of two rectangles, possibly with negative area, meaning the empty set
24    fn bitand_assign(&mut self, rhs: Self) {
25        if rhs.min.x > self.min.x {
26            self.min.x = rhs.min.x;
27        }
28        if rhs.min.y > self.min.y {
29            self.min.y = rhs.min.y;
30        }
31        if rhs.max.x < self.max.x {
32            self.max.x = rhs.max.x;
33        }
34        if rhs.max.y < self.max.y {
35            self.max.y = rhs.max.y;
36        }
37
38    }
39}