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

Unified Diff: ui/gfx/rect_conversions.cc

Issue 10996037: Do not convert from RectF to Rect by flooring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing mac build. Created 8 years, 3 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
« no previous file with comments | « ui/gfx/rect_conversions.h ('k') | ui/gfx/rect_f.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/rect_conversions.cc
diff --git a/ui/gfx/rect_conversions.cc b/ui/gfx/rect_conversions.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0d8fdb5e09cdd9979b11495fb8542eb06e58a04d
--- /dev/null
+++ b/ui/gfx/rect_conversions.cc
@@ -0,0 +1,32 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/rect_conversions.h"
+
+#include "ui/gfx/safe_floor_ceil.h"
+
+namespace gfx {
+
+Rect ToEnclosingRect(const RectF& rect) {
+ int min_x = ToFlooredInt(rect.origin().x());
+ int min_y = ToFlooredInt(rect.origin().y());
+ float max_x = rect.origin().x() + rect.size().width();
+ float max_y = rect.origin().y() + rect.size().height();
+ int width = std::max(ToCeiledInt(max_x) - min_x, 0);
+ int height = std::max(ToCeiledInt(max_y) - min_y, 0);
+ return Rect(min_x, min_y, width, height);
+}
+
+Rect ToEnclosedRect(const RectF& rect) {
+ int min_x = ToCeiledInt(rect.origin().x());
+ int min_y = ToCeiledInt(rect.origin().y());
+ float max_x = rect.origin().x() + rect.size().width();
+ float max_y = rect.origin().y() + rect.size().height();
+ int width = std::max(ToFlooredInt(max_x) - min_x, 0);
+ int height = std::max(ToFlooredInt(max_y) - min_y, 0);
+ return Rect(min_x, min_y, width, height);
+}
+
+} // namespace gfx
+
« no previous file with comments | « ui/gfx/rect_conversions.h ('k') | ui/gfx/rect_f.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698