Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
gfx::RectF Class Reference

#include <rect_f.h>

Public Member Functions

constexpr RectF ()=default
 
constexpr RectF (float width, float height)
 
constexpr RectF (float x, float y, float width, float height)
 
constexpr RectF (const SizeF &size)
 
constexpr RectF (const PointF &origin, const SizeF &size)
 
constexpr RectF (const Rect &r)
 
constexpr float x () const
 
void set_x (float x)
 
constexpr float y () const
 
void set_y (float y)
 
constexpr float width () const
 
void set_width (float width)
 
constexpr float height () const
 
void set_height (float height)
 
constexpr const PointForigin () const
 
void set_origin (const PointF &origin)
 
constexpr const SizeFsize () const
 
void set_size (const SizeF &size)
 
constexpr float right () const
 
constexpr float bottom () const
 
constexpr PointF top_right () const
 
constexpr PointF bottom_left () const
 
constexpr PointF bottom_right () const
 
constexpr PointF left_center () const
 
constexpr PointF top_center () const
 
constexpr PointF right_center () const
 
constexpr PointF bottom_center () const
 
Vector2dF OffsetFromOrigin () const
 
void SetRect (float x, float y, float width, float height)
 
void Inset (float horizontal, float vertical)
 
void Inset (const InsetsF &insets)
 
void Inset (float left, float top, float right, float bottom)
 
void Offset (float horizontal, float vertical)
 
void Offset (const Vector2dF &distance)
 
void operator+= (const Vector2dF &offset)
 
void operator-= (const Vector2dF &offset)
 
InsetsF InsetsFrom (const RectF &inner) const
 
bool IsEmpty () const
 
bool operator< (const RectF &other) const
 
bool Contains (float point_x, float point_y) const
 
bool Contains (const PointF &point) const
 
bool Contains (const RectF &rect) const
 
bool Intersects (const RectF &rect) const
 
void Intersect (const RectF &rect)
 
void Union (const RectF &rect)
 
void Subtract (const RectF &rect)
 
void AdjustToFit (const RectF &rect)
 
PointF CenterPoint () const
 
void ClampToCenteredSize (const SizeF &size)
 
void Transpose ()
 
void SplitVertically (RectF *left_half, RectF *right_half) const
 
bool SharesEdgeWith (const RectF &rect) const
 
float ManhattanDistanceToPoint (const PointF &point) const
 
float ManhattanInternalDistance (const RectF &rect) const
 
void Scale (float scale)
 
void Scale (float x_scale, float y_scale)
 
bool IsExpressibleAsRect () const
 
std::string ToString () const
 

Detailed Description

Definition at line 26 of file rect_f.h.

Constructor & Destructor Documentation

◆ RectF() [1/6]

constexpr gfx::RectF::RectF ( )
constexprdefault

◆ RectF() [2/6]

constexpr gfx::RectF::RectF ( float  width,
float  height 
)
inlineconstexpr

Definition at line 29 of file rect_f.h.

29: size_(width, height) {}
constexpr float width() const
Definition rect_f.h:53
constexpr float height() const
Definition rect_f.h:56

◆ RectF() [3/6]

constexpr gfx::RectF::RectF ( float  x,
float  y,
float  width,
float  height 
)
inlineconstexpr

Definition at line 30 of file rect_f.h.

31 : origin_(x, y), size_(width, height) {}
constexpr float y() const
Definition rect_f.h:50
constexpr float x() const
Definition rect_f.h:47

◆ RectF() [4/6]

constexpr gfx::RectF::RectF ( const SizeF size)
inlineexplicitconstexpr

Definition at line 32 of file rect_f.h.

32: size_(size) {}
constexpr const SizeF & size() const
Definition rect_f.h:62

◆ RectF() [5/6]

constexpr gfx::RectF::RectF ( const PointF origin,
const SizeF size 
)
inlineconstexpr

Definition at line 33 of file rect_f.h.

33: origin_(origin), size_(size) {}
constexpr const PointF & origin() const
Definition rect_f.h:59

