Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Unified Diff: third_party/WebKit/Source/platform/geometry/FloatRect.cpp

Issue 1580363002: Implement FloatRect::squaredDistanceTo function (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/geometry/FloatRect.cpp
diff --git a/third_party/WebKit/Source/platform/geometry/FloatRect.cpp b/third_party/WebKit/Source/platform/geometry/FloatRect.cpp
index 13c4b815ff075a05fdba414b6d9e395ed78e6e63..6ff8f28e593989563fd9df1ad723a208809f5097 100644
--- a/third_party/WebKit/Source/platform/geometry/FloatRect.cpp
+++ b/third_party/WebKit/Source/platform/geometry/FloatRect.cpp
@@ -171,6 +171,35 @@ void FloatRect::scale(float sx, float sy)
m_size.setHeight(height() * sy);
}
+float FloatRect::distanceTo(const FloatPoint& point)
+{
+ float distance = 0.f;
+ if (point.x() < this->x()) {
fs 2016/01/13 10:22:03 I don't see the need for explicit this - here and
+ if (point.y() < this->y())
+ distance = (point - FloatPoint(this->x(), this->y())).diagonalLengthSquared();
fs 2016/01/13 10:22:03 FloatRect has minXMinYCorner (etc.) which would ma
+ else if (point.y() > this->maxY())
+ distance = (point - FloatPoint(this->x(), this->maxY())).diagonalLengthSquared();
fs 2016/01/13 10:22:03 The 'corner' areas compute the squared distance wh
+ else
+ distance = this->x() - point.x();
+ } else if (point.x() > this->maxX()) {
+ if (point.y() < this->y())
+ distance = (point - FloatPoint(this->maxX(), this->y())).diagonalLengthSquared();
+ else if (point.y() > this->maxY())
+ distance = (point - FloatPoint(this->maxX(), this->maxY())).diagonalLengthSquared();
+ else
+ distance = point.x() - this->maxX();
+ } else {
+ if (point.y() < this->y())
+ distance = this->y() - point.y();
+ else if (point.y() > this->maxY())
+ distance = point.y() - this->maxY();
+ else
+ distance = 0.f;
+ }
+
+ return distance;
+}
+
FloatRect unionRect(const Vector<FloatRect>& rects)
{
FloatRect result;

Powered by Google App Engine
This is Rietveld 408576698