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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2005 Nokia. All rights reserved. 3 * Copyright (C) 2005 Nokia. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 165
166 void FloatRect::scale(float sx, float sy) 166 void FloatRect::scale(float sx, float sy)
167 { 167 {
168 m_location.setX(x() * sx); 168 m_location.setX(x() * sx);
169 m_location.setY(y() * sy); 169 m_location.setY(y() * sy);
170 m_size.setWidth(width() * sx); 170 m_size.setWidth(width() * sx);
171 m_size.setHeight(height() * sy); 171 m_size.setHeight(height() * sy);
172 } 172 }
173 173
174 float FloatRect::squaredDistanceTo(const FloatPoint& point) const
175 {
176 FloatPoint closestPoint;
177 closestPoint.setX(clampTo<float>(point.x(), x(), maxX()));
178 closestPoint.setY(clampTo<float>(point.y(), y(), maxY()));
179 return (point - closestPoint).diagonalLengthSquared();
180 }
181
174 FloatRect unionRect(const Vector<FloatRect>& rects) 182 FloatRect unionRect(const Vector<FloatRect>& rects)
175 { 183 {
176 FloatRect result; 184 FloatRect result;
177 185
178 size_t count = rects.size(); 186 size_t count = rects.size();
179 for (size_t i = 0; i < count; ++i) 187 for (size_t i = 0; i < count; ++i)
180 result.unite(rects[i]); 188 result.unite(rects[i]);
181 189
182 return result; 190 return result;
183 } 191 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 return FloatRect(); 226 return FloatRect();
219 227
220 float widthScale = destRect.width() / srcRect.width(); 228 float widthScale = destRect.width() / srcRect.width();
221 float heightScale = destRect.height() / srcRect.height(); 229 float heightScale = destRect.height() / srcRect.height();
222 return FloatRect(destRect.x() + (r.x() - srcRect.x()) * widthScale, 230 return FloatRect(destRect.x() + (r.x() - srcRect.x()) * widthScale,
223 destRect.y() + (r.y() - srcRect.y()) * heightScale, 231 destRect.y() + (r.y() - srcRect.y()) * heightScale,
224 r.width() * widthScale, r.height() * heightScale); 232 r.width() * widthScale, r.height() * heightScale);
225 } 233 }
226 234
227 } 235 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/geometry/FloatRect.h ('k') | third_party/WebKit/Source/platform/geometry/FloatRectTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698