Bug 681192. Part 0.1: Add BaseRect::ClampPoint. r=bas
authorRobert O'Callahan <robert@ocallahan.org>
Thu, 10 May 2012 17:24:17 +1200
changeset 93682 954704d8d3d29d4f11d3eb49635069b05de83bfe
parent 93681 b5304fd23df9f5f1fb1bdaeb8857629c9fa0e2cf
child 93683 6a059c7d3578781c1cc0c44e894f98f06aeaeddc
push idunknown
push userunknown
push dateunknown
reviewersbas
bugs681192
milestone15.0a1
Bug 681192. Part 0.1: Add BaseRect::ClampPoint. r=bas
gfx/2d/BaseRect.h
--- a/gfx/2d/BaseRect.h
+++ b/gfx/2d/BaseRect.h
@@ -410,16 +410,26 @@ struct BaseRect {
     T right = static_cast<T>(ceil(double(XMost()) / aXScale));
     T bottom = static_cast<T>(ceil(double(YMost()) / aYScale));
     x = static_cast<T>(floor(double(x) / aXScale));
     y = static_cast<T>(floor(double(y) / aYScale));
     width = right - x;
     height = bottom - y;
   }
 
+  /**
+   * Clamp aPoint to this rectangle. It is allowed to end up on any
+   * edge of the rectangle.
+   */
+  Point ClampPoint(const Point& aPoint) const
+  {
+    return Point(NS_MAX(x, NS_MIN(XMost(), aPoint.x)),
+                 NS_MAX(y, NS_MIN(YMost(), aPoint.y)));
+  }
+
 private:
   // Do not use the default operator== or operator!= !
   // Use IsEqualEdges or IsEqualInterior explicitly.
   bool operator==(const Sub& aRect) const { return false; }
   bool operator!=(const Sub& aRect) const { return false; }
 };
 
 }