| 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
|
|
|