◆ RectF() [6/6]

constexpr gfx::RectF::RectF ( const Rect r)
inlineexplicitconstexpr

Definition at line 35 of file rect_f.h.

36 : RectF(static_cast<float>(r.x()),
37 static_cast<float>(r.y()),
38 static_cast<float>(r.width()),
39 static_cast<float>(r.height())) {}
constexpr RectF()=default

Member Function Documentation

◆ AdjustToFit()

void gfx::RectF::AdjustToFit ( const RectF rect)

Definition at line 161 of file rect_f.cc.

161 {
162 float new_x = x();
163 float new_y = y();
164 float new_width = width();
165 float new_height = height();
166 AdjustAlongAxis(rect.x(), rect.width(), &new_x, &new_width);
167 AdjustAlongAxis(rect.y(), rect.height(), &new_y, &new_height);
168 SetRect(new_x, new_y, new_width, new_height);
169}
void SetRect(float x, float y, float width, float height)
Definition rect_f.h:79
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
void AdjustAlongAxis(int dst_origin, int dst_size, int *origin, int *size)
Definition rect.cc:49

◆ bottom()

constexpr float gfx::RectF::bottom ( ) const
inlineconstexpr

Definition at line 66 of file rect_f.h.

66{ return y() + height(); }

◆ bottom_center()

constexpr PointF gfx::RectF::bottom_center ( ) const
inlineconstexpr

Definition at line 75 of file rect_f.h.

75{ return PointF(x() + width() / 2, bottom()); }
constexpr float bottom() const
Definition rect_f.h:66

◆ bottom_left()

constexpr PointF gfx::RectF::bottom_left ( ) const
inlineconstexpr

Definition at line 69 of file rect_f.h.

69{ return PointF(x(), bottom()); }

◆ bottom_right()

constexpr PointF gfx::RectF::bottom_right ( ) const
inlineconstexpr

Definition at line 70 of file rect_f.h.

70{ return PointF(right(), bottom()); }
constexpr float right() const
Definition rect_f.h:65

◆ CenterPoint()

PointF gfx::RectF::CenterPoint ( ) const

Definition at line 171 of file rect_f.cc.

171 {
172 return PointF(x() + width() / 2, y() + height() / 2);
173}

◆ ClampToCenteredSize()

void gfx::RectF::ClampToCenteredSize ( const SizeF size)

Definition at line 175 of file rect_f.cc.

175 {
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);
181}
constexpr float height() const
Definition size_f.h:29
constexpr float width() const
Definition size_f.h:28

◆ Contains() [1/3]

bool gfx::RectF::Contains ( const PointF point) const
inline

Definition at line 120 of file rect_f.h.

120{ return Contains(point.x(), point.y()); }
bool Contains(float point_x, float point_y) const
Definition rect_f.cc:80

◆ Contains() [2/3]

bool gfx::RectF::Contains ( const RectF rect) const

Definition at line 85 of file rect_f.cc.

85 {
86 return rect.x() >= x() && rect.right() <= right() && rect.y() >= y() &&
87 rect.bottom() <= bottom();
88}

◆ Contains() [3/3]

bool gfx::RectF::Contains ( float  point_x,
float  point_y 
) const

Definition at line 80 of file rect_f.cc.

80 {
81 return point_x >= x() && point_x < right() && point_y >= y() &&
82 point_y < bottom();
83}

◆ height()

constexpr float gfx::RectF::height ( ) const
inlineconstexpr

Definition at line 56 of file rect_f.h.

56{ return size_.height(); }

◆ Inset() [1/3]

void gfx::RectF::Inset ( const InsetsF insets)

Definition at line 44 of file rect_f.cc.

44 {
45 Inset(insets.left(), insets.top(), insets.right(), insets.bottom());
46}
void Inset(float horizontal, float vertical)
Definition rect_f.h:85

◆ Inset() [2/3]

void gfx::RectF::Inset ( float  horizontal,
float  vertical 
)
inline

