Bug 1382534 - Add a UnionMaybeRects() method to gfx/2d/Rect.h. r=mstange draft
authorBotond Ballo <botond@mozilla.com>
Wed, 23 Aug 2017 17:45:15 -0400
changeset 690303 6c2b22f28ee648bc93f4cb3471727f992f8cb34e
parent 690302 4d9c47dd4f217471e743973d2f641a67dae509fe
child 690304 86099814a5fcd7b391c86a471f23337bc345fcdf
push id87277
push userbballo@mozilla.com
push dateWed, 01 Nov 2017 21:17:50 +0000
reviewersmstange
bugs1382534
milestone58.0a1
Bug 1382534 - Add a UnionMaybeRects() method to gfx/2d/Rect.h. r=mstange MozReview-Commit-ID: 3G4Hlj54Thy
gfx/2d/Rect.h
--- 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_ */