#include "ui/gfx/geometry/rect.h"
#include <algorithm>
#include "base/check.h"
#include "base/numerics/clamped_math.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/outsets.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#elif BUILDFLAG(IS_IOS)
#include <CoreGraphics/CoreGraphics.h>
#elif BUILDFLAG(IS_MAC)
#include <ApplicationServices/ApplicationServices.h>
#endif
namespace {
void AdjustAlongAxis(int dst_origin, int dst_size, int* origin, int* size) { … }
void SaturatedClampRange(int min, int max, int* origin, int* span) { … }
}
namespace gfx {
#if BUILDFLAG(IS_WIN)
Rect::Rect(const RECT& r)
: origin_(r.left, r.top),
size_(std::abs(r.right - r.left), std::abs(r.bottom - r.top)) {}
RECT Rect::ToRECT() const {
RECT r;
r.left = x();
r.right = right();
r.top = y();
r.bottom = bottom();
return r;
}
#elif BUILDFLAG(IS_APPLE)
Rect::Rect(const CGRect& r)
: origin_(r.origin.x, r.origin.y), size_(r.size.width, r.size.height) {}
CGRect Rect::ToCGRect() const {
return CGRectMake(x(), y(), width(), height());
}
#endif
void Rect::AdjustForSaturatedRight(int right) { … }
void Rect::AdjustForSaturatedBottom(int bottom) { … }
void Rect::Inset(const Insets& insets) { … }
void Rect::Offset(const Vector2d& distance) { … }
Insets Rect::InsetsFrom(const Rect& inner) const { … }
bool Rect::operator<(const Rect& other) const { … }
bool Rect::Contains(int point_x, int point_y) const { … }
bool Rect::Contains(const Rect& rect) const { … }
bool Rect::Intersects(const Rect& rect) const { … }
void Rect::Intersect(const Rect& rect) { … }
bool Rect::InclusiveIntersect(const Rect& rect) { … }
void Rect::Union(const Rect& rect) { … }
void Rect::UnionEvenIfEmpty(const Rect& rect) { … }
void Rect::Subtract(const Rect& rect) { … }
void Rect::AdjustToFit(const Rect& rect) { … }
Point Rect::CenterPoint() const { … }
void Rect::ClampToCenteredSize(const Size& size) { … }
void Rect::Transpose() { … }
void Rect::SplitVertically(Rect& left_half, Rect& right_half) const { … }
void Rect::SplitHorizontally(Rect& top_half, Rect& bottom_half) const { … }
bool Rect::SharesEdgeWith(const Rect& rect) const { … }
int Rect::ManhattanDistanceToPoint(const Point& point) const { … }
int Rect::ManhattanInternalDistance(const Rect& rect) const { … }
std::string Rect::ToString() const { … }
bool Rect::ApproximatelyEqual(const Rect& rect, int tolerance) const { … }
Rect operator+(const Rect& lhs, const Vector2d& rhs) { … }
Rect operator-(const Rect& lhs, const Vector2d& rhs) { … }
Rect IntersectRects(const Rect& a, const Rect& b) { … }
Rect UnionRects(const Rect& a, const Rect& b) { … }
Rect UnionRectsEvenIfEmpty(const Rect& a, const Rect& b) { … }
Rect SubtractRects(const Rect& a, const Rect& b) { … }
Rect BoundingRect(const Point& p1, const Point& p2) { … }
Rect ScaleToEnclosingRectIgnoringError(const Rect& rect,
float scale,
float epsilon) { … }
Rect MaximumCoveredRect(const Rect& a, const Rect& b) { … }
}