[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
kbr at google.com
kbr at google.com
Wed Dec 22 12:54:52 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit fe6a8fa7751b38a7d11b679245be0d6172472c1b
Author: kbr at google.com <kbr at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Wed Sep 1 16:59:09 2010 +0000
2010-08-31 Kenneth Russell <kbr at google.com>
Reviewed by Simon Fraser.
Add helpers to FloatRect to compute bounding box from points
https://bugs.webkit.org/show_bug.cgi?id=45015
Added fitToPoints, including a few overloaded variants for the
cases of two, three and four points. I opted not to add a
generalized version taking const FloatRect* or Vector<FloatRect>
at the present time because for my own purposes they are
unnecessary, and the specific versions can be more tightly coded.
Also added left() and top() for symmetry with right() and bottom().
These changes have been tested with new code to be added later.
* platform/graphics/FloatRect.cpp:
(WebCore::FloatRect::intersect):
(WebCore::FloatRect::unite):
(WebCore::FloatRect::fitToPoints):
* platform/graphics/FloatRect.h:
(WebCore::FloatRect::left):
(WebCore::FloatRect::top):
(WebCore::FloatRect::setLocationAndSizeFromEdges):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66611 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 779de75..0bdabec 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,27 @@
+2010-08-31 Kenneth Russell <kbr at google.com>
+
+ Reviewed by Simon Fraser.
+
+ Add helpers to FloatRect to compute bounding box from points
+ https://bugs.webkit.org/show_bug.cgi?id=45015
+
+ Added fitToPoints, including a few overloaded variants for the
+ cases of two, three and four points. I opted not to add a
+ generalized version taking const FloatRect* or Vector<FloatRect>
+ at the present time because for my own purposes they are
+ unnecessary, and the specific versions can be more tightly coded.
+ Also added left() and top() for symmetry with right() and bottom().
+ These changes have been tested with new code to be added later.
+
+ * platform/graphics/FloatRect.cpp:
+ (WebCore::FloatRect::intersect):
+ (WebCore::FloatRect::unite):
+ (WebCore::FloatRect::fitToPoints):
+ * platform/graphics/FloatRect.h:
+ (WebCore::FloatRect::left):
+ (WebCore::FloatRect::top):
+ (WebCore::FloatRect::setLocationAndSizeFromEdges):
+
2010-09-01 Anton Muhin <antonm at chromium.org>
Reviewed by Dimitri Glazkov.
diff --git a/WebCore/platform/graphics/FloatRect.cpp b/WebCore/platform/graphics/FloatRect.cpp
index 6dfa808..0d8a24e 100644
--- a/WebCore/platform/graphics/FloatRect.cpp
+++ b/WebCore/platform/graphics/FloatRect.cpp
@@ -76,10 +76,7 @@ void FloatRect::intersect(const FloatRect& other)
b = 0;
}
- m_location.setX(l);
- m_location.setY(t);
- m_size.setWidth(r - l);
- m_size.setHeight(b - t);
+ setLocationAndSizeFromEdges(l, t, r, b);
}
void FloatRect::unite(const FloatRect& other)
@@ -97,10 +94,7 @@ void FloatRect::unite(const FloatRect& other)
float r = max(right(), other.right());
float b = max(bottom(), other.bottom());
- m_location.setX(l);
- m_location.setY(t);
- m_size.setWidth(r - l);
- m_size.setHeight(b - t);
+ setLocationAndSizeFromEdges(l, t, r, b);
}
void FloatRect::scale(float sx, float sy)
@@ -111,6 +105,65 @@ void FloatRect::scale(float sx, float sy)
m_size.setHeight(height() * sy);
}
+void FloatRect::fitToPoints(const FloatPoint& p0, const FloatPoint& p1)
+{
+ float left = min(p0.x(), p1.x());
+ float top = min(p0.y(), p1.y());
+ float right = max(p0.x(), p1.x());
+ float bottom = max(p0.y(), p1.y());
+
+ setLocationAndSizeFromEdges(left, top, right, bottom);
+}
+
+namespace {
+// Helpers for 3- and 4-way max and min.
+
+template <typename T>
+T min3(const T& v1, const T& v2, const T& v3)
+{
+ return min(min(v1, v2), v3);
+}
+
+template <typename T>
+T max3(const T& v1, const T& v2, const T& v3)
+{
+ return max(max(v1, v2), v3);
+}
+
+template <typename T>
+T min4(const T& v1, const T& v2, const T& v3, const T& v4)
+{
+ return min(min(v1, v2), min(v3, v4));
+}
+
+template <typename T>
+T max4(const T& v1, const T& v2, const T& v3, const T& v4)
+{
+ return max(max(v1, v2), max(v3, v4));
+}
+
+} // anonymous namespace
+
+void FloatRect::fitToPoints(const FloatPoint& p0, const FloatPoint& p1, const FloatPoint& p2)
+{
+ float left = min3(p0.x(), p1.x(), p2.x());
+ float top = min3(p0.y(), p1.y(), p2.y());
+ float right = max3(p0.x(), p1.x(), p2.x());
+ float bottom = max3(p0.y(), p1.y(), p2.y());
+
+ setLocationAndSizeFromEdges(left, top, right, bottom);
+}
+
+void FloatRect::fitToPoints(const FloatPoint& p0, const FloatPoint& p1, const FloatPoint& p2, const FloatPoint& p3)
+{
+ float left = min4(p0.x(), p1.x(), p2.x(), p3.x());
+ float top = min4(p0.y(), p1.y(), p2.y(), p3.y());
+ float right = max4(p0.x(), p1.x(), p2.x(), p3.x());
+ float bottom = max4(p0.y(), p1.y(), p2.y(), p3.y());
+
+ setLocationAndSizeFromEdges(left, top, right, bottom);
+}
+
static inline int safeFloatToInt(float x)
{
static const int s_intMax = std::numeric_limits<int>::max();
diff --git a/WebCore/platform/graphics/FloatRect.h b/WebCore/platform/graphics/FloatRect.h
index 2b23576..e387927 100644
--- a/WebCore/platform/graphics/FloatRect.h
+++ b/WebCore/platform/graphics/FloatRect.h
@@ -96,7 +96,9 @@ public:
bool isEmpty() const { return m_size.isEmpty(); }
+ float left() const { return x(); }
float right() const { return x() + width(); }
+ float top() const { return y(); }
float bottom() const { return y() + height(); }
FloatPoint center() const { return FloatPoint(x() + width() / 2, y() + height() / 2); }
@@ -129,6 +131,11 @@ public:
void scale(float s) { scale(s, s); }
void scale(float sx, float sy);
+ // Re-initializes this rectangle to fit the sets of passed points.
+ void fitToPoints(const FloatPoint& p0, const FloatPoint& p1);
+ void fitToPoints(const FloatPoint& p0, const FloatPoint& p1, const FloatPoint& p2);
+ void fitToPoints(const FloatPoint& p0, const FloatPoint& p1, const FloatPoint& p2, const FloatPoint& p3);
+
#if PLATFORM(CG)
FloatRect(const CGRect&);
operator CGRect() const;
@@ -168,6 +175,13 @@ public:
private:
FloatPoint m_location;
FloatSize m_size;
+
+ void setLocationAndSizeFromEdges(float left, float top, float right, float bottom)
+ {
+ m_location.set(left, top);
+ m_size.setWidth(right - left);
+ m_size.setHeight(bottom - top);
+ }
};
inline FloatRect intersection(const FloatRect& a, const FloatRect& b)
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list