Bug 1518584 - Add WithinEpsilonOf() functions to RectTyped and MarginTyped. r=kats
authorBotond Ballo <botond@mozilla.com>
Wed, 09 Jan 2019 15:37:52 +0000
changeset 510208 541282f7d798595e3bdace073d51843e06c9bfed
parent 510207 f12fba5d2706be972c86072f4ec733de1aac363b
child 510209 f9e54ff712bcddd257a3c4084839e6c70b40ec53
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1518584
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1518584 - Add WithinEpsilonOf() functions to RectTyped and MarginTyped. r=kats Also make a const-correctness fix to PointTyped::WithinEpsilonOf(). Depends on D15974 Differential Revision: https://phabricator.services.mozilla.com/D15975
gfx/2d/Point.h
gfx/2d/Rect.h
--- a/gfx/2d/Point.h
+++ b/gfx/2d/Point.h
@@ -134,17 +134,17 @@ struct PointTyped
   // The mixed-type constructors (Float, Coord) and (Coord, Float) are needed to
   // avoid ambiguities because Coord is implicitly convertible to Float.
   constexpr PointTyped(F aX, Coord aY) : Super(Coord(aX), aY) {}
   constexpr PointTyped(Coord aX, F aY) : Super(aX, Coord(aY)) {}
   constexpr PointTyped(Coord aX, Coord aY) : Super(aX.value, aY.value) {}
   constexpr MOZ_IMPLICIT PointTyped(const IntPointTyped<units>& point)
       : Super(F(point.x), F(point.y)) {}
 
-  bool WithinEpsilonOf(const PointTyped<units, F>& aPoint, F aEpsilon) {
+  bool WithinEpsilonOf(const PointTyped<units, F>& aPoint, F aEpsilon) const {
     return fabs(aPoint.x - this->x) < aEpsilon &&
            fabs(aPoint.y - this->y) < aEpsilon;
   }
 
   // XXX When all of the code is ported, the following functions to convert to
   // and from unknown types should be removed.
 
   static PointTyped<units, F> FromUnknownPoint(
--- a/gfx/2d/Rect.h
+++ b/gfx/2d/Rect.h
@@ -63,16 +63,23 @@ struct MarginTyped : public BaseMargin<F
   typedef BaseMargin<F, MarginTyped<units, F> > Super;
 
   MarginTyped() : Super() {}
   MarginTyped(F aTop, F aRight, F aBottom, F aLeft)
       : Super(aTop, aRight, aBottom, aLeft) {}
   explicit MarginTyped(const IntMarginTyped<units>& aMargin)
       : Super(F(aMargin.top), F(aMargin.right), F(aMargin.bottom),
               F(aMargin.left)) {}
+
+  bool WithinEpsilonOf(const MarginTyped& aOther, F aEpsilon) const {
+    return fabs(this->left - aOther.left) < aEpsilon &&
+           fabs(this->top - aOther.top) < aEpsilon &&
+           fabs(this->right - aOther.right) < aEpsilon &&
+           fabs(this->bottom - aOther.bottom) < aEpsilon;
+  }
 };
 typedef MarginTyped<UnknownUnits> Margin;
 typedef MarginTyped<UnknownUnits, double> MarginDouble;
 
 template <class units>
 IntMarginTyped<units> RoundedToInt(const MarginTyped<units>& aMargin) {
   return IntMarginTyped<units>(int32_t(floorf(aMargin.top + 0.5f)),
                                int32_t(floorf(aMargin.right + 0.5f)),
@@ -276,16 +283,23 @@ struct RectTyped : public BaseRect<F, Re
     return RectTyped<UnknownUnits, F>(this->X(), this->Y(), this->Width(),
                                       this->Height());
   }
 
   // This is here only to keep IPDL-generated code happy. DO NOT USE.
   bool operator==(const RectTyped<units, F>& aRect) const {
     return RectTyped<units, F>::IsEqualEdges(aRect);
   }
+
+  bool WithinEpsilonOf(const RectTyped& aOther, F aEpsilon) const {
+    return fabs(this->x - aOther.x) < aEpsilon &&
+           fabs(this->y - aOther.y) < aEpsilon &&
+           fabs(this->width - aOther.width) < aEpsilon &&
+           fabs(this->height - aOther.height) < aEpsilon;
+  }
 };
 typedef RectTyped<UnknownUnits> Rect;
 typedef RectTyped<UnknownUnits, double> RectDouble;
 
 template <class units>
 IntRectTyped<units> RoundedToInt(const RectTyped<units>& aRect) {
   RectTyped<units> copy(aRect);
   copy.Round();