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

Side by Side Diff: ui/gfx/geometry/rect.h

Issue 1186133003: gfx: Fix ToEnclosing/ToEnclosed math to deal with big numbers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move function Created 5 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 | « no previous file | ui/gfx/geometry/rect.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Defines a simple integer rectangle class. The containment semantics 5 // Defines a simple integer rectangle class. The containment semantics
6 // are array-like; that is, the coordinate (x, y) is considered to be 6 // are array-like; that is, the coordinate (x, y) is considered to be
7 // contained by the rectangle, but the coordinate (x + width, y) is not. 7 // contained by the rectangle, but the coordinate (x + width, y) is not.
8 // The class will happily let you create malformed rectangles (that is, 8 // The class will happily let you create malformed rectangles (that is,
9 // rectangles with negative width and/or height), but there will be assertions 9 // rectangles with negative width and/or height), but there will be assertions
10 // in the operations (such as Contains()) to complain in this case. 10 // in the operations (such as Contains()) to complain in this case.
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 x : static_cast<int>(std::ceil(rect.right() * x_scale)); 238 x : static_cast<int>(std::ceil(rect.right() * x_scale));
239 int b = rect.height() == 0 ? 239 int b = rect.height() == 0 ?
240 y : static_cast<int>(std::ceil(rect.bottom() * y_scale)); 240 y : static_cast<int>(std::ceil(rect.bottom() * y_scale));
241 return Rect(x, y, r - x, b - y); 241 return Rect(x, y, r - x, b - y);
242 } 242 }
243 243
244 inline Rect ScaleToEnclosingRect(const Rect& rect, float scale) { 244 inline Rect ScaleToEnclosingRect(const Rect& rect, float scale) {
245 return ScaleToEnclosingRect(rect, scale, scale); 245 return ScaleToEnclosingRect(rect, scale, scale);
246 } 246 }
247 247
248 // Returns the smallest Rect that encloses the given Rect after scaling by
249 // scale. If the result is scaling would make any dimension of the rect be too
danakj 2015/06/15 19:13:47 result from
250 // big to be represented by an integer, then use the largest integer for that
251 // dimension.
252 // Note that the resulting rect x(), y(), width(), height(), right(), bottom()
253 // will all return valid integer values. This means that if x() is max_int,
254 // then width would() have to be 0 in order for right() to be max_int.
255 GFX_EXPORT Rect SafelyScaleToEnclosingRect(const Rect& rect, float scale);
danakj 2015/06/15 19:13:47 Should we be returning a bool equivalent of |clipp
256
248 inline Rect ScaleToEnclosedRect(const Rect& rect, 257 inline Rect ScaleToEnclosedRect(const Rect& rect,
249 float x_scale, 258 float x_scale,
250 float y_scale) { 259 float y_scale) {
251 DCHECK(base::IsValueInRangeForNumericType<int>( 260 DCHECK(base::IsValueInRangeForNumericType<int>(
252 std::ceil(rect.x() * x_scale))); 261 std::ceil(rect.x() * x_scale)));
253 DCHECK(base::IsValueInRangeForNumericType<int>( 262 DCHECK(base::IsValueInRangeForNumericType<int>(
254 std::ceil(rect.y() * y_scale))); 263 std::ceil(rect.y() * y_scale)));
255 DCHECK(base::IsValueInRangeForNumericType<int>( 264 DCHECK(base::IsValueInRangeForNumericType<int>(
256 std::floor(rect.right() * x_scale))); 265 std::floor(rect.right() * x_scale)));
257 DCHECK(base::IsValueInRangeForNumericType<int>( 266 DCHECK(base::IsValueInRangeForNumericType<int>(
(...skipping 12 matching lines...) Expand all
270 } 279 }
271 280
272 // This is declared here for use in gtest-based unit tests but is defined in 281 // This is declared here for use in gtest-based unit tests but is defined in
273 // the gfx_test_support target. Depend on that to use this in your unit test. 282 // the gfx_test_support target. Depend on that to use this in your unit test.
274 // This should not be used in production code - call ToString() instead. 283 // This should not be used in production code - call ToString() instead.
275 void PrintTo(const Rect& rect, ::std::ostream* os); 284 void PrintTo(const Rect& rect, ::std::ostream* os);
276 285
277 } // namespace gfx 286 } // namespace gfx
278 287
279 #endif // UI_GFX_GEOMETRY_RECT_H_ 288 #endif // UI_GFX_GEOMETRY_RECT_H_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/geometry/rect.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698