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

Side by Side Diff: Source/WebCore/platform/graphics/FloatRect.cpp

Issue 7155005: Merge 87103 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/742/
Patch Set: Created 9 years, 6 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
« no previous file with comments | « Source/JavaScriptCore/wtf/MathExtras.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 void FloatRect::fitToPoints(const FloatPoint& p0, const FloatPoint& p1, const Fl oatPoint& p2, const FloatPoint& p3) 175 void FloatRect::fitToPoints(const FloatPoint& p0, const FloatPoint& p1, const Fl oatPoint& p2, const FloatPoint& p3)
176 { 176 {
177 float left = min4(p0.x(), p1.x(), p2.x(), p3.x()); 177 float left = min4(p0.x(), p1.x(), p2.x(), p3.x());
178 float top = min4(p0.y(), p1.y(), p2.y(), p3.y()); 178 float top = min4(p0.y(), p1.y(), p2.y(), p3.y());
179 float right = max4(p0.x(), p1.x(), p2.x(), p3.x()); 179 float right = max4(p0.x(), p1.x(), p2.x(), p3.x());
180 float bottom = max4(p0.y(), p1.y(), p2.y(), p3.y()); 180 float bottom = max4(p0.y(), p1.y(), p2.y(), p3.y());
181 181
182 setLocationAndSizeFromEdges(left, top, right, bottom); 182 setLocationAndSizeFromEdges(left, top, right, bottom);
183 } 183 }
184 184
185 static inline int safeFloatToInt(float x)
186 {
187 static const int s_intMax = std::numeric_limits<int>::max();
188 static const int s_intMin = std::numeric_limits<int>::min();
189
190 if (x >= static_cast<float>(s_intMax))
191 return s_intMax;
192 if (x < static_cast<float>(s_intMin))
193 return s_intMin;
194 return static_cast<int>(x);
195 }
196
197 IntRect enclosingIntRect(const FloatRect& rect) 185 IntRect enclosingIntRect(const FloatRect& rect)
198 { 186 {
199 float left = floorf(rect.x()); 187 float left = floorf(rect.x());
200 float top = floorf(rect.y()); 188 float top = floorf(rect.y());
201 float width = ceilf(rect.maxX()) - left; 189 float width = ceilf(rect.maxX()) - left;
202 float height = ceilf(rect.maxY()) - top; 190 float height = ceilf(rect.maxY()) - top;
203 191
204 return IntRect(safeFloatToInt(left), safeFloatToInt(top), 192 return IntRect(clampToInteger(left), clampToInteger(top),
205 safeFloatToInt(width), safeFloatToInt(height)); 193 clampToInteger(width), clampToInteger(height));
206 } 194 }
207 195
208 FloatRect mapRect(const FloatRect& r, const FloatRect& srcRect, const FloatRect& destRect) 196 FloatRect mapRect(const FloatRect& r, const FloatRect& srcRect, const FloatRect& destRect)
209 { 197 {
210 if (srcRect.width() == 0 || srcRect.height() == 0) 198 if (srcRect.width() == 0 || srcRect.height() == 0)
211 return FloatRect(); 199 return FloatRect();
212 200
213 float widthScale = destRect.width() / srcRect.width(); 201 float widthScale = destRect.width() / srcRect.width();
214 float heightScale = destRect.height() / srcRect.height(); 202 float heightScale = destRect.height() / srcRect.height();
215 return FloatRect(destRect.x() + (r.x() - srcRect.x()) * widthScale, 203 return FloatRect(destRect.x() + (r.x() - srcRect.x()) * widthScale,
216 destRect.y() + (r.y() - srcRect.y()) * heightScale, 204 destRect.y() + (r.y() - srcRect.y()) * heightScale,
217 r.width() * widthScale, r.height() * heightScale); 205 r.width() * widthScale, r.height() * heightScale);
218 } 206 }
219 207
220 } 208 }
OLDNEW
« no previous file with comments | « Source/JavaScriptCore/wtf/MathExtras.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698