Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | List of all members
skgpu::graphite::Rect Class Reference

#include <Rect.h>

Classes

struct  ComplementRect
 

Public Member Functions

AI Rect ()=default
 
AI Rect (float l, float t, float r, float b)
 
AI Rect (float2 topLeft, float2 botRight)
 
AI Rect (const SkRect &r)
 
AI bool operator== (Rect rect) const
 
AI bool operator!= (Rect rect) const
 
AI const float4vals () const
 
AI float4vals ()
 
AI float x () const
 
AI float y () const
 
AI float left () const
 
AI float top () const
 
AI float right () const
 
AI float bot () const
 
AI float2 topLeft () const
 
AI float2 botRight () const
 
AI float4 ltrb () const
 
AI void setLeft (float left)
 
AI void setTop (float top)
 
AI void setRight (float right)
 
AI void setBot (float bot)
 
AI void setTopLeft (float2 topLeft)
 
AI void setBotRight (float2 botRight)
 
AI SkRect asSkRect () const
 
AI SkIRect asSkIRect () const
 
AI bool isEmptyNegativeOrNaN () const
 
AI float2 size () const
 
AI float2 center () const
 
AI float area () const
 
AI bool intersects (ComplementRect comp) const
 
AI bool contains (Rect rect) const
 
AI Rect makeRoundIn () const
 
AI Rect makeRoundOut () const
 
AI Rect makeInset (float inset) const
 
AI Rect makeInset (float2 inset) const
 
AI Rect makeOutset (float outset) const
 
AI Rect makeOutset (float2 outset) const
 
AI Rect makeOffset (float2 offset) const
 
AI Rect makeJoin (Rect rect) const
 
AI Rect makeIntersect (Rect rect) const
 
AI Rect makeSorted () const
 
AI RectroundIn ()
 
AI RectroundOut ()
 
AI Rectinset (float inset)
 
AI Rectinset (float2 inset)
 
AI Rectoutset (float outset)
 
AI Rectoutset (float2 outset)
 
AI Rectoffset (float2 offset)
 
AI Rectjoin (Rect rect)
 
AI Rectintersect (Rect rect)
 
AI Rectsort ()
 

Static Public Member Functions

static AI Rect LTRB (float4 ltrb)
 
static AI Rect XYWH (float x, float y, float w, float h)
 
static AI Rect XYWH (float2 topLeft, float2 size)
 
static AI Rect WH (float w, float h)
 
static AI Rect WH (float2 size)
 
static AI Rect Point (float2 p)
 
static AI Rect FromVals (float4 vals)
 
static AI Rect Infinite ()
 
static AI Rect InfiniteInverted ()
 

Detailed Description

SIMD rect implementation. Values are stored internally in the form: [left, top, -right, -bot].

Some operations (e.g., intersect, inset) may return a negative or empty rect (negative meaning, left >= right or top >= bot).

Operations on a rect that is either negative or empty, while well-defined, might not give the intended result. It is the caller's responsibility to check isEmptyOrNegative() if needed.

Definition at line 27 of file Rect.h.

Constructor & Destructor Documentation

◆ Rect() [1/4]

AI skgpu::graphite::Rect::Rect ( )
default

◆ Rect() [2/4]

AI skgpu::graphite::Rect::Rect ( float  l,
float  t,
float  r,
float  b 
)
inline

Definition at line 32 of file Rect.h.

32: fVals(NegateBotRight({l,t,r,b})) {}
static bool b

◆ Rect() [3/4]

AI skgpu::graphite::Rect::Rect ( float2  topLeft,
float2  botRight 
)
inline

Definition at line 33 of file Rect.h.

33: fVals(topLeft, -botRight) {}
AI float2 topLeft() const
Definition: Rect.h:80
AI float2 botRight() const
Definition: Rect.h:81

◆ Rect() [4/4]

AI skgpu::graphite::Rect::Rect ( const SkRect r)
inline

Definition at line 34 of file Rect.h.

34: fVals(NegateBotRight(float4::Load(r.asScalars()))) {}
const float * asScalars() const
Definition: SkRect.h:1340
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition: SkVx.h:109

Member Function Documentation

◆ area()

AI float skgpu::graphite::Rect::area ( ) const
inline

Definition at line 114 of file Rect.h.

114 {
115 float2 negativeSize = fVals.xy() + fVals.zw(); // == [l-r, t-b] == [-w, -h]
116 return negativeSize.x() * negativeSize.y();
117 }
Definition: SkVx.h:83

