+inline bool Rect::operator==(const Rect &other) const
+{
+ return left==other.left && bottom==other.bottom && width==other.width && height==other.height;
+}
+
+inline Rect Rect::intersect(const Rect &other) const
+{
+ auto intersect_axis = [](int &s1, unsigned &z1, int s2, unsigned z2){
+ if(s2>s1)
+ {
+ unsigned d = s2-s1;
+ z1 = (d>z1 ? 0 : std::min(z1-d, z2));
+ s1 = s2;
+ }
+ else
+ {
+ unsigned d = s1-s2;
+ z1 = (d>z2 ? 0 : std::min(z2-d, z1));
+ }
+ };
+
+ Rect result = *this;
+ intersect_axis(result.left, result.width, other.left, other.width);
+ intersect_axis(result.bottom, result.height, other.bottom, other.height);
+ return result;
+}
+