Definition at line 85 of file rect_f.h.

85 {
86 Inset(horizontal, vertical, horizontal, vertical);
87 }

◆ Inset() [3/3]

void gfx::RectF::Inset ( float  left,
float  top,
float  right,
float  bottom 
)

Definition at line 48 of file rect_f.cc.

48 {
49 origin_ += Vector2dF(left, top);
50 set_width(std::max(width() - left - right, 0.0f));
51 set_height(std::max(height() - top - bottom, 0.0f));
52}
static bool left(const SkPoint &p0, const SkPoint &p1)
void set_width(float width)
Definition rect_f.h:54
void set_height(float height)
Definition rect_f.h:57

◆ InsetsFrom()

InsetsF gfx::RectF::InsetsFrom ( const RectF inner) const

Definition at line 66 of file rect_f.cc.

66 {
67 return InsetsF(inner.y() - y(), inner.x() - x(), bottom() - inner.bottom(),
68 right() - inner.right());
69}

◆ Intersect()

void gfx::RectF::Intersect ( const RectF rect)

Definition at line 95 of file rect_f.cc.

95 {
96 if (IsEmpty() || rect.IsEmpty()) {
97 SetRect(0, 0, 0, 0);
98 return;
99 }
100
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());
105
106 if (rx >= rr || ry >= rb) {
107 SetRect(0, 0, 0, 0);
108 return;
109 }
110
111 SetRect(rx, ry, rr - rx, rb - ry);
112}
bool IsEmpty() const
Definition rect_f.h:104

◆ Intersects()

bool gfx::RectF::Intersects ( const RectF rect) const

Definition at line 90 of file rect_f.cc.

90 {
91 return !IsEmpty() && !rect.IsEmpty() && rect.x() < right() &&
92 rect.right() > x() && rect.y() < bottom() && rect.bottom() > y();
93}

◆ IsEmpty()

bool gfx::RectF::IsEmpty ( ) const
inline

Definition at line 104 of file rect_f.h.

104{ return size_.IsEmpty(); }
bool IsEmpty() const
Definition size_f.h:46

◆ IsExpressibleAsRect()

bool gfx::RectF::IsExpressibleAsRect ( ) const

Definition at line 222 of file rect_f.cc.

222 {
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());
229}

◆ left_center()

constexpr PointF gfx::RectF::left_center ( ) const
inlineconstexpr

Definition at line 72 of file rect_f.h.

72{ return PointF(x(), y() + height() / 2); }

◆ ManhattanDistanceToPoint()

float gfx::RectF::ManhattanDistanceToPoint ( const PointF point) const

Definition at line 203 of file rect_f.cc.

203 {
204 float x_distance =
205 std::max<float>(0, std::max(x() - point.x(), point.x() - right()));
206 float y_distance =
207 std::max<float>(0, std::max(y() - point.y(), point.y() - bottom()));
208
209 return x_distance + y_distance;
210}

◆ ManhattanInternalDistance()

float gfx::RectF::ManhattanInternalDistance ( const RectF rect) const

Definition at line 212 of file rect_f.cc.

212 {
213 RectF c(*this);
214 c.Union(rect);
215
216 static constexpr float kEpsilon = std::numeric_limits<float>::epsilon();
217 float x = std::max(0.f, c.width() - width() - rect.width() + kEpsilon);
218 float y = std::max(0.f, c.height() - height() - rect.height() + kEpsilon);
219 return x + y;
220}
static constexpr double kEpsilon

◆ Offset() [1/2]

void gfx::RectF::Offset ( const Vector2dF distance)
inline

Definition at line 97 of file rect_f.h.

97{ Offset(distance.x(), distance.y()); }
void Offset(float horizontal, float vertical)
Definition rect_f.cc:54

◆ Offset() [2/2]

void gfx::RectF::Offset ( float  horizontal,
float  vertical 
)

Definition at line 54 of file rect_f.cc.

54 {
55 origin_ += Vector2dF(horizontal, vertical);
56}

