File tree 3 files changed +35
-10
lines changed
3 files changed +35
-10
lines changed Original file line number Diff line number Diff line change 8
8
#include " mozilla/dom/DOMQuadBinding.h"
9
9
#include " mozilla/dom/DOMPoint.h"
10
10
#include " mozilla/dom/DOMRect.h"
11
- #include < algorithm >
11
+ #include " mozilla/FloatingPoint.h "
12
12
13
13
using namespace mozilla ;
14
14
using namespace mozilla ::dom;
@@ -106,8 +106,8 @@ DOMQuad::GetHorizontalMinMax(double* aX1, double* aX2) const
106
106
x1 = x2 = Point (0 )->X ();
107
107
for (uint32_t i = 1 ; i < 4 ; ++i) {
108
108
double x = Point (i)->X ();
109
- x1 = std::min (x1, x);
110
- x2 = std::max (x2, x);
109
+ x1 = NaNSafeMin (x1, x);
110
+ x2 = NaNSafeMax (x2, x);
111
111
}
112
112
*aX1 = x1;
113
113
*aX2 = x2;
@@ -120,8 +120,8 @@ DOMQuad::GetVerticalMinMax(double* aY1, double* aY2) const
120
120
y1 = y2 = Point (0 )->Y ();
121
121
for (uint32_t i = 1 ; i < 4 ; ++i) {
122
122
double y = Point (i)->Y ();
123
- y1 = std::min (y1 , y);
124
- y2 = std::max (y2, y);
123
+ y1 = NaNSafeMin (y1 , y);
124
+ y2 = NaNSafeMax (y2, y);
125
125
}
126
126
*aY1 = y1 ;
127
127
*aY2 = y2;
Original file line number Diff line number Diff line change 16
16
#include " mozilla/Attributes.h"
17
17
#include " mozilla/dom/BindingDeclarations.h"
18
18
#include " mozilla/ErrorResult.h"
19
- #include < algorithm >
19
+ #include " mozilla/FloatingPoint.h "
20
20
21
21
struct nsRect ;
22
22
@@ -79,22 +79,22 @@ class DOMRectReadOnly : public nsISupports
79
79
double Left () const
80
80
{
81
81
double x = X (), w = Width ();
82
- return std::min (x, x + w);
82
+ return NaNSafeMin (x, x + w);
83
83
}
84
84
double Top () const
85
85
{
86
86
double y = Y (), h = Height ();
87
- return std::min (y, y + h);
87
+ return NaNSafeMin (y, y + h);
88
88
}
89
89
double Right () const
90
90
{
91
91
double x = X (), w = Width ();
92
- return std::max (x, x + w);
92
+ return NaNSafeMax (x, x + w);
93
93
}
94
94
double Bottom () const
95
95
{
96
96
double y = Y (), h = Height ();
97
- return std::max (y, y + h);
97
+ return NaNSafeMax (y, y + h);
98
98
}
99
99
100
100
bool WriteStructuredClone (JSStructuredCloneWriter* aWriter) const ;
Original file line number Diff line number Diff line change 14
14
#include " mozilla/MathAlgorithms.h"
15
15
#include " mozilla/Types.h"
16
16
17
+ #include < algorithm>
17
18
#include < stdint.h>
18
19
19
20
namespace mozilla {
@@ -450,6 +451,30 @@ EqualOrBothNaN(T aValue1, T aValue2)
450
451
return aValue1 == aValue2;
451
452
}
452
453
454
+ /* *
455
+ * Return NaN if either |aValue1| or |aValue2| is NaN, or the minimum of
456
+ * |aValue1| and |aValue2| otherwise.
457
+ */
458
+ template <typename T>
459
+ static inline T NaNSafeMin (T aValue1, T aValue2) {
460
+ if (IsNaN (aValue1) || IsNaN (aValue2)) {
461
+ return UnspecifiedNaN<T>();
462
+ }
463
+ return std::min (aValue1, aValue2);
464
+ }
465
+
466
+ /* *
467
+ * Return NaN if either |aValue1| or |aValue2| is NaN, or the maximum of
468
+ * |aValue1| and |aValue2| otherwise.
469
+ */
470
+ template <typename T>
471
+ static inline T NaNSafeMax (T aValue1, T aValue2) {
472
+ if (IsNaN (aValue1) || IsNaN (aValue2)) {
473
+ return UnspecifiedNaN<T>();
474
+ }
475
+ return std::max (aValue1, aValue2);
476
+ }
477
+
453
478
namespace detail {
454
479
455
480
template <typename T>
You can’t perform that action at this time.
0 commit comments