Skip to content
Permalink
Browse files
2011-05-23 Matthew Delaney <mdelaney@apple.com>
        Reviewed by Simon Fraser.

        Remove safeFloatToInt() in FloatRect.cpp and replace with working version of clampToInteger()
        https://bugs.webkit.org/show_bug.cgi?id=58216

        * wtf/MathExtras.h:
        (clampToInteger):
        (clampToPositiveInteger):
2011-05-23  Matthew Delaney  <mdelaney@apple.com>

        Reviewed by Simon Fraser.

        Remove safeFloatToInt() in FloatRect.cpp and replace with working version of clampToInteger()
        https://bugs.webkit.org/show_bug.cgi?id=58216

        No new tests. The SVG tests mask-excessive-malloc.svg and pattern-excessive-malloc.svg exercise this code path.

        * platform/graphics/FloatRect.cpp:
        (WebCore::enclosingIntRect):


Canonical link: https://commits.webkit.org/76684@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@87103 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Matt Delaney committed May 23, 2011
1 parent 951b5cb commit 06572223c31597d6cca8c55c6858c37289d04e51
Showing with 42 additions and 21 deletions.
  1. +11 −0 Source/JavaScriptCore/ChangeLog
  2. +17 −7 Source/JavaScriptCore/wtf/MathExtras.h
  3. +12 −0 Source/WebCore/ChangeLog
  4. +2 −14 Source/WebCore/platform/graphics/FloatRect.cpp
@@ -1,3 +1,14 @@
2011-05-23 Matthew Delaney <mdelaney@apple.com>

Reviewed by Simon Fraser.

Remove safeFloatToInt() in FloatRect.cpp and replace with working version of clampToInteger()
https://bugs.webkit.org/show_bug.cgi?id=58216

* wtf/MathExtras.h:
(clampToInteger):
(clampToPositiveInteger):

2011-05-23 Ruben <chromium@hybridsource.org>

Reviewed by Tony Chang.
@@ -220,17 +220,27 @@ inline int clampToPositiveInteger(double d)
return static_cast<int>(std::max<double>(std::min(d, maxIntAsDouble), 0));
}

inline int clampToInteger(float d)
inline int clampToInteger(float x)
{
const float minIntAsFloat = static_cast<float>(std::numeric_limits<int>::min());
const float maxIntAsFloat = static_cast<float>(std::numeric_limits<int>::max());
return static_cast<int>(std::max(std::min(d, maxIntAsFloat), minIntAsFloat));
static const int s_intMax = std::numeric_limits<int>::max();
static const int s_intMin = std::numeric_limits<int>::min();

if (x >= static_cast<float>(s_intMax))
return s_intMax;
if (x < static_cast<float>(s_intMin))
return s_intMin;
return static_cast<int>(x);
}

inline int clampToPositiveInteger(float d)
inline int clampToPositiveInteger(float x)
{
const float maxIntAsFloat = static_cast<float>(std::numeric_limits<int>::max());
return static_cast<int>(std::max<float>(std::min(d, maxIntAsFloat), 0));
static const int s_intMax = std::numeric_limits<int>::max();

if (x >= static_cast<float>(s_intMax))
return s_intMax;
if (x < 0)
return 0;
return static_cast<int>(x);
}

inline int clampToInteger(unsigned value)
@@ -1,3 +1,15 @@
2011-05-23 Matthew Delaney <mdelaney@apple.com>

Reviewed by Simon Fraser.

Remove safeFloatToInt() in FloatRect.cpp and replace with working version of clampToInteger()
https://bugs.webkit.org/show_bug.cgi?id=58216

No new tests. The SVG tests mask-excessive-malloc.svg and pattern-excessive-malloc.svg exercise this code path.

* platform/graphics/FloatRect.cpp:
(WebCore::enclosingIntRect):

2011-05-20 Jeremy Noble <jer.noble@apple.com>

Reviewed by Darin Adler.
@@ -182,27 +182,15 @@ void FloatRect::fitToPoints(const FloatPoint& p0, const FloatPoint& p1, const Fl
setLocationAndSizeFromEdges(left, top, right, bottom);
}

static inline int safeFloatToInt(float x)
{
static const int s_intMax = std::numeric_limits<int>::max();
static const int s_intMin = std::numeric_limits<int>::min();

if (x >= static_cast<float>(s_intMax))
return s_intMax;
if (x < static_cast<float>(s_intMin))
return s_intMin;
return static_cast<int>(x);
}

IntRect enclosingIntRect(const FloatRect& rect)
{
float left = floorf(rect.x());
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));
return IntRect(clampToInteger(left), clampToInteger(top),
clampToInteger(width), clampToInteger(height));
}

FloatRect mapRect(const FloatRect& r, const FloatRect& srcRect, const FloatRect& destRect)

0 comments on commit 0657222

Please sign in to comment.