OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 #include "platform/geometry/FloatRect.h" | 28 #include "platform/geometry/FloatRect.h" |
29 | 29 |
30 #include "platform/FloatConversion.h" | 30 #include "platform/FloatConversion.h" |
31 #include "platform/geometry/IntRect.h" | 31 #include "platform/geometry/IntRect.h" |
32 #include "platform/geometry/LayoutRect.h" | 32 #include "platform/geometry/LayoutRect.h" |
33 #include "third_party/skia/include/core/SkRect.h" | 33 #include "third_party/skia/include/core/SkRect.h" |
34 #include "wtf/MathExtras.h" | 34 #include "wtf/MathExtras.h" |
35 | 35 |
36 #include <algorithm> | |
37 #include <math.h> | |
38 | |
39 namespace blink { | 36 namespace blink { |
40 | 37 |
41 FloatRect::FloatRect(const IntRect& r) : m_location(r.location()), m_size(r.size
()) | 38 FloatRect::FloatRect(const IntRect& r) : m_location(r.location()), m_size(r.size
()) |
42 { | 39 { |
43 } | 40 } |
44 | 41 |
45 FloatRect::FloatRect(const LayoutRect& r) : m_location(r.location()), m_size(r.s
ize()) | 42 FloatRect::FloatRect(const LayoutRect& r) : m_location(r.location()), m_size(r.s
ize()) |
46 { | 43 { |
47 } | 44 } |
48 | 45 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 { | 166 { |
170 FloatRect result; | 167 FloatRect result; |
171 | 168 |
172 size_t count = rects.size(); | 169 size_t count = rects.size(); |
173 for (size_t i = 0; i < count; ++i) | 170 for (size_t i = 0; i < count; ++i) |
174 result.unite(rects[i]); | 171 result.unite(rects[i]); |
175 | 172 |
176 return result; | 173 return result; |
177 } | 174 } |
178 | 175 |
179 void FloatRect::fitToPoints(const FloatPoint& p0, const FloatPoint& p1) | |
180 { | |
181 float left = std::min(p0.x(), p1.x()); | |
182 float top = std::min(p0.y(), p1.y()); | |
183 float right = std::max(p0.x(), p1.x()); | |
184 float bottom = std::max(p0.y(), p1.y()); | |
185 | |
186 setLocationAndSizeFromEdges(left, top, right, bottom); | |
187 } | |
188 | |
189 namespace { | |
190 // Helpers for 3- and 4-way max and min. | |
191 | |
192 template <typename T> | |
193 T min3(const T& v1, const T& v2, const T& v3) | |
194 { | |
195 return std::min(std::min(v1, v2), v3); | |
196 } | |
197 | |
198 template <typename T> | |
199 T max3(const T& v1, const T& v2, const T& v3) | |
200 { | |
201 return std::max(std::max(v1, v2), v3); | |
202 } | |
203 | |
204 template <typename T> | |
205 T min4(const T& v1, const T& v2, const T& v3, const T& v4) | |
206 { | |
207 return std::min(std::min(v1, v2), std::min(v3, v4)); | |
208 } | |
209 | |
210 template <typename T> | |
211 T max4(const T& v1, const T& v2, const T& v3, const T& v4) | |
212 { | |
213 return std::max(std::max(v1, v2), std::max(v3, v4)); | |
214 } | |
215 | |
216 } // anonymous namespace | |
217 | |
218 void FloatRect::fitToPoints(const FloatPoint& p0, const FloatPoint& p1, const Fl
oatPoint& p2) | |
219 { | |
220 float left = min3(p0.x(), p1.x(), p2.x()); | |
221 float top = min3(p0.y(), p1.y(), p2.y()); | |
222 float right = max3(p0.x(), p1.x(), p2.x()); | |
223 float bottom = max3(p0.y(), p1.y(), p2.y()); | |
224 | |
225 setLocationAndSizeFromEdges(left, top, right, bottom); | |
226 } | |
227 | |
228 void FloatRect::fitToPoints(const FloatPoint& p0, const FloatPoint& p1, const Fl
oatPoint& p2, const FloatPoint& p3) | |
229 { | |
230 float left = min4(p0.x(), p1.x(), p2.x(), p3.x()); | |
231 float top = min4(p0.y(), p1.y(), p2.y(), p3.y()); | |
232 float right = max4(p0.x(), p1.x(), p2.x(), p3.x()); | |
233 float bottom = max4(p0.y(), p1.y(), p2.y(), p3.y()); | |
234 | |
235 setLocationAndSizeFromEdges(left, top, right, bottom); | |
236 } | |
237 | |
238 #ifndef NDEBUG | 176 #ifndef NDEBUG |
239 void FloatRect::show() const | 177 void FloatRect::show() const |
240 { | 178 { |
241 LayoutRect(*this).show(); | 179 LayoutRect(*this).show(); |
242 } | 180 } |
243 #endif | 181 #endif |
244 | 182 |
245 IntRect enclosingIntRect(const FloatRect& rect) | 183 IntRect enclosingIntRect(const FloatRect& rect) |
246 { | 184 { |
247 IntPoint location = flooredIntPoint(rect.minXMinYCorner()); | 185 IntPoint location = flooredIntPoint(rect.minXMinYCorner()); |
(...skipping 23 matching lines...) Expand all Loading... |
271 return FloatRect(); | 209 return FloatRect(); |
272 | 210 |
273 float widthScale = destRect.width() / srcRect.width(); | 211 float widthScale = destRect.width() / srcRect.width(); |
274 float heightScale = destRect.height() / srcRect.height(); | 212 float heightScale = destRect.height() / srcRect.height(); |
275 return FloatRect(destRect.x() + (r.x() - srcRect.x()) * widthScale, | 213 return FloatRect(destRect.x() + (r.x() - srcRect.x()) * widthScale, |
276 destRect.y() + (r.y() - srcRect.y()) * heightScale, | 214 destRect.y() + (r.y() - srcRect.y()) * heightScale, |
277 r.width() * widthScale, r.height() * heightScale); | 215 r.width() * widthScale, r.height() * heightScale); |
278 } | 216 } |
279 | 217 |
280 } | 218 } |
OLD | NEW |