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

Unified Diff: cc/math/int_rect.cc

Issue 10984053: cc: Use ui/gfx geometry types for the CCRenderPass and CCDrawQuad classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
Index: cc/math/int_rect.cc
diff --git a/cc/math/int_rect.cc b/cc/math/int_rect.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c5721e8659284d1d4163514e45cd47941523c915
--- /dev/null
+++ b/cc/math/int_rect.cc
@@ -0,0 +1,77 @@
+// Copyright 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 "cc/math/int_rect.h"
+
+#include <algorithm>
+
+using std::min;
+using std::max;
+
+namespace ccmath {
+
+bool IntRect::Contains(IntRect other) const {
+ return
+ x() <= other.x() && max_x() >= other.max_x() &&
+ y() <= other.y() && max_y() >= other.max_y();
+ }
+
+bool IntRect::IsEmpty() const {
+ return m_size.IsEmpty();
+}
+
+void IntRect::InflateX(float amount) {
+ set_x(x() + amount);
+}
+
+void IntRect::InflateY(float amount) {
+ set_y(y() + amount);
+}
+
+void IntRect::InflateWidth(float amount) {
+ set_width(width() + amount);
+}
+
+void IntRect::InflateHeight(float amount) {
+ set_height(height() + amount);
+}
+
+void IntRect::Intersect(IntRect other) {
+ int min_x = max(x(), other.x());
+ int min_y = max(y(), other.y());
+ int max_x = min(this->max_x(), other.max_x());
+ int max_y = min(this->max_y(), other.max_y());
+
+ set_x(min_x);
+ set_y(min_y);
+ set_width(max_x - min_x);
+ set_height(max_y - min_y);
+ m_size.ClampToNonNegative();
+}
+
+void IntRect::Unite(IntRect other) {
+ int min_x = min(x(), other.x());
+ int min_y = min(y(), other.y());
+ int max_x = max(this->max_x(), other.max_x());
+ int max_y = max(this->max_y(), other.max_y());
+
+ set_x(min_x);
+ set_y(min_y);
+ set_width(max_x - min_x);
+ set_height(max_y - min_y);
+}
+
+IntRect IntRect::Intersection(IntRect a, IntRect b) {
+ IntRect result = a;
+ result.Intersect(b);
+ return result;
+}
+
+IntRect IntRect::Union(IntRect a, IntRect b) {
+ IntRect result = a;
+ result.Unite(b);
+ return result;
+}
+
+} // namespace ccmath
« cc/math/int_point.h ('K') | « cc/math/int_rect.h ('k') | cc/math/int_size.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698