◆ asSkIRect()

AI SkIRect skgpu::graphite::Rect::asSkIRect ( ) const
inline

Definition at line 96 of file Rect.h.

96 {
98 skvx::cast<int>(this->ltrb()).store(&rect);
99 return rect;
100 }
AI float4 ltrb() const
Definition: Rect.h:82
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
Definition: SkRect.h:32

◆ asSkRect()

AI SkRect skgpu::graphite::Rect::asSkRect ( ) const
inline

Definition at line 91 of file Rect.h.

91 {
93 this->ltrb().store(&rect);
94 return rect;
95 }
SKVX_ALWAYS_INLINE void store(void *ptr) const
Definition: SkVx.h:112

◆ bot()

AI float skgpu::graphite::Rect::bot ( ) const
inline

Definition at line 79 of file Rect.h.

79{ return -fVals.w(); }

◆ botRight()

AI float2 skgpu::graphite::Rect::botRight ( ) const
inline

Definition at line 81 of file Rect.h.

81{ return -fVals.zw(); }

◆ center()

AI float2 skgpu::graphite::Rect::center ( ) const
inline

Definition at line 109 of file Rect.h.

109 {
110 float4 p = fVals * float4(.5f, .5f, -.5f, -.5f); // == [l, t, r, b] * .5
111 return p.xy() + p.zw(); // == [(l + r)/2, (t + b)/2]
112 }

◆ contains()

AI bool skgpu::graphite::Rect::contains ( Rect  rect) const
inline

Definition at line 127 of file Rect.h.

127{ return all(fVals <= rect.fVals); }
SIT bool all(const Vec< 1, T > &x)
Definition: SkVx.h:582

◆ FromVals()

static AI Rect skgpu::graphite::Rect::FromVals ( float4  vals)
inlinestatic

Definition at line 55 of file Rect.h.

55 { // vals.zw must already be negated.
56 return Rect(vals);
57 }
AI const float4 & vals() const
Definition: Rect.h:71

◆ Infinite()

static AI Rect skgpu::graphite::Rect::Infinite ( )
inlinestatic

Definition at line 60 of file Rect.h.

60 {
62 }
constexpr float SK_FloatNegativeInfinity
static AI Rect FromVals(float4 vals)
Definition: Rect.h:55

◆ InfiniteInverted()

static AI Rect skgpu::graphite::Rect::InfiniteInverted ( )
inlinestatic

Definition at line 64 of file Rect.h.

64 {
66 }
constexpr float SK_FloatInfinity

◆ inset() [1/2]

AI Rect & skgpu::graphite::Rect::inset ( float  inset)
inline

Definition at line 145 of file Rect.h.

145{ return *this = this->makeInset(inset); }
AI Rect & inset(float inset)
Definition: Rect.h:145
AI Rect makeInset(float inset) const
Definition: Rect.h:134

◆ inset() [2/2]

AI Rect & skgpu::graphite::Rect::inset ( float2  inset)
inline

Definition at line 146 of file Rect.h.

146{ return *this = this->makeInset(inset); }

◆ intersect()

AI Rect & skgpu::graphite::Rect::intersect ( Rect  rect)
inline

Definition at line 151 of file Rect.h.

151{ return *this = this->makeIntersect(rect); }
AI Rect makeIntersect(Rect rect) const
Definition: Rect.h:140

◆ intersects()

AI bool skgpu::graphite::Rect::intersects ( ComplementRect  comp) const
inline

Definition at line 126 of file Rect.h.

126{ return all(fVals < comp.fVals); }

◆ isEmptyNegativeOrNaN()

AI bool skgpu::graphite::Rect::isEmptyNegativeOrNaN ( ) const
inline

Definition at line 102 of file Rect.h.

102 {
103 return !all(fVals.xy() + fVals.zw() < 0); // !([l-r, r-b] < 0) == ([w, h] <= 0)
104 // Use "!(-size < 0)" in order to detect NaN.
105 }

◆ join()

AI Rect & skgpu::graphite::Rect::join ( Rect  rect)
inline

Definition at line 150 of file Rect.h.

150{ return *this = this->makeJoin(rect); }
AI Rect makeJoin(Rect rect) const
Definition: Rect.h:139

◆ left()

AI float skgpu::graphite::Rect::left ( ) const
inline

Definition at line 76 of file Rect.h.

76{ return fVals.x(); }

◆ ltrb()

AI float4 skgpu::graphite::Rect::ltrb ( ) const
inline

