diff options
Diffstat (limited to 'Source/WebCore/platform/graphics/FloatRect.cpp')
-rw-r--r-- | Source/WebCore/platform/graphics/FloatRect.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Source/WebCore/platform/graphics/FloatRect.cpp b/Source/WebCore/platform/graphics/FloatRect.cpp index 36f3d3a..165ef76 100644 --- a/Source/WebCore/platform/graphics/FloatRect.cpp +++ b/Source/WebCore/platform/graphics/FloatRect.cpp @@ -30,8 +30,8 @@ #include "FloatConversion.h" #include "IntRect.h" #include <algorithm> -#include <limits> #include <math.h> +#include <wtf/MathExtras.h> using std::max; using std::min; @@ -97,6 +97,24 @@ void FloatRect::unite(const FloatRect& other) setLocationAndSizeFromEdges(l, t, r, b); } +void FloatRect::uniteIfNonZero(const FloatRect& other) +{ + // Handle empty special cases first. + if (!other.width() && !other.height()) + return; + if (!width() && !height()) { + *this = other; + return; + } + + float left = min(x(), other.x()); + float top = min(y(), other.y()); + float right = max(maxX(), other.maxX()); + float bottom = max(maxY(), other.maxY()); + + setLocationAndSizeFromEdges(left, top, right, bottom); +} + void FloatRect::scale(float sx, float sy) { m_location.setX(x() * sx); @@ -182,6 +200,7 @@ IntRect enclosingIntRect(const FloatRect& rect) float top = floorf(rect.y()); float width = ceilf(rect.maxX()) - left; float height = ceilf(rect.maxY()) - top; + return IntRect(safeFloatToInt(left), safeFloatToInt(top), safeFloatToInt(width), safeFloatToInt(height)); } |