|
16 | 16 | #include "BasePoint4D.h"
|
17 | 17 | #include "BaseSize.h"
|
18 | 18 | #include "mozilla/Maybe.h"
|
| 19 | +#include "mozilla/gfx/NumericTools.h" |
19 | 20 |
|
20 | 21 | #include <cmath>
|
21 | 22 | #include <type_traits>
|
@@ -80,39 +81,44 @@ struct MOZ_EMPTY_BASES IntPointTyped
|
80 | 81 | constexpr IntPointTyped(ToInt aX, ToInt aY)
|
81 | 82 | : Super(Coord(aX.value), Coord(aY.value)) {}
|
82 | 83 |
|
83 |
| - static IntPointTyped<Units> Round(float aX, float aY) { |
| 84 | + static IntPointTyped Round(float aX, float aY) { |
84 | 85 | return IntPointTyped(int32_t(floorf(aX + 0.5f)),
|
85 | 86 | int32_t(floorf(aY + 0.5f)));
|
86 | 87 | }
|
87 | 88 |
|
88 |
| - static IntPointTyped<Units> Ceil(float aX, float aY) { |
| 89 | + static IntPointTyped Ceil(float aX, float aY) { |
89 | 90 | return IntPointTyped(int32_t(ceilf(aX)), int32_t(ceilf(aY)));
|
90 | 91 | }
|
91 | 92 |
|
92 |
| - static IntPointTyped<Units> Floor(float aX, float aY) { |
| 93 | + static IntPointTyped Floor(float aX, float aY) { |
93 | 94 | return IntPointTyped(int32_t(floorf(aX)), int32_t(floorf(aY)));
|
94 | 95 | }
|
95 | 96 |
|
96 |
| - static IntPointTyped<Units> Truncate(float aX, float aY) { |
| 97 | + static IntPointTyped Truncate(float aX, float aY) { |
97 | 98 | return IntPointTyped(int32_t(aX), int32_t(aY));
|
98 | 99 | }
|
99 | 100 |
|
100 |
| - static IntPointTyped<Units> Round(const PointTyped<Units, float>& aPoint); |
101 |
| - static IntPointTyped<Units> Ceil(const PointTyped<Units, float>& aPoint); |
102 |
| - static IntPointTyped<Units> Floor(const PointTyped<Units, float>& aPoint); |
103 |
| - static IntPointTyped<Units> Truncate(const PointTyped<Units, float>& aPoint); |
| 101 | + static IntPointTyped Round(const PointTyped<Units, float>& aPoint); |
| 102 | + static IntPointTyped Ceil(const PointTyped<Units, float>& aPoint); |
| 103 | + static IntPointTyped Floor(const PointTyped<Units, float>& aPoint); |
| 104 | + static IntPointTyped Truncate(const PointTyped<Units, float>& aPoint); |
104 | 105 |
|
105 | 106 | // XXX When all of the code is ported, the following functions to convert to
|
106 | 107 | // and from unknown types should be removed.
|
107 | 108 |
|
108 |
| - static IntPointTyped<Units> FromUnknownPoint( |
| 109 | + static IntPointTyped FromUnknownPoint( |
109 | 110 | const IntPointTyped<UnknownUnits>& aPoint) {
|
110 | 111 | return IntPointTyped<Units>(aPoint.x, aPoint.y);
|
111 | 112 | }
|
112 | 113 |
|
113 | 114 | IntPointTyped<UnknownUnits> ToUnknownPoint() const {
|
114 | 115 | return IntPointTyped<UnknownUnits>(this->x, this->y);
|
115 | 116 | }
|
| 117 | + |
| 118 | + IntPointTyped RoundedToMultiple(int32_t aMultiplier) const { |
| 119 | + return {RoundToMultiple(this->x, aMultiplier), |
| 120 | + RoundToMultiple(this->y, aMultiplier)}; |
| 121 | + } |
116 | 122 | };
|
117 | 123 | typedef IntPointTyped<UnknownUnits> IntPoint;
|
118 | 124 |
|
@@ -278,34 +284,49 @@ struct MOZ_EMPTY_BASES IntSizeTyped
|
278 | 284 | constexpr IntSizeTyped(ToInt aWidth, ToInt aHeight)
|
279 | 285 | : Super(aWidth.value, aHeight.value) {}
|
280 | 286 |
|
281 |
| - static IntSizeTyped<Units> Round(float aWidth, float aHeight) { |
| 287 | + static IntSizeTyped Round(float aWidth, float aHeight) { |
282 | 288 | return IntSizeTyped(int32_t(floorf(aWidth + 0.5)),
|
283 | 289 | int32_t(floorf(aHeight + 0.5)));
|
284 | 290 | }
|
285 | 291 |
|
286 |
| - static IntSizeTyped<Units> Truncate(float aWidth, float aHeight) { |
| 292 | + static IntSizeTyped Truncate(float aWidth, float aHeight) { |
287 | 293 | return IntSizeTyped(int32_t(aWidth), int32_t(aHeight));
|
288 | 294 | }
|
289 | 295 |
|
290 |
| - static IntSizeTyped<Units> Ceil(float aWidth, float aHeight) { |
| 296 | + static IntSizeTyped Ceil(float aWidth, float aHeight) { |
291 | 297 | return IntSizeTyped(int32_t(ceil(aWidth)), int32_t(ceil(aHeight)));
|
292 | 298 | }
|
293 | 299 |
|
294 |
| - static IntSizeTyped<Units> Floor(float aWidth, float aHeight) { |
| 300 | + static IntSizeTyped Floor(float aWidth, float aHeight) { |
295 | 301 | return IntSizeTyped(int32_t(floorf(aWidth)), int32_t(floorf(aHeight)));
|
296 | 302 | }
|
297 | 303 |
|
298 |
| - static IntSizeTyped<Units> Round(const SizeTyped<Units, float>& aSize); |
299 |
| - static IntSizeTyped<Units> Ceil(const SizeTyped<Units, float>& aSize); |
300 |
| - static IntSizeTyped<Units> Floor(const SizeTyped<Units, float>& aSize); |
301 |
| - static IntSizeTyped<Units> Truncate(const SizeTyped<Units, float>& aSize); |
| 304 | + static IntSizeTyped Round(const SizeTyped<Units, float>& aSize); |
| 305 | + static IntSizeTyped Ceil(const SizeTyped<Units, float>& aSize); |
| 306 | + static IntSizeTyped Floor(const SizeTyped<Units, float>& aSize); |
| 307 | + static IntSizeTyped Truncate(const SizeTyped<Units, float>& aSize); |
| 308 | + |
| 309 | + IntSizeTyped TruncatedToMultiple(int32_t aMultiplier) const { |
| 310 | + if (aMultiplier == 1) { |
| 311 | + return *this; |
| 312 | + } |
| 313 | + return {RoundDownToMultiple(this->width, aMultiplier), |
| 314 | + RoundDownToMultiple(this->height, aMultiplier)}; |
| 315 | + } |
| 316 | + |
| 317 | + IntSizeTyped CeiledToMultiple(int32_t aMultiplier) const { |
| 318 | + if (aMultiplier == 1) { |
| 319 | + return *this; |
| 320 | + } |
| 321 | + return {RoundUpToMultiple(this->width, aMultiplier), |
| 322 | + RoundUpToMultiple(this->height, aMultiplier)}; |
| 323 | + } |
302 | 324 |
|
303 | 325 | // XXX When all of the code is ported, the following functions to convert to
|
304 | 326 | // and from unknown types should be removed.
|
305 | 327 |
|
306 |
| - static IntSizeTyped<Units> FromUnknownSize( |
307 |
| - const IntSizeTyped<UnknownUnits>& aSize) { |
308 |
| - return IntSizeTyped<Units>(aSize.width, aSize.height); |
| 328 | + static IntSizeTyped FromUnknownSize(const IntSizeTyped<UnknownUnits>& aSize) { |
| 329 | + return IntSizeTyped(aSize.width, aSize.height); |
309 | 330 | }
|
310 | 331 |
|
311 | 332 | IntSizeTyped<UnknownUnits> ToUnknownSize() const {
|
|
0 commit comments