| Index: cc/math/float_rect.cc
|
| diff --git a/cc/math/float_rect.cc b/cc/math/float_rect.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..07c16a97c3d42957b58785a22210b30a48ed3f79
|
| --- /dev/null
|
| +++ b/cc/math/float_rect.cc
|
| @@ -0,0 +1,111 @@
|
| +// 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/float_rect.h"
|
| +
|
| +#include <algorithm>
|
| +
|
| +using std::min;
|
| +using std::max;
|
| +
|
| +namespace ccmath {
|
| +
|
| +bool FloatRect::Contains(IntRect other) const {
|
| + return
|
| + x() <= other.x() && max_x() >= other.max_x() &&
|
| + y() <= other.y() && max_y() >= other.max_y();
|
| +}
|
| +
|
| +bool FloatRect::IsEmpty() const {
|
| + return m_size.IsEmpty();
|
| +}
|
| +
|
| +IntRect FloatRect::EnclosingIntRect() const {
|
| + FloatPoint min_xy = m_location;
|
| + FloatPoint max_xy = FloatPoint(max_x(), max_y());
|
| +
|
| + IntPoint floored_min_xy = min_xy.FlooredIntPoint();
|
| + IntPoint ceiled_max_xy = max_xy.CeiledIntPoint();
|
| +
|
| + IntSize size(ceiled_max_xy.x() - floored_min_xy.x(),
|
| + ceiled_max_xy.y() - floored_min_xy.y());
|
| +
|
| + return IntRect(floored_min_xy, size);
|
| +}
|
| +
|
| +IntRect FloatRect::EnclosedIntRect() const {
|
| + FloatPoint min_xy = m_location;
|
| + FloatPoint max_xy = FloatPoint(max_x(), max_y());
|
| +
|
| + IntPoint ceiled_min_xy = min_xy.CeiledIntPoint();
|
| + IntPoint floored_max_xy = max_xy.FlooredIntPoint();
|
| +
|
| + IntSize size(floored_max_xy.x() - ceiled_min_xy.x(),
|
| + floored_max_xy.y() - ceiled_min_xy.y());
|
| + size.ClampToNonNegative();
|
| +
|
| + return IntRect(ceiled_min_xy, size);
|
| +}
|
| +
|
| +void FloatRect::InflateX(float amount) {
|
| + set_x(x() + amount);
|
| +}
|
| +
|
| +void FloatRect::InflateY(float amount) {
|
| + set_y(y() + amount);
|
| +}
|
| +
|
| +void FloatRect::InflateWidth(float amount) {
|
| + set_width(width() + amount);
|
| +}
|
| +
|
| +void FloatRect::InflateHeight(float amount) {
|
| + set_height(height() + amount);
|
| +}
|
| +
|
| +void FloatRect::Intersect(FloatRect other) {
|
| + float min_x = max(x(), other.x());
|
| + float min_y = max(y(), other.y());
|
| + float max_x = min(this->max_x(), other.max_x());
|
| + float 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 FloatRect::Scale(float scale_x, float scale_y) {
|
| + set_x(x() * scale_x);
|
| + set_y(y() * scale_y);
|
| + set_width(width() * scale_x);
|
| + set_height(height() * scale_y);
|
| +}
|
| +
|
| +void FloatRect::Unite(FloatRect other) {
|
| + float min_x = min(x(), other.x());
|
| + float min_y = min(y(), other.y());
|
| + float max_x = max(this->max_x(), other.max_x());
|
| + float 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);
|
| +}
|
| +
|
| +FloatRect FloatRect::Intersection(FloatRect a, FloatRect b) {
|
| + FloatRect result = a;
|
| + result.Intersect(b);
|
| + return result;
|
| +}
|
| +
|
| +FloatRect FloatRect::Union(FloatRect a, FloatRect b) {
|
| + FloatRect result = a;
|
| + result.Unite(b);
|
| + return result;
|
| +}
|
| +
|
| +} // namespace ccmath
|
|
|