17#include <CoreGraphics/CoreGraphics.h>
18#elif defined(OS_APPLE)
19#include <ApplicationServices/ApplicationServices.h>
29 if (*origin < dst_origin)
32 *origin = std::min(dst_origin + dst_size, *origin + *
size) - *
size;
39CGRect RectF::ToCGRect()
const {
48void RectF::Inset(
float left,
float top,
float right,
float bottom) {
50 set_width(std::max(
width() - left - right, 0.0f));
51 set_height(std::max(
height() - top - bottom, 0.0f));
54void RectF::Offset(
float horizontal,
float vertical) {
55 origin_ +=
Vector2dF(horizontal, vertical);
68 right() - inner.
right());
71bool RectF::operator<(
const RectF& other)
const {
72 if (origin_ != other.origin_)
73 return origin_ < other.origin_;
80bool RectF::Contains(
float point_x,
float point_y)
const {
81 return point_x >=
x() && point_x < right() && point_y >=
y() &&
85bool RectF::Contains(
const RectF& rect)
const {
86 return rect.
x() >=
x() && rect.
right() <= right() && rect.
y() >=
y() &&
90bool RectF::Intersects(
const RectF& rect)
const {
91 return !IsEmpty() && !rect.
IsEmpty() && rect.
x() < right() &&
95void RectF::Intersect(
const RectF& rect) {
96 if (IsEmpty() || rect.
IsEmpty()) {
101 float rx = std::max(
x(), rect.
x());
102 float ry = std::max(
y(), rect.
y());
103 float rr = std::min(right(), rect.
right());
104 float rb = std::min(bottom(), rect.
bottom());
106 if (rx >= rr || ry >= rb) {
111 SetRect(rx, ry, rr - rx, rb - ry);
114void RectF::Union(
const RectF& rect) {
122 float rx = std::min(
x(), rect.
x());
123 float ry = std::min(
y(), rect.
y());
124 float rr = std::max(right(), rect.
right());
125 float rb = std::max(bottom(), rect.
bottom());
127 SetRect(rx, ry, rr - rx, rb - ry);
130void RectF::Subtract(
const RectF& rect) {
131 if (!Intersects(rect))
143 if (rect.
y() <=
y() && rect.
bottom() >= bottom()) {
145 if (rect.
x() <=
x()) {
147 }
else if (rect.
right() >= right()) {
150 }
else if (rect.
x() <=
x() && rect.
right() >= right()) {
152 if (rect.
y() <=
y()) {
154 }
else if (rect.
bottom() >= bottom()) {
158 SetRect(rx, ry, rr - rx, rb - ry);
161void RectF::AdjustToFit(
const RectF& rect) {
164 float new_width =
width();
165 float new_height =
height();
168 SetRect(new_x, new_y, new_width, new_height);
175void RectF::ClampToCenteredSize(
const SizeF& size) {
176 float new_width = std::min(
width(), size.width());
177 float new_height = std::min(
height(), size.height());
178 float new_x =
x() + (
width() - new_width) / 2;
179 float new_y =
y() + (
height() - new_height) / 2;
180 SetRect(new_x, new_y, new_width, new_height);
183void RectF::Transpose() {
187void RectF::SplitVertically(
RectF* left_half,
RectF* right_half)
const {
196bool RectF::SharesEdgeWith(
const RectF& rect)
const {
198 (
x() == rect.
right() || right() == rect.
x())) ||
200 (
y() == rect.
bottom() || bottom() == rect.
y()));
203float RectF::ManhattanDistanceToPoint(
const PointF& point)
const {
205 std::max<float>(0, std::max(
x() - point.
x(), point.
x() - right()));
207 std::max<float>(0, std::max(
y() - point.
y(), point.
y() - bottom()));
209 return x_distance + y_distance;
212float RectF::ManhattanInternalDistance(
const RectF& rect)
const {
216 static constexpr float kEpsilon = std::numeric_limits<float>::epsilon();
222bool RectF::IsExpressibleAsRect()
const {
223 return base::IsValueInRangeForNumericType<int>(
x()) &&
224 base::IsValueInRangeForNumericType<int>(
y()) &&
225 base::IsValueInRangeForNumericType<int>(
width()) &&
226 base::IsValueInRangeForNumericType<int>(
height()) &&
227 base::IsValueInRangeForNumericType<int>(right()) &&
228 base::IsValueInRangeForNumericType<int>(bottom());
231std::string RectF::ToString()
const {
233 size().ToString().c_str());
255 float rx = std::min(p1.
x(), p2.
x());
256 float ry = std::min(p1.
y(), p2.
y());
257 float rr = std::max(p1.
x(), p2.
x());
258 float rb = std::max(p1.
y(), p2.
y());
259 return RectF(rx, ry, rr - rx, rb - ry);
constexpr float left() const
constexpr float bottom() const
constexpr float top() const
constexpr float right() const
constexpr float x() const
constexpr float y() const
constexpr RectF()=default
constexpr float y() const
constexpr float width() const
constexpr float height() const
void Union(const RectF &rect)
void Intersect(const RectF &rect)
constexpr float right() const
bool Contains(float point_x, float point_y) const
constexpr float bottom() const
void Subtract(const RectF &rect)
void SetRect(float x, float y, float width, float height)
constexpr float x() const
std::string StringPrintf(const std::string &format, Args... args)
Rect BoundingRect(const Point &p1, const Point &p2)
void AdjustAlongAxis(int dst_origin, int dst_size, int *origin, int *size)
Rect IntersectRects(const Rect &a, const Rect &b)
Rect UnionRects(const Rect &a, const Rect &b)
Rect SubtractRects(const Rect &a, const Rect &b)
constexpr size_t size(const T(&array)[N]) noexcept
#define BASE_DCHECK(condition)