Flutter Impeller
rect.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_IMPELLER_GEOMETRY_RECT_H_
6 #define FLUTTER_IMPELLER_GEOMETRY_RECT_H_
7 
8 #include <array>
9 #include <optional>
10 #include <ostream>
11 #include <vector>
12 
13 #include "fml/logging.h"
17 #include "impeller/geometry/size.h"
18 
19 namespace impeller {
20 
21 template <class T>
22 struct TRect {
23  using Type = T;
24 
25  constexpr TRect() : origin({0, 0}), size({0, 0}) {}
26 
27  constexpr static TRect MakeLTRB(Type left,
28  Type top,
29  Type right,
30  Type bottom) {
31  return TRect(left, top, right - left, bottom - top);
32  }
33 
34  constexpr static TRect MakeXYWH(Type x, Type y, Type width, Type height) {
35  return TRect(x, y, width, height);
36  }
37 
38  constexpr static TRect MakeOriginSize(const TPoint<Type>& origin,
39  const TSize<Type>& size) {
40  return TRect(origin, size);
41  }
42 
43  template <class U>
44  constexpr static TRect MakeSize(const TSize<U>& size) {
45  return TRect(0.0, 0.0, size.width, size.height);
46  }
47 
48  template <typename U>
49  constexpr static std::optional<TRect> MakePointBounds(const U& value) {
50  return MakePointBounds(value.begin(), value.end());
51  }
52 
53  template <typename PointIter>
54  constexpr static std::optional<TRect> MakePointBounds(const PointIter first,
55  const PointIter last) {
56  if (first == last) {
57  return std::nullopt;
58  }
59  auto left = first->x;
60  auto top = first->y;
61  auto right = first->x;
62  auto bottom = first->y;
63  for (auto it = first + 1; it < last; ++it) {
64  left = std::min(left, it->x);
65  top = std::min(top, it->y);
66  right = std::max(right, it->x);
67  bottom = std::max(bottom, it->y);
68  }
69  return TRect::MakeLTRB(left, top, right, bottom);
70  }
71 
72  constexpr static TRect MakeMaximum() {
73  return TRect::MakeLTRB(-std::numeric_limits<Type>::infinity(),
74  -std::numeric_limits<Type>::infinity(),
75  std::numeric_limits<Type>::infinity(),
76  std::numeric_limits<Type>::infinity());
77  }
78 
79  template <class U>
80  constexpr explicit TRect(const TRect<U>& other)
81  : origin(static_cast<T>(other.GetX()), static_cast<T>(other.GetY())),
82  size(static_cast<T>(other.GetWidth()),
83  static_cast<T>(other.GetHeight())) {}
84 
85  [[nodiscard]] constexpr TRect operator+(const TRect& r) const {
86  return TRect({origin.x + r.origin.x, origin.y + r.origin.y},
87  {size.width + r.size.width, size.height + r.size.height});
88  }
89 
90  [[nodiscard]] constexpr TRect operator-(const TRect& r) const {
91  return TRect({origin.x - r.origin.x, origin.y - r.origin.y},
92  {size.width - r.size.width, size.height - r.size.height});
93  }
94 
95  [[nodiscard]] constexpr TRect operator*(Type scale) const {
96  return Scale(scale);
97  }
98 
99  [[nodiscard]] constexpr TRect operator*(const TRect& r) const {
100  return TRect({origin.x * r.origin.x, origin.y * r.origin.y},
101  {size.width * r.size.width, size.height * r.size.height});
102  }
103 
104  [[nodiscard]] constexpr bool operator==(const TRect& r) const {
105  return origin == r.origin && size == r.size;
106  }
107 
108  [[nodiscard]] constexpr TRect Scale(Type scale) const {
109  return TRect({origin.x * scale, origin.y * scale},
110  {size.width * scale, size.height * scale});
111  }
112 
113  [[nodiscard]] constexpr TRect Scale(Type scale_x, Type scale_y) const {
114  return TRect({origin.x * scale_x, origin.y * scale_y},
115  {size.width * scale_x, size.height * scale_y});
116  }
117 
118  [[nodiscard]] constexpr TRect Scale(TPoint<T> scale) const {
119  return TRect({origin.x * scale.x, origin.y * scale.y},
120  {size.width * scale.x, size.height * scale.y});
121  }
122 
123  [[nodiscard]] constexpr TRect Scale(TSize<T> scale) const {
124  return Scale(TPoint<T>(scale));
125  }
126 
127  [[nodiscard]] constexpr bool Contains(const TPoint<Type>& p) const {
128  return p.x >= GetLeft() && p.x < GetRight() && p.y >= GetTop() &&
129  p.y < GetBottom();
130  }
131 
132  [[nodiscard]] constexpr bool Contains(const TRect& o) const {
133  return o.GetLeft() >= GetLeft() && o.GetTop() >= GetTop() &&
134  o.GetRight() <= GetRight() && o.GetBottom() <= GetBottom();
135  }
136 
137  /// Returns true if either of the width or height are 0, negative, or NaN.
138  [[nodiscard]] constexpr bool IsEmpty() const { return size.IsEmpty(); }
139 
140  /// Returns true if width and height are equal and neither is NaN.
141  [[nodiscard]] constexpr bool IsSquare() const { return size.IsSquare(); }
142 
143  [[nodiscard]] constexpr bool IsMaximum() const {
144  return *this == MakeMaximum();
145  }
146 
147  /// @brief Returns the upper left corner of the rectangle as specified
148  /// when it was constructed.
149  ///
150  /// Note that unlike the |GetLeft|, |GetTop|, and |GetLeftTop|
151  /// methods which will return values as if the rectangle had been
152  /// "unswapped" by calling |GetPositive| on it, this method
153  /// returns the raw origin values.
154  [[nodiscard]] constexpr TPoint<Type> GetOrigin() const { return origin; }
155 
156  /// @brief Returns the size of the rectangle as specified when it was
157  /// constructed and which may be negative in either width or
158  /// height.
159  [[nodiscard]] constexpr TSize<Type> GetSize() const { return size; }
160 
161  /// @brief Returns the X coordinate of the upper left corner, equivalent
162  /// to |GetOrigin().x|
163  [[nodiscard]] constexpr Type GetX() const { return origin.x; }
164 
165  /// @brief Returns the Y coordinate of the upper left corner, equivalent
166  /// to |GetOrigin().y|
167  [[nodiscard]] constexpr Type GetY() const { return origin.y; }
168 
169  /// @brief Returns the width of the rectangle, equivalent to
170  /// |GetSize().width|
171  [[nodiscard]] constexpr Type GetWidth() const { return size.width; }
172 
173  /// @brief Returns the height of the rectangle, equivalent to
174  /// |GetSize().height|
175  [[nodiscard]] constexpr Type GetHeight() const { return size.height; }
176 
177  [[nodiscard]] constexpr auto GetLeft() const {
178  if (IsMaximum()) {
179  return -std::numeric_limits<Type>::infinity();
180  }
181  return std::min(origin.x, origin.x + size.width);
182  }
183 
184  [[nodiscard]] constexpr auto GetTop() const {
185  if (IsMaximum()) {
186  return -std::numeric_limits<Type>::infinity();
187  }
188  return std::min(origin.y, origin.y + size.height);
189  }
190 
191  [[nodiscard]] constexpr auto GetRight() const {
192  if (IsMaximum()) {
193  return std::numeric_limits<Type>::infinity();
194  }
195  return std::max(origin.x, origin.x + size.width);
196  }
197 
198  [[nodiscard]] constexpr auto GetBottom() const {
199  if (IsMaximum()) {
200  return std::numeric_limits<Type>::infinity();
201  }
202  return std::max(origin.y, origin.y + size.height);
203  }
204 
205  [[nodiscard]] constexpr TPoint<T> GetLeftTop() const {
206  return {GetLeft(), GetTop()};
207  }
208 
209  [[nodiscard]] constexpr TPoint<T> GetRightTop() const {
210  return {GetRight(), GetTop()};
211  }
212 
213  [[nodiscard]] constexpr TPoint<T> GetLeftBottom() const {
214  return {GetLeft(), GetBottom()};
215  }
216 
217  [[nodiscard]] constexpr TPoint<T> GetRightBottom() const {
218  return {GetRight(), GetBottom()};
219  }
220 
221  /// @brief Get the area of the rectangle, equivalent to |GetSize().Area()|
222  [[nodiscard]] constexpr T Area() const { return size.Area(); }
223 
224  /// @brief Get the center point as a |Point|.
225  [[nodiscard]] constexpr Point GetCenter() const {
226  return Point(origin.x + size.width * 0.5f, origin.y + size.height * 0.5f);
227  }
228 
229  [[nodiscard]] constexpr std::array<T, 4> GetLTRB() const {
230  return {GetLeft(), GetTop(), GetRight(), GetBottom()};
231  }
232 
233  /// @brief Get the x, y coordinates of the origin and the width and
234  /// height of the rectangle in an array.
235  [[nodiscard]] constexpr std::array<T, 4> GetXYWH() const {
236  return {origin.x, origin.y, size.width, size.height};
237  }
238 
239  /// @brief Get a version of this rectangle that has a non-negative size.
240  [[nodiscard]] constexpr TRect GetPositive() const {
241  auto ltrb = GetLTRB();
242  return MakeLTRB(ltrb[0], ltrb[1], ltrb[2], ltrb[3]);
243  }
244 
245  /// @brief Get the points that represent the 4 corners of this rectangle.
246  /// The order is: Top left, top right, bottom left, bottom right.
247  [[nodiscard]] constexpr std::array<TPoint<T>, 4> GetPoints() const {
248  auto [left, top, right, bottom] = GetLTRB();
249  return {TPoint(left, top), TPoint(right, top), TPoint(left, bottom),
250  TPoint(right, bottom)};
251  }
252 
253  [[nodiscard]] constexpr std::array<TPoint<T>, 4> GetTransformedPoints(
254  const Matrix& transform) const {
255  auto points = GetPoints();
256  for (size_t i = 0; i < points.size(); i++) {
257  points[i] = transform * points[i];
258  }
259  return points;
260  }
261 
262  /// @brief Creates a new bounding box that contains this transformed
263  /// rectangle.
264  [[nodiscard]] constexpr TRect TransformBounds(const Matrix& transform) const {
265  auto points = GetTransformedPoints(transform);
266  auto bounds = TRect::MakePointBounds(points.begin(), points.end());
267  if (bounds.has_value()) {
268  return bounds.value();
269  }
270  FML_UNREACHABLE();
271  }
272 
273  /// @brief Constructs a Matrix that will map all points in the coordinate
274  /// space of the rectangle into a new normalized coordinate space
275  /// where the upper left corner of the rectangle maps to (0, 0)
276  /// and the lower right corner of the rectangle maps to (1, 1).
277  ///
278  /// Empty and non-finite rectangles will return a zero-scaling
279  /// transform that maps all points to (0, 0).
280  [[nodiscard]] constexpr Matrix GetNormalizingTransform() const {
281  if (!IsEmpty()) {
282  Scalar sx = 1.0 / size.width;
283  Scalar sy = 1.0 / size.height;
284  Scalar tx = origin.x * -sx;
285  Scalar ty = origin.y * -sy;
286 
287  // Exclude NaN and infinities and either scale underflowing to zero
288  if (sx != 0.0 && sy != 0.0 && 0.0 * sx * sy * tx * ty == 0.0) {
289  // clang-format off
290  return Matrix( sx, 0.0f, 0.0f, 0.0f,
291  0.0f, sy, 0.0f, 0.0f,
292  0.0f, 0.0f, 1.0f, 0.0f,
293  tx, ty, 0.0f, 1.0f);
294  // clang-format on
295  }
296  }
297 
298  // Map all coordinates to the origin.
299  return Matrix::MakeScale({0.0f, 0.0f, 1.0f});
300  }
301 
302  [[nodiscard]] constexpr TRect Union(const TRect& o) const {
303  auto this_ltrb = GetLTRB();
304  auto other_ltrb = o.GetLTRB();
305  return TRect::MakeLTRB(std::min(this_ltrb[0], other_ltrb[0]), //
306  std::min(this_ltrb[1], other_ltrb[1]), //
307  std::max(this_ltrb[2], other_ltrb[2]), //
308  std::max(this_ltrb[3], other_ltrb[3]) //
309  );
310  }
311 
312  [[nodiscard]] constexpr std::optional<TRect<T>> Intersection(
313  const TRect& o) const {
314  auto this_ltrb = GetLTRB();
315  auto other_ltrb = o.GetLTRB();
316  auto intersection =
317  TRect::MakeLTRB(std::max(this_ltrb[0], other_ltrb[0]), //
318  std::max(this_ltrb[1], other_ltrb[1]), //
319  std::min(this_ltrb[2], other_ltrb[2]), //
320  std::min(this_ltrb[3], other_ltrb[3]) //
321  );
322  if (intersection.size.IsEmpty()) {
323  return std::nullopt;
324  }
325  return intersection;
326  }
327 
328  [[nodiscard]] constexpr bool IntersectsWithRect(const TRect& o) const {
329  return Intersection(o).has_value();
330  }
331 
332  /// @brief Returns the new boundary rectangle that would result from the
333  /// rectangle being cutout by a second rectangle.
334  [[nodiscard]] constexpr std::optional<TRect<T>> Cutout(const TRect& o) const {
335  const auto& [a_left, a_top, a_right, a_bottom] = GetLTRB(); // Source rect.
336  const auto& [b_left, b_top, b_right, b_bottom] = o.GetLTRB(); // Cutout.
337  if (b_left <= a_left && b_right >= a_right) {
338  if (b_top <= a_top && b_bottom >= a_bottom) {
339  // Full cutout.
340  return std::nullopt;
341  }
342  if (b_top <= a_top && b_bottom > a_top) {
343  // Cuts off the top.
344  return TRect::MakeLTRB(a_left, b_bottom, a_right, a_bottom);
345  }
346  if (b_bottom >= a_bottom && b_top < a_bottom) {
347  // Cuts out the bottom.
348  return TRect::MakeLTRB(a_left, a_top, a_right, b_top);
349  }
350  }
351  if (b_top <= a_top && b_bottom >= a_bottom) {
352  if (b_left <= a_left && b_right > a_left) {
353  // Cuts out the left.
354  return TRect::MakeLTRB(b_right, a_top, a_right, a_bottom);
355  }
356  if (b_right >= a_right && b_left < a_right) {
357  // Cuts out the right.
358  return TRect::MakeLTRB(a_left, a_top, b_left, a_bottom);
359  }
360  }
361 
362  return *this;
363  }
364 
365  /// @brief Returns a new rectangle translated by the given offset.
366  [[nodiscard]] constexpr TRect<T> Shift(TPoint<T> offset) const {
367  return TRect(origin.x + offset.x, origin.y + offset.y, size.width,
368  size.height);
369  }
370 
371  /// @brief Returns a rectangle with expanded edges. Negative expansion
372  /// results in shrinking.
373  [[nodiscard]] constexpr TRect<T> Expand(T left,
374  T top,
375  T right,
376  T bottom) const {
377  return TRect(origin.x - left, //
378  origin.y - top, //
379  size.width + left + right, //
380  size.height + top + bottom);
381  }
382 
383  /// @brief Returns a rectangle with expanded edges in all directions.
384  /// Negative expansion results in shrinking.
385  [[nodiscard]] constexpr TRect<T> Expand(T amount) const {
386  return TRect(origin.x - amount, //
387  origin.y - amount, //
388  size.width + amount * 2, //
389  size.height + amount * 2);
390  }
391 
392  /// @brief Returns a rectangle with expanded edges in all directions.
393  /// Negative expansion results in shrinking.
394  [[nodiscard]] constexpr TRect<T> Expand(T horizontal_amount,
395  T vertical_amount) const {
396  return TRect(origin.x - horizontal_amount, //
397  origin.y - vertical_amount, //
398  size.width + horizontal_amount * 2, //
399  size.height + vertical_amount * 2);
400  }
401 
402  /// @brief Returns a rectangle with expanded edges in all directions.
403  /// Negative expansion results in shrinking.
404  [[nodiscard]] constexpr TRect<T> Expand(TPoint<T> amount) const {
405  return TRect(origin.x - amount.x, //
406  origin.y - amount.y, //
407  size.width + amount.x * 2, //
408  size.height + amount.y * 2);
409  }
410 
411  /// @brief Returns a rectangle with expanded edges in all directions.
412  /// Negative expansion results in shrinking.
413  [[nodiscard]] constexpr TRect<T> Expand(TSize<T> amount) const {
414  return TRect(origin.x - amount.width, //
415  origin.y - amount.height, //
416  size.width + amount.width * 2, //
417  size.height + amount.height * 2);
418  }
419 
420  /// @brief Returns a new rectangle that represents the projection of the
421  /// source rectangle onto this rectangle. In other words, the source
422  /// rectangle is redefined in terms of the corrdinate space of this
423  /// rectangle.
424  [[nodiscard]] constexpr TRect<T> Project(TRect<T> source) const {
425  return source.Shift(-origin).Scale(
426  TSize<T>(1.0 / static_cast<Scalar>(size.width),
427  1.0 / static_cast<Scalar>(size.height)));
428  }
429 
430  [[nodiscard]] constexpr static TRect RoundOut(const TRect& r) {
431  return TRect::MakeLTRB(floor(r.GetLeft()), floor(r.GetTop()),
432  ceil(r.GetRight()), ceil(r.GetBottom()));
433  }
434 
435  [[nodiscard]] constexpr static std::optional<TRect> Union(
436  const TRect& a,
437  const std::optional<TRect> b) {
438  return b.has_value() ? a.Union(b.value()) : a;
439  }
440 
441  [[nodiscard]] constexpr static std::optional<TRect> Union(
442  const std::optional<TRect> a,
443  const TRect& b) {
444  return Union(b, a);
445  }
446 
447  [[nodiscard]] constexpr static std::optional<TRect> Union(
448  const std::optional<TRect> a,
449  const std::optional<TRect> b) {
450  return a.has_value() ? Union(a.value(), b) : b;
451  }
452 
453  [[nodiscard]] constexpr static std::optional<TRect> Intersection(
454  const TRect& a,
455  const std::optional<TRect> b) {
456  return b.has_value() ? a.Intersection(b.value()) : a;
457  }
458 
459  [[nodiscard]] constexpr static std::optional<TRect> Intersection(
460  const std::optional<TRect> a,
461  const TRect& b) {
462  return Intersection(b, a);
463  }
464 
465  [[nodiscard]] constexpr static std::optional<TRect> Intersection(
466  const std::optional<TRect> a,
467  const std::optional<TRect> b) {
468  return a.has_value() ? Intersection(a.value(), b) : b;
469  }
470 
471  private:
472  constexpr TRect(Type x, Type y, Type width, Type height)
473  : origin(x, y), size(width, height) {}
474 
475  constexpr TRect(TPoint<Type> origin, TSize<Type> size)
476  : origin(origin), size(size) {}
477 
478  // NOLINTBEGIN
479  // These fields should be named origin_ and size_, but will be renamed to
480  // left_/top_/right_/bottom_ during the next phase of the reworking of the
481  // TRect class and we will deal with the renaming of all the usages here
482  // and in path_builder.cc at that time
483  TPoint<Type> origin;
484  TSize<Type> size;
485  // NOLINTEND
486 };
487 
490 
491 } // namespace impeller
492 
493 namespace std {
494 
495 template <class T>
496 inline std::ostream& operator<<(std::ostream& out,
497  const impeller::TRect<T>& r) {
498  out << "(" << r.GetOrigin() << ", " << r.GetSize() << ")";
499  return out;
500 }
501 
502 } // namespace std
503 
504 #endif // FLUTTER_IMPELLER_GEOMETRY_RECT_H_
impeller::TRect::Union
constexpr static std::optional< TRect > Union(const std::optional< TRect > a, const TRect &b)
Definition: rect.h:441
impeller::TRect::GetLTRB
constexpr std::array< T, 4 > GetLTRB() const
Definition: rect.h:229
point.h
impeller::TPoint::y
Type y
Definition: point.h:26
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::TRect::Expand
constexpr TRect< T > Expand(T horizontal_amount, T vertical_amount) const
Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.
Definition: rect.h:394
impeller::TSize::IsSquare
constexpr bool IsSquare() const
Definition: size.h:107
impeller::TRect< Scalar >::Type
Scalar Type
Definition: rect.h:23
impeller::TRect::MakeXYWH
constexpr static TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition: rect.h:34
impeller::TRect::Expand
constexpr TRect< T > Expand(T amount) const
Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.
Definition: rect.h:385
impeller::TRect::operator-
constexpr TRect operator-(const TRect &r) const
Definition: rect.h:90
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:264
impeller::TRect::IsMaximum
constexpr bool IsMaximum() const
Definition: rect.h:143
impeller::TRect::GetLeftTop
constexpr TPoint< T > GetLeftTop() const
Definition: rect.h:205
impeller::TRect::Scale
constexpr TRect Scale(Type scale_x, Type scale_y) const
Definition: rect.h:113
impeller::TRect::GetNormalizingTransform
constexpr Matrix GetNormalizingTransform() const
Constructs a Matrix that will map all points in the coordinate space of the rectangle into a new norm...
Definition: rect.h:280
impeller::TRect::RoundOut
constexpr static TRect RoundOut(const TRect &r)
Definition: rect.h:430
impeller::TRect::operator+
constexpr TRect operator+(const TRect &r) const
Definition: rect.h:85
impeller::TRect::Intersection
constexpr static std::optional< TRect > Intersection(const TRect &a, const std::optional< TRect > b)
Definition: rect.h:453
std::operator<<
std::ostream & operator<<(std::ostream &out, const impeller::Color &c)
Definition: color.h:951
impeller::TRect::TRect
constexpr TRect()
Definition: rect.h:25
impeller::TRect::GetCenter
constexpr Point GetCenter() const
Get the center point as a |Point|.
Definition: rect.h:225
impeller::TRect::GetX
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
Definition: rect.h:163
impeller::TRect::GetHeight
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition: rect.h:175
impeller::TRect::GetOrigin
constexpr TPoint< Type > GetOrigin() const
Returns the upper left corner of the rectangle as specified when it was constructed.
Definition: rect.h:154
impeller::TRect::GetRightTop
constexpr TPoint< T > GetRightTop() const
Definition: rect.h:209
impeller::TRect::Contains
constexpr bool Contains(const TRect &o) const
Definition: rect.h:132
impeller::TRect::operator==
constexpr bool operator==(const TRect &r) const
Definition: rect.h:104
impeller::TRect::IntersectsWithRect
constexpr bool IntersectsWithRect(const TRect &o) const
Definition: rect.h:328
impeller::TRect::GetPoints
constexpr std::array< TPoint< T >, 4 > GetPoints() const
Get the points that represent the 4 corners of this rectangle. The order is: Top left,...
Definition: rect.h:247
impeller::TRect::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:49
impeller::TRect::IsEmpty
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: rect.h:138
matrix.h
impeller::TRect::Scale
constexpr TRect Scale(TSize< T > scale) const
Definition: rect.h:123
impeller::TSize< Type >
impeller::Point
TPoint< Scalar > Point
Definition: point.h:308
impeller::TRect::Intersection
constexpr std::optional< TRect< T > > Intersection(const TRect &o) const
Definition: rect.h:312
impeller::TRect::GetLeft
constexpr auto GetLeft() const
Definition: rect.h:177
impeller::TRect::GetTransformedPoints
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
Definition: rect.h:253
impeller::TRect::operator*
constexpr TRect operator*(Type scale) const
Definition: rect.h:95
impeller::TRect::GetWidth
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition: rect.h:171
impeller::TRect::GetLeftBottom
constexpr TPoint< T > GetLeftBottom() const
Definition: rect.h:213
impeller::TRect::IsSquare
constexpr bool IsSquare() const
Returns true if width and height are equal and neither is NaN.
Definition: rect.h:141
impeller::TRect::MakeOriginSize
constexpr static TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
Definition: rect.h:38
impeller::TRect::Scale
constexpr TRect Scale(Type scale) const
Definition: rect.h:108
impeller::TRect::MakePointBounds
constexpr static std::optional< TRect > MakePointBounds(const PointIter first, const PointIter last)
Definition: rect.h:54
impeller::TRect::Shift
constexpr TRect< T > Shift(TPoint< T > offset) const
Returns a new rectangle translated by the given offset.
Definition: rect.h:366
impeller::TRect::Scale
constexpr TRect Scale(TPoint< T > scale) const
Definition: rect.h:118
impeller::TSize::width
Type width
Definition: size.h:22
impeller::TRect::Contains
constexpr bool Contains(const TPoint< Type > &p) const
Definition: rect.h:127
impeller::TPoint::x
Type x
Definition: point.h:25
scalar.h
impeller::TRect::Expand
constexpr TRect< T > Expand(TPoint< T > amount) const
Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.
Definition: rect.h:404
impeller::TRect::Expand
constexpr TRect< T > Expand(TSize< T > amount) const
Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.
Definition: rect.h:413
impeller::TRect::Cutout
constexpr std::optional< TRect< T > > Cutout(const TRect &o) const
Returns the new boundary rectangle that would result from the rectangle being cutout by a second rect...
Definition: rect.h:334
impeller::TRect::GetSize
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle as specified when it was constructed and which may be negative in e...
Definition: rect.h:159
impeller::TRect::GetRight
constexpr auto GetRight() const
Definition: rect.h:191
impeller::TSize::Area
constexpr Type Area() const
Definition: size.h:102
impeller::TRect::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:44
std
Definition: comparable.h:95
impeller::TRect::operator*
constexpr TRect operator*(const TRect &r) const
Definition: rect.h:99
impeller::TRect::Project
constexpr TRect< T > Project(TRect< T > source) const
Returns a new rectangle that represents the projection of the source rectangle onto this rectangle....
Definition: rect.h:424
impeller::TPoint< Type >
impeller::TRect::MakeMaximum
constexpr static TRect MakeMaximum()
Definition: rect.h:72
impeller::TRect::Union
constexpr TRect Union(const TRect &o) const
Definition: rect.h:302
impeller::TRect::Area
constexpr T Area() const
Get the area of the rectangle, equivalent to |GetSize().Area()|.
Definition: rect.h:222
impeller::TRect::GetBottom
constexpr auto GetBottom() const
Definition: rect.h:198
impeller::TSize::height
Type height
Definition: size.h:23
impeller::TRect::Union
constexpr static std::optional< TRect > Union(const std::optional< TRect > a, const std::optional< TRect > b)
Definition: rect.h:447
impeller::TRect::MakeLTRB
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:27
impeller::TSize::IsEmpty
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: size.h:105
impeller::TRect::GetPositive
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
Definition: rect.h:240
impeller::TRect::GetRightBottom
constexpr TPoint< T > GetRightBottom() const
Definition: rect.h:217
impeller::TRect::Intersection
constexpr static std::optional< TRect > Intersection(const std::optional< TRect > a, const TRect &b)
Definition: rect.h:459
impeller::TRect::GetY
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
Definition: rect.h:167
impeller
Definition: aiks_context.cc:10
impeller::TRect::GetXYWH
constexpr std::array< T, 4 > GetXYWH() const
Get the x, y coordinates of the origin and the width and height of the rectangle in an array.
Definition: rect.h:235
impeller::Matrix::MakeScale
static constexpr Matrix MakeScale(const Vector3 &s)
Definition: matrix.h:104
impeller::TRect::TRect
constexpr TRect(const TRect< U > &other)
Definition: rect.h:80
impeller::TRect::GetTop
constexpr auto GetTop() const
Definition: rect.h:184
impeller::TRect
Definition: rect.h:22
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
size.h
impeller::TRect::Expand
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
Definition: rect.h:373
impeller::TRect::Union
constexpr static std::optional< TRect > Union(const TRect &a, const std::optional< TRect > b)
Definition: rect.h:435
impeller::TRect::Intersection
constexpr static std::optional< TRect > Intersection(const std::optional< TRect > a, const std::optional< TRect > b)
Definition: rect.h:465