◆ OffsetFromOrigin()

Vector2dF gfx::RectF::OffsetFromOrigin ( ) const
inline

Definition at line 77 of file rect_f.h.

77{ return Vector2dF(x(), y()); }

◆ operator+=()

void gfx::RectF::operator+= ( const Vector2dF offset)

Definition at line 58 of file rect_f.cc.

58 {
59 origin_ += offset;
60}
Point offset

◆ operator-=()

void gfx::RectF::operator-= ( const Vector2dF offset)

Definition at line 62 of file rect_f.cc.

62 {
63 origin_ -= offset;
64}

◆ operator<()

bool gfx::RectF::operator< ( const RectF other) const

Definition at line 71 of file rect_f.cc.

71 {
72 if (origin_ != other.origin_)
73 return origin_ < other.origin_;
74
75 if (width() == other.width())
76 return height() < other.height();
77 return width() < other.width();
78}

◆ origin()

constexpr const PointF & gfx::RectF::origin ( ) const
inlineconstexpr

Definition at line 59 of file rect_f.h.

59{ return origin_; }

◆ right()

constexpr float gfx::RectF::right ( ) const
inlineconstexpr

Definition at line 65 of file rect_f.h.

65{ return x() + width(); }

◆ right_center()

constexpr PointF gfx::RectF::right_center ( ) const
inlineconstexpr

Definition at line 74 of file rect_f.h.

74{ return PointF(right(), y() + height() / 2); }

◆ Scale() [1/2]

void gfx::RectF::Scale ( float  scale)
inline

Definition at line 175 of file rect_f.h.

175{ Scale(scale, scale); }
const Scalar scale

◆ Scale() [2/2]

void gfx::RectF::Scale ( float  x_scale,
float  y_scale 
)
inline

Definition at line 177 of file rect_f.h.

177 {
178 set_origin(ScalePoint(origin(), x_scale, y_scale));
179 set_size(ScaleSize(size(), x_scale, y_scale));
180 }
void set_size(const SizeF &size)
Definition rect_f.h:63
void set_origin(const PointF &origin)
Definition rect_f.h:60
PointF ScalePoint(const PointF &p, float x_scale, float y_scale)
Definition point_f.cc:25
SizeF ScaleSize(const SizeF &s, float x_scale, float y_scale)
Definition size_f.cc:33

◆ set_height()

void gfx::RectF::set_height ( float  height)
inline

Definition at line 57 of file rect_f.h.

57{ size_.set_height(height); }
void set_height(float height)
Definition size_f.h:32

◆ set_origin()

void gfx::RectF::set_origin ( const PointF origin)
inline

Definition at line 60 of file rect_f.h.

60{ origin_ = origin; }

◆ set_size()

void gfx::RectF::set_size ( const SizeF size)
inline

Definition at line 63 of file rect_f.h.

63{ size_ = size; }

◆ set_width()

void gfx::RectF::set_width ( float  width)
inline

Definition at line 54 of file rect_f.h.

54{ size_.set_width(width); }
void set_width(float width)
Definition size_f.h:31

◆ set_x()

void gfx::RectF::set_x ( float  x)
inline

Definition at line 48 of file rect_f.h.

48{ origin_.set_x(x); }
void set_x(float x)
Definition point_f.h:29

◆ set_y()

void gfx::RectF::set_y ( float  y)
inline

Definition at line 51 of file rect_f.h.

51{ origin_.set_y(y); }
void set_y(float y)
Definition point_f.h:30

◆ SetRect()

void gfx::RectF::SetRect ( float  x,
float  y,
float  width,
float  height 
)
inline

Definition at line 79 of file rect_f.h.

79 {
80 origin_.SetPoint(x, y);
81 size_.SetSize(width, height);
82 }
void SetPoint(float x, float y)
Definition point_f.h:32
void SetSize(float width, float height)
Definition size_f.h:36

◆ SharesEdgeWith()

bool gfx::RectF::SharesEdgeWith ( const RectF rect) const