Definition at line 82 of file Rect.h.

82{ return NegateBotRight(fVals); }

◆ LTRB()

static AI Rect skgpu::graphite::Rect::LTRB ( float4  ltrb)
inlinestatic

Definition at line 36 of file Rect.h.

36 {
37 return Rect(NegateBotRight(ltrb));
38 }

◆ makeInset() [1/2]

AI Rect skgpu::graphite::Rect::makeInset ( float  inset) const
inline

Definition at line 134 of file Rect.h.

134{ return fVals + inset; }

◆ makeInset() [2/2]

AI Rect skgpu::graphite::Rect::makeInset ( float2  inset) const
inline

Definition at line 135 of file Rect.h.

135{ return fVals + inset.xyxy(); }

◆ makeIntersect()

AI Rect skgpu::graphite::Rect::makeIntersect ( Rect  rect) const
inline

Definition at line 140 of file Rect.h.

140{ return max(fVals, rect.fVals); }
static float max(float r, float g, float b)
Definition: hsl.cpp:49

◆ makeJoin()

AI Rect skgpu::graphite::Rect::makeJoin ( Rect  rect) const
inline

Definition at line 139 of file Rect.h.

139{ return min(fVals, rect.fVals); }
static float min(float r, float g, float b)
Definition: hsl.cpp:48

◆ makeOffset()

AI Rect skgpu::graphite::Rect::makeOffset ( float2  offset) const
inline

Definition at line 138 of file Rect.h.

138{ return fVals + float4(offset, -offset); }
AI Rect & offset(float2 offset)
Definition: Rect.h:149

◆ makeOutset() [1/2]

AI Rect skgpu::graphite::Rect::makeOutset ( float  outset) const
inline

Definition at line 136 of file Rect.h.

136{ return fVals - outset; }
AI Rect & outset(float outset)
Definition: Rect.h:147

◆ makeOutset() [2/2]

AI Rect skgpu::graphite::Rect::makeOutset ( float2  outset) const
inline

Definition at line 137 of file Rect.h.

137{ return fVals - outset.xyxy(); }

◆ makeRoundIn()

AI Rect skgpu::graphite::Rect::makeRoundIn ( ) const
inline

Definition at line 132 of file Rect.h.

132{ return ceil(fVals); }
SIN Vec< N, float > ceil(const Vec< N, float > &x)
Definition: SkVx.h:702

◆ makeRoundOut()

AI Rect skgpu::graphite::Rect::makeRoundOut ( ) const
inline

Definition at line 133 of file Rect.h.

133{ return floor(fVals); }
SIN Vec< N, float > floor(const Vec< N, float > &x)
Definition: SkVx.h:703

◆ makeSorted()

AI Rect skgpu::graphite::Rect::makeSorted ( ) const
inline

Definition at line 141 of file Rect.h.

141{ return min(fVals, -fVals.zwxy()); }

◆ offset()

AI Rect & skgpu::graphite::Rect::offset ( float2  offset)
inline

Definition at line 149 of file Rect.h.

149{ return *this = this->makeOffset(offset); }
AI Rect makeOffset(float2 offset) const
Definition: Rect.h:138

◆ operator!=()

AI bool skgpu::graphite::Rect::operator!= ( Rect  rect) const
inline

Definition at line 69 of file Rect.h.

69{ return any(fVals != rect.fVals); }
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530

◆ operator==()

AI bool skgpu::graphite::Rect::operator== ( Rect  rect) const
inline

Definition at line 68 of file Rect.h.

68{ return all(fVals == rect.fVals); }

◆ outset() [1/2]

AI Rect & skgpu::graphite::Rect::outset ( float  outset)
inline

Definition at line 147 of file Rect.h.

147{ return *this = this->makeOutset(outset); }
AI Rect makeOutset(float outset) const
Definition: Rect.h:136

◆ outset() [2/2]

AI Rect & skgpu::graphite::Rect::outset ( float2  outset)
inline

Definition at line 148 of file Rect.h.

148{ return *this = this->makeOutset(outset); }

◆ Point()

static AI Rect skgpu::graphite::Rect::Point ( float2  p)
inlinestatic

Definition at line 52 of file Rect.h.

52 {
53 return Rect(p, p);
54 }

◆ right()

AI float skgpu::graphite::Rect::right ( ) const
inline

Definition at line 78 of file Rect.h.

78{ return -fVals.z(); }

◆ roundIn()

AI Rect & skgpu::graphite::Rect::roundIn ( )
inline

