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

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

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: Resolving comments Created 3 years, 4 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 // 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
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 ScaleToRoundedRect(const Rect& rect, float x_scale, float y_scale) {
sky 2017/07/26 22:12:11 Please add a description. Also, given the descript
malaykeshav 2017/07/28 01:24:37 This specific name was used to give consistency as
344 if (x_scale == 1.f && y_scale == 1.f)
345 return rect;
346
347 DCHECK(
348 base::IsValueInRangeForNumericType<int>(std::round(rect.x() * x_scale)));
349 DCHECK(
350 base::IsValueInRangeForNumericType<int>(std::round(rect.y() * y_scale)));
351 DCHECK(base::IsValueInRangeForNumericType<int>(
352 std::round(rect.right() * x_scale)));
353 DCHECK(base::IsValueInRangeForNumericType<int>(
354 std::round(rect.bottom() * y_scale)));
355
356 int x = static_cast<int>(std::round(rect.x() * x_scale));
357 int y = static_cast<int>(std::round(rect.y() * y_scale));
358 int r = rect.width() == 0
359 ? x
360 : static_cast<int>(std::round(rect.right() * x_scale));
361 int b = rect.height() == 0
362 ? y
363 : static_cast<int>(std::round(rect.bottom() * y_scale));
364
365 return Rect(x, y, r - x, b - y);
366 }
367
368 inline Rect ScaleToRoundedRect(const Rect& rect, float scale) {
369 return ScaleToRoundedRect(rect, scale, scale);
370 }
371
343 // This is declared here for use in gtest-based unit tests but is defined in 372 // 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 373 // 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. 374 // test. This should not be used in production code - call ToString() instead.
346 void PrintTo(const Rect& rect, ::std::ostream* os); 375 void PrintTo(const Rect& rect, ::std::ostream* os);
347 376
348 } // namespace gfx 377 } // namespace gfx
349 378
350 #endif // UI_GFX_GEOMETRY_RECT_H_ 379 #endif // UI_GFX_GEOMETRY_RECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698