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

Unified Diff: ui/gfx/geometry/rect.h

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: Merged PaintContext Offset into paint_recording_bounds_ Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/geometry/rect.h
diff --git a/ui/gfx/geometry/rect.h b/ui/gfx/geometry/rect.h
index 1858d44d2c765537100072f4f0d845c91d2d2c9e..23918c4bbeba5bda5424eb432df860a3b8adb649 100644
--- a/ui/gfx/geometry/rect.h
+++ b/ui/gfx/geometry/rect.h
@@ -340,6 +340,37 @@ inline Rect ScaleToEnclosedRect(const Rect& rect, float scale) {
return ScaleToEnclosedRect(rect, scale, scale);
}
+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
+ float x_scale,
+ float y_scale) {
+ if (x_scale == 1.f && y_scale == 1.f)
+ return rect;
+
+ DCHECK(
+ base::IsValueInRangeForNumericType<int>(std::round(rect.x() * x_scale)));
+ DCHECK(
+ base::IsValueInRangeForNumericType<int>(std::round(rect.y() * y_scale)));
+ DCHECK(base::IsValueInRangeForNumericType<int>(
+ std::round(rect.right() * x_scale)));
+ DCHECK(base::IsValueInRangeForNumericType<int>(
+ std::round(rect.bottom() * y_scale)));
+
+ int x = static_cast<int>(std::round(rect.x() * x_scale));
+ int y = static_cast<int>(std::round(rect.y() * y_scale));
+ int r = rect.width() == 0
+ ? x
+ : static_cast<int>(std::round(rect.right() * x_scale));
+ int b = rect.height() == 0
+ ? y
+ : static_cast<int>(std::round(rect.bottom() * y_scale));
+
+ return Rect(x, y, r - x, b - y);
+}
+
+inline Rect ScaleToCornerScaledRect(const Rect& rect, float scale) {
+ return ScaleToCornerScaledRect(rect, scale, scale);
+}
+
// This is declared here for use in gtest-based unit tests but is defined in
// the //ui/gfx:test_support target. Depend on that to use this in your unit
// test. This should not be used in production code - call ToString() instead.

Powered by Google App Engine
This is Rietveld 408576698