5#ifndef FLUTTER_IMPELLER_GEOMETRY_RECT_H_
6#define FLUTTER_IMPELLER_GEOMETRY_RECT_H_
22#define ONLY_ON_FLOAT_M(Modifiers, Return) \
23 template <typename U = T> \
24 Modifiers std::enable_if_t<std::is_floating_point_v<U>, Return>
25#define ONLY_ON_FLOAT(Return) DL_ONLY_ON_FLOAT_M(, Return)
127 constexpr TRect() : left_(0), top_(0), right_(0), bottom_(0) {}
133 return TRect(left, top, right, bottom);
150 template <
typename U>
155 template <
typename Po
intIter>
157 const PointIter last) {
161 auto left = first->x;
163 auto right = first->x;
164 auto bottom = first->y;
165 for (
auto it = first + 1; it < last; ++it) {
176 std::numeric_limits<Type>::lowest(),
182 return left_ == r.left_ &&
184 right_ == r.right_ &&
185 bottom_ == r.bottom_;
189 return !(*
this == r);
200 return TRect(left_ * scale_x,
265 (o.
IsEmpty() || (o.left_ >= left_ &&
267 o.right_ <= right_ &&
268 o.bottom_ <= bottom_));
287 [[nodiscard]]
constexpr bool IsEmpty()
const {
290 return !(left_ < right_ && top_ < bottom_);
301 return !
IsEmpty() && (right_ - left_) == (bottom_ - top_);
311 return {left_, top_};
323 [[nodiscard]]
constexpr Type GetX()
const {
return left_; }
327 [[nodiscard]]
constexpr Type GetY()
const {
return top_; }
332 return saturated::Sub(right_, left_);
338 return saturated::Sub(bottom_, top_);
341 [[nodiscard]]
constexpr auto GetLeft()
const {
return left_; }
343 [[nodiscard]]
constexpr auto GetTop()
const {
return top_; }
345 [[nodiscard]]
constexpr auto GetRight()
const {
return right_; }
347 [[nodiscard]]
constexpr auto GetBottom()
const {
return bottom_; }
350 return {left_, top_};
354 return {right_, top_};
358 return {left_, bottom_};
362 return {right_, bottom_};
366 [[nodiscard]]
constexpr T Area()
const {
369 return IsEmpty() ? 0 : (right_ - left_) * (bottom_ - top_);
374 return {saturated::AverageScalar(left_, right_),
375 saturated::AverageScalar(top_, bottom_)};
378 [[nodiscard]]
constexpr std::array<T, 4>
GetLTRB()
const {
379 return {left_, top_, right_, bottom_};
384 [[nodiscard]]
constexpr std::array<T, 4>
GetXYWH()
const {
405 [[nodiscard]]
constexpr std::array<TPoint<T>, 4>
GetPoints()
const {
420 for (
size_t i = 0;
i <
points.size();
i++) {
439 auto ul =
transform.TransformHomogenous({left_, top_});
440 auto ur =
transform.TransformHomogenous({right_, top_});
441 auto ll =
transform.TransformHomogenous({left_, bottom_});
442 auto lr =
transform.TransformHomogenous({right_, bottom_});
452 index = ClipAndInsert(
points, index, ll, ul, ur);
453 index = ClipAndInsert(
points, index, ul, ur, lr);
454 index = ClipAndInsert(
points, index, ur, lr, ll);
455 index = ClipAndInsert(
points, index, lr, ll, ul);
490 if (sx != 0.0 && sy != 0.0 && 0.0 * sx * sy * tx * ty == 0.0) {
492 return Matrix( sx, 0.0f, 0.0f, 0.0f,
493 0.0f, sy, 0.0f, 0.0f,
494 0.0f, 0.0f, 1.0f, 0.0f,
520 const TRect& o)
const {
544 [[nodiscard]]
constexpr std::optional<TRect<T>>
Cutout(
const TRect& o)
const {
554 const auto& [a_left, a_top, a_right, a_bottom] =
GetLTRB();
555 const auto& [b_left, b_top, b_right, b_bottom] = o.
GetLTRB();
556 if (b_left <= a_left && b_right >= a_right) {
557 if (b_top <= a_top && b_bottom >= a_bottom) {
561 if (b_top <= a_top && b_bottom > a_top) {
565 if (b_bottom >= a_bottom && b_top < a_bottom) {
570 if (b_top <= a_top && b_bottom >= a_bottom) {
571 if (b_left <= a_left && b_right > a_left) {
575 if (b_right >= a_right && b_left < a_right) {
591 saturated::Add(left_,
dx),
592 saturated::Add(top_, dy),
593 saturated::Add(right_,
dx),
594 saturated::Add(bottom_, dy),
610 saturated::Sub(left_, left),
611 saturated::Sub(top_, top),
612 saturated::Add(right_, right),
613 saturated::Add(bottom_, bottom),
621 saturated::Sub(left_, amount),
622 saturated::Sub(top_, amount),
623 saturated::Add(right_, amount),
624 saturated::Add(bottom_, amount),
631 T vertical_amount)
const {
633 saturated::Sub(left_, horizontal_amount),
634 saturated::Sub(top_, vertical_amount),
635 saturated::Add(right_, horizontal_amount),
636 saturated::Add(bottom_, vertical_amount),
660 return source.Shift(-left_, -top_)
668 saturated::Cast<U, Type>(
floor(r.GetTop())),
669 saturated::Cast<U, Type>(
ceil(r.GetRight())),
670 saturated::Cast<U, Type>(
ceil(r.GetBottom())));
676 saturated::Cast<U, Type>(
round(r.GetTop())),
677 saturated::Cast<U, Type>(
round(r.GetRight())),
678 saturated::Cast<U, Type>(
round(r.GetBottom())));
681 [[nodiscard]]
constexpr static std::optional<TRect>
Union(
683 const std::optional<TRect>
b) {
684 return b.has_value() ?
a.Union(
b.value()) :
a;
687 [[nodiscard]]
constexpr static std::optional<TRect>
Union(
688 const std::optional<TRect>
a,
690 return a.has_value() ?
a->Union(
b) :
b;
693 [[nodiscard]]
constexpr static std::optional<TRect>
Union(
694 const std::optional<TRect>
a,
695 const std::optional<TRect>
b) {
696 return a.has_value() ?
Union(
a.value(),
b) :
b;
701 const std::optional<TRect>
b) {
702 return b.has_value() ?
a.Intersection(
b.value()) :
a;
706 const std::optional<TRect>
a,
708 return a.has_value() ?
a->Intersection(
b) :
b;
712 const std::optional<TRect>
a,
713 const std::optional<TRect>
b) {
719 : left_(left), top_(top), right_(right), bottom_(bottom) {}
726 static constexpr Scalar kMinimumHomogenous = 1.0f / (1 << 14);
737 static constexpr int ClipAndInsert(
Point clipped[],
741 const Vector3& right) {
742 if (
p.z >= kMinimumHomogenous) {
743 clipped[index++] = {
p.x /
p.z,
p.y /
p.z};
745 index = InterpolateAndInsert(clipped, index,
p, left);
746 index = InterpolateAndInsert(clipped, index,
p, right);
754 static constexpr int InterpolateAndInsert(
Point clipped[],
757 const Vector3& neighbor) {
758 if (neighbor.z >= kMinimumHomogenous) {
759 auto t = (kMinimumHomogenous -
p.z) / (neighbor.z -
p.z);
761 (t *
p.x + (1.0f - t) * neighbor.x) / kMinimumHomogenous,
762 (t *
p.y + (1.0f - t) * neighbor.y) / kMinimumHomogenous,
775#undef ONLY_ON_FLOAT_M
static void round(SkPoint *p)
static const int points[]
#define FML_UNREACHABLE()
static float max(float r, float g, float b)
static float min(float r, float g, float b)
#define ONLY_ON_FLOAT_M(Modifiers, Return)
Optional< SkRect > bounds
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
SK_API sk_sp< PrecompileColorFilter > Matrix()
SINT bool isfinite(const Vec< N, T > &v)
SIN Vec< N, float > floor(const Vec< N, float > &x)
SIN Vec< N, float > ceil(const Vec< N, float > &x)
std::ostream & operator<<(std::ostream &out, const impeller::Color &c)
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeScale(const Vector3 &s)
constexpr auto GetBottom() const
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
constexpr bool ContainsInclusive(const TPoint< Type > &p) const
Returns true iff the provided point |p| is inside the closed-range interior of this rectangle.
constexpr auto GetTop() const
constexpr std::array< TPoint< T >, 4 > GetPoints() const
Get the points that represent the 4 corners of this rectangle in a Z order that is compatible with tr...
constexpr std::optional< TRect > Intersection(const TRect &o) const
constexpr TRect< T > Project(TRect< T > source) const
Returns a new rectangle that represents the projection of the source rectangle onto this rectangle....
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
static constexpr std::optional< TRect > Union(const std::optional< TRect > a, const std::optional< TRect > b)
constexpr std::optional< TRect< T > > Cutout(const TRect &o) const
Returns the new boundary rectangle that would result from this rectangle being cut out by the specifi...
constexpr TRect Scale(TPoint< T > scale) const
constexpr bool IsMaximum() const
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
constexpr T Area() const
Get the area of the rectangle, equivalent to |GetSize().Area()|.
constexpr bool Contains(const TPoint< Type > &p) const
Returns true iff the provided point |p| is inside the half-open interior of this rectangle.
static constexpr std::optional< TRect > MakePointBounds(const PointIter first, const PointIter last)
constexpr TRect Union(const TRect &o) const
constexpr TRect Scale(Type scale_x, Type scale_y) const
constexpr bool IntersectsWithRect(const TRect &o) const
constexpr auto GetLeft() const
constexpr TRect CutoutOrEmpty(const TRect &o) const
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.
constexpr TPoint< T > GetLeftTop() const
static constexpr std::optional< TRect > Union(const TRect &a, const std::optional< TRect > b)
Round(const TRect< U > &r)
RoundOut(const TRect< U > &r)
constexpr TRect GetPositive() const
Get a version of this rectangle that has a non-negative size.
static constexpr std::optional< TRect > Intersection(const TRect &a, const std::optional< TRect > b)
constexpr TRect Scale(TSize< T > scale) const
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
constexpr std::array< T, 4 > GetLTRB() const
static constexpr TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
constexpr auto GetRight() const
constexpr bool IsSquare() const
Returns true if width and height are equal and neither is NaN.
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
constexpr bool Contains(const TRect &o) const
Returns true iff this rectangle is not empty and it also contains every point considered inside the p...
IsFinite() const
Returns true if all of the fields of this floating point rectangle are finite.
constexpr Matrix GetNormalizingTransform() const
Constructs a Matrix that will map all points in the coordinate space of the rectangle into a new norm...
constexpr bool operator!=(const TRect &r) const
constexpr TRect Scale(Type scale) const
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
constexpr TRect TransformAndClipBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle, clipped against the near clippin...
constexpr TPoint< T > GetRightBottom() const
static constexpr std::optional< TRect > Intersection(const std::optional< TRect > a, const std::optional< TRect > b)
constexpr TPoint< T > GetLeftBottom() const
static constexpr TRect MakeSize(const TSize< U > &size)
static constexpr std::optional< TRect > Union(const std::optional< TRect > a, const TRect &b)
constexpr TRect< T > Shift(TPoint< T > offset) const
Returns a new rectangle translated by the given offset.
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
static constexpr std::optional< TRect > Intersection(const std::optional< TRect > a, const TRect &b)
constexpr TPoint< T > GetRightTop() const
static constexpr std::optional< TRect > MakePointBounds(const U &value)
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
static constexpr TRect MakeMaximum()
constexpr Point GetCenter() const
Get the center point as a |Point|.
constexpr TRect< T > Expand(TSize< T > amount) const
Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.
constexpr bool operator==(const TRect &r) const
constexpr TRect< T > Expand(T amount) const
Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.
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.
constexpr TRect< T > Shift(T dx, T dy) const
Returns a new rectangle translated by the given offset.
constexpr TRect< T > Expand(TPoint< T > amount) const
Returns a rectangle with expanded edges in all directions. Negative expansion results in shrinking.
constexpr TPoint< Type > GetOrigin() const
Returns the upper left corner of the rectangle as specified by the left/top or x/y values when it was...
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)