Bug 1382534 - Add a UnionMaybeRects() method to gfx/2d/Rect.h. r=mstange
MozReview-Commit-ID: 3G4Hlj54Thy
--- a/gfx/2d/Rect.h
+++ b/gfx/2d/Rect.h
@@ -310,26 +310,38 @@ IntRectTyped<units> TruncatedToInt(const
}
template<class units>
RectTyped<units> IntRectToRect(const IntRectTyped<units>& aRect)
{
return RectTyped<units>(aRect.x, aRect.y, aRect.Width(), aRect.Height());
}
-// Convenience function for intersecting two rectangles wrapped in Maybes.
-template <typename T>
-Maybe<T>
-IntersectMaybeRects(const Maybe<T>& a, const Maybe<T>& b)
+// Convenience functions for intersecting and unioning two rectangles wrapped in Maybes.
+template <typename Rect>
+Maybe<Rect>
+IntersectMaybeRects(const Maybe<Rect>& a, const Maybe<Rect>& b)
{
if (!a) {
return b;
} else if (!b) {
return a;
} else {
return Some(a->Intersect(*b));
}
}
+template <typename Rect>
+Maybe<Rect>
+UnionMaybeRects(const Maybe<Rect>& a, const Maybe<Rect>& b)
+{
+ if (!a) {
+ return b;
+ } else if (!b) {
+ return a;
+ } else {
+ return Some(a->Union(*b));
+ }
+}
} // namespace gfx
} // namespace mozilla
#endif /* MOZILLA_GFX_RECT_H_ */