Definition at line 143 of file Rect.h.

143{ return *this = this->makeRoundIn(); }
AI Rect makeRoundIn() const
Definition: Rect.h:132

◆ roundOut()

AI Rect & skgpu::graphite::Rect::roundOut ( )
inline

Definition at line 144 of file Rect.h.

144{ return *this = this->makeRoundOut(); }
AI Rect makeRoundOut() const
Definition: Rect.h:133

◆ setBot()

AI void skgpu::graphite::Rect::setBot ( float  bot)
inline

Definition at line 87 of file Rect.h.

87{ fVals.w() = -bot; }
AI float bot() const
Definition: Rect.h:79

◆ setBotRight()

AI void skgpu::graphite::Rect::setBotRight ( float2  botRight)
inline

Definition at line 89 of file Rect.h.

89{ fVals.zw() = -botRight; }

◆ setLeft()

AI void skgpu::graphite::Rect::setLeft ( float  left)
inline

Definition at line 84 of file Rect.h.

84{ fVals.x() = left; }
AI float left() const
Definition: Rect.h:76

◆ setRight()

AI void skgpu::graphite::Rect::setRight ( float  right)
inline

Definition at line 86 of file Rect.h.

86{ fVals.z() = -right; }
AI float right() const
Definition: Rect.h:78

◆ setTop()

AI void skgpu::graphite::Rect::setTop ( float  top)
inline

Definition at line 85 of file Rect.h.

85{ fVals.y() = top; }
AI float top() const
Definition: Rect.h:77

◆ setTopLeft()

AI void skgpu::graphite::Rect::setTopLeft ( float2  topLeft)
inline

Definition at line 88 of file Rect.h.

88{ fVals.xy() = topLeft; }

◆ size()

AI float2 skgpu::graphite::Rect::size ( ) const
inline

Definition at line 107 of file Rect.h.

107{ return -(fVals.xy() + fVals.zw()); } // == [-(l-r), -(t-b)] == [w, h]

◆ sort()

AI Rect & skgpu::graphite::Rect::sort ( )
inline

Definition at line 152 of file Rect.h.

152{ return *this = this->makeSorted(); }
AI Rect makeSorted() const
Definition: Rect.h:141

◆ top()

AI float skgpu::graphite::Rect::top ( ) const
inline

Definition at line 77 of file Rect.h.

77{ return fVals.y(); }

◆ topLeft()

AI float2 skgpu::graphite::Rect::topLeft ( ) const
inline

Definition at line 80 of file Rect.h.

80{ return fVals.xy(); }

◆ vals() [1/2]

AI float4 & skgpu::graphite::Rect::vals ( )
inline

Definition at line 72 of file Rect.h.

72{ return fVals; } // [left, top, -right, -bot].

◆ vals() [2/2]

AI const float4 & skgpu::graphite::Rect::vals ( ) const
inline

Definition at line 71 of file Rect.h.

71{ return fVals; } // [left, top, -right, -bot].

◆ WH() [1/2]

static AI Rect skgpu::graphite::Rect::WH ( float  w,
float  h 
)
inlinestatic

Definition at line 46 of file Rect.h.

46 {
47 return Rect(0, 0, w, h);
48 }
SkScalar w
SkScalar h

◆ WH() [2/2]

static AI Rect skgpu::graphite::Rect::WH ( float2  size)
inlinestatic

Definition at line 49 of file Rect.h.

49 {
50 return Rect(float2(0), size);
51 }
AI float2 size() const
Definition: Rect.h:107

◆ x()

AI float skgpu::graphite::Rect::x ( ) const
inline

Definition at line 74 of file Rect.h.

74{ return fVals.x(); }

◆ XYWH() [1/2]

static AI Rect skgpu::graphite::Rect::XYWH ( float  x,
float  y,
float  w,
float  h 
)
inlinestatic

Definition at line 40 of file Rect.h.

40 {
41 return Rect(x, y, x + w, y + h);
42 }
AI float y() const
Definition: Rect.h:75
AI float x() const
Definition: Rect.h:74

◆ XYWH() [2/2]

static AI Rect skgpu::graphite::Rect::XYWH ( float2  topLeft,
float2  size 
)
inlinestatic

Definition at line 43 of file Rect.h.

43 {
44 return Rect(topLeft, topLeft + size);
45 }

◆ y()

AI float skgpu::graphite::Rect::y ( ) const
inline

Definition at line 75 of file Rect.h.

75{ return fVals.y(); }

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