Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 x : static_cast<int>(std::floor(rect.right() * x_scale)); | 333 x : static_cast<int>(std::floor(rect.right() * x_scale)); |
| 334 int b = rect.height() == 0 ? | 334 int b = rect.height() == 0 ? |
| 335 y : static_cast<int>(std::floor(rect.bottom() * y_scale)); | 335 y : static_cast<int>(std::floor(rect.bottom() * y_scale)); |
| 336 return Rect(x, y, r - x, b - y); | 336 return Rect(x, y, r - x, b - y); |
| 337 } | 337 } |
| 338 | 338 |
| 339 inline Rect ScaleToEnclosedRect(const Rect& rect, float scale) { | 339 inline Rect ScaleToEnclosedRect(const Rect& rect, float scale) { |
| 340 return ScaleToEnclosedRect(rect, scale, scale); | 340 return ScaleToEnclosedRect(rect, scale, scale); |
| 341 } | 341 } |
| 342 | 342 |
| 343 inline Rect ScaleToCornerScaledRect(const Rect& rect, | |
|
vmpstr
2017/07/11 17:37:22
Should this be called something like ScaleToRounde
malaykeshav
2017/07/12 00:55:36
Done.
Forgot to rename when moved it here from Pa
| |
| 344 float x_scale, | |
| 345 float y_scale) { | |
| 346 if (x_scale == 1.f && y_scale == 1.f) | |
| 347 return rect; | |
| 348 | |
| 349 DCHECK( | |
| 350 base::IsValueInRangeForNumericType<int>(std::round(rect.x() * x_scale))); | |
| 351 DCHECK( | |
| 352 base::IsValueInRangeForNumericType<int>(std::round(rect.y() * y_scale))); | |
| 353 DCHECK(base::IsValueInRangeForNumericType<int>( | |
| 354 std::round(rect.right() * x_scale))); | |
| 355 DCHECK(base::IsValueInRangeForNumericType<int>( | |
| 356 std::round(rect.bottom() * y_scale))); | |
| 357 | |
| 358 int x = static_cast<int>(std::round(rect.x() * x_scale)); | |
| 359 int y = static_cast<int>(std::round(rect.y() * y_scale)); | |
| 360 int r = rect.width() == 0 | |
| 361 ? x | |
| 362 : static_cast<int>(std::round(rect.right() * x_scale)); | |
| 363 int b = rect.height() == 0 | |
| 364 ? y | |
| 365 : static_cast<int>(std::round(rect.bottom() * y_scale)); | |
| 366 | |
| 367 return Rect(x, y, r - x, b - y); | |
| 368 } | |
| 369 | |
| 370 inline Rect ScaleToCornerScaledRect(const Rect& rect, float scale) { | |
| 371 return ScaleToCornerScaledRect(rect, scale, scale); | |
| 372 } | |
| 373 | |
| 343 // This is declared here for use in gtest-based unit tests but is defined in | 374 // This is declared here for use in gtest-based unit tests but is defined in |
| 344 // the //ui/gfx:test_support target. Depend on that to use this in your unit | 375 // the //ui/gfx:test_support target. Depend on that to use this in your unit |
| 345 // test. This should not be used in production code - call ToString() instead. | 376 // test. This should not be used in production code - call ToString() instead. |
| 346 void PrintTo(const Rect& rect, ::std::ostream* os); | 377 void PrintTo(const Rect& rect, ::std::ostream* os); |
| 347 | 378 |
| 348 } // namespace gfx | 379 } // namespace gfx |
| 349 | 380 |
| 350 #endif // UI_GFX_GEOMETRY_RECT_H_ | 381 #endif // UI_GFX_GEOMETRY_RECT_H_ |
| OLD | NEW |