Definition at line 196 of file rect_f.cc.

196 {
197 return (y() == rect.y() && height() == rect.height() &&
198 (x() == rect.right() || right() == rect.x())) ||
199 (x() == rect.x() && width() == rect.width() &&
200 (y() == rect.bottom() || bottom() == rect.y()));
201}

◆ size()

constexpr const SizeF & gfx::RectF::size ( ) const
inlineconstexpr

Definition at line 62 of file rect_f.h.

62{ return size_; }

◆ SplitVertically()

void gfx::RectF::SplitVertically ( RectF left_half,
RectF right_half 
) const

Definition at line 187 of file rect_f.cc.

187 {
188 BASE_DCHECK(left_half);
189 BASE_DCHECK(right_half);
190
191 left_half->SetRect(x(), y(), width() / 2, height());
192 right_half->SetRect(left_half->right(), y(), width() - left_half->width(),
193 height());
194}
#define BASE_DCHECK(condition)
Definition logging.h:63

◆ Subtract()

void gfx::RectF::Subtract ( const RectF rect)

Definition at line 130 of file rect_f.cc.

130 {
131 if (!Intersects(rect))
132 return;
133 if (rect.Contains(*this)) {
134 SetRect(0, 0, 0, 0);
135 return;
136 }
137
138 float rx = x();
139 float ry = y();
140 float rr = right();
141 float rb = bottom();
142
143 if (rect.y() <= y() && rect.bottom() >= bottom()) {
144 // complete intersection in the y-direction
145 if (rect.x() <= x()) {
146 rx = rect.right();
147 } else if (rect.right() >= right()) {
148 rr = rect.x();
149 }
150 } else if (rect.x() <= x() && rect.right() >= right()) {
151 // complete intersection in the x-direction
152 if (rect.y() <= y()) {
153 ry = rect.bottom();
154 } else if (rect.bottom() >= bottom()) {
155 rb = rect.y();
156 }
157 }
158 SetRect(rx, ry, rr - rx, rb - ry);
159}
bool Intersects(const RectF &rect) const
Definition rect_f.cc:90

◆ top_center()

constexpr PointF gfx::RectF::top_center ( ) const
inlineconstexpr

Definition at line 73 of file rect_f.h.

73{ return PointF(x() + width() / 2, y()); }

◆ top_right()

constexpr PointF gfx::RectF::top_right ( ) const
inlineconstexpr

Definition at line 68 of file rect_f.h.

68{ return PointF(right(), y()); }

◆ ToString()

std::string gfx::RectF::ToString ( ) const

Definition at line 231 of file rect_f.cc.

231 {
232 return base::StringPrintf("%s %s", origin().ToString().c_str(),
233 size().ToString().c_str());
234}
std::string ToString() const
Definition rect_f.cc:231
std::string StringPrintf(const std::string &format, Args... args)

◆ Transpose()

void gfx::RectF::Transpose ( )

Definition at line 183 of file rect_f.cc.

183 {
184 SetRect(y(), x(), height(), width());
185}

◆ Union()

void gfx::RectF::Union ( const RectF rect)

Definition at line 114 of file rect_f.cc.

114 {
115 if (IsEmpty()) {
116 *this = rect;
117 return;
118 }
119 if (rect.IsEmpty())
120 return;
121
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());
126
127 SetRect(rx, ry, rr - rx, rb - ry);
128}

◆ width()

constexpr float gfx::RectF::width ( ) const
inlineconstexpr

Definition at line 53 of file rect_f.h.

53{ return size_.width(); }

◆ x()

constexpr float gfx::RectF::x ( ) const
inlineconstexpr

Definition at line 47 of file rect_f.h.

47{ return origin_.x(); }
constexpr float x() const
Definition point_f.h:27

◆ y()

constexpr float gfx::RectF::y ( ) const
inlineconstexpr

Definition at line 50 of file rect_f.h.

50{ return origin_.y(); }
constexpr float y() const
Definition point_f.h:28

The documentation for this class was generated from the following files: