Flutter Engine
The Flutter Engine
Static Public Member Functions | List of all members
SkRectPriv Class Reference

#include <SkRectPriv.h>

Static Public Member Functions

static SkIRect MakeILarge ()
 
static SkIRect MakeILargestInverted ()
 
static SkRect MakeLargeS32 ()
 
static SkRect MakeLargest ()
 
static constexpr SkRect MakeLargestInverted ()
 
static void GrowToInclude (SkRect *r, const SkPoint &pt)
 
static bool FitsInFixed (const SkRect &r)
 
static constexpr float HalfWidth (const SkRect &r)
 
static constexpr float HalfHeight (const SkRect &r)
 
static bool Subtract (const SkRect &a, const SkRect &b, SkRect *out)
 
static bool Subtract (const SkIRect &a, const SkIRect &b, SkIRect *out)
 
static SkRect Subtract (const SkRect &a, const SkRect &b)
 
static SkIRect Subtract (const SkIRect &a, const SkIRect &b)
 
static bool QuadContainsRect (const SkMatrix &m, const SkIRect &a, const SkIRect &b, float tol=0.f)
 
static bool QuadContainsRect (const SkM44 &m, const SkRect &a, const SkRect &b, float tol=0.f)
 
static skvx::int4 QuadContainsRectMask (const SkM44 &m, const SkRect &a, const SkRect &b, float tol=0.f)
 
static SkIRect ClosestDisjointEdge (const SkIRect &src, const SkIRect &dst)
 

Detailed Description

Definition at line 18 of file SkRectPriv.h.

Member Function Documentation

◆ ClosestDisjointEdge()

SkIRect SkRectPriv::ClosestDisjointEdge ( const SkIRect src,
const SkIRect dst 
)
static

Definition at line 323 of file SkRect.cpp.

323 {
324 if (src.isEmpty() || dst.isEmpty()) {
325 return SkIRect::MakeEmpty();
326 }
327
328 int l = src.fLeft;
329 int r = src.fRight;
330 if (r <= dst.fLeft) {
331 // Select right column of pixels in crop
332 l = r - 1;
333 } else if (l >= dst.fRight) {
334 // Left column of 'crop'
335 r = l + 1;
336 } else {
337 // Regular intersection along X axis.
338 l = SkTPin(l, dst.fLeft, dst.fRight);
339 r = SkTPin(r, dst.fLeft, dst.fRight);
340 }
341
342 int t = src.fTop;
343 int b = src.fBottom;
344 if (b <= dst.fTop) {
345 // Select bottom row of pixels in crop
346 t = b - 1;
347 } else if (t >= dst.fBottom) {
348 // Top row of 'crop'
349 b = t + 1;
350 } else {
351 t = SkTPin(t, dst.fTop, dst.fBottom);
352 b = SkTPin(b, dst.fTop, dst.fBottom);
353 }
354
355 return SkIRect::MakeLTRB(l,t,r,b);
356}
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
static bool b
dst
Definition: cp.py:12
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition: SkRect.h:91
static constexpr SkIRect MakeEmpty()
Definition: SkRect.h:45

◆ FitsInFixed()

static bool SkRectPriv::FitsInFixed ( const SkRect r)
inlinestatic

Definition at line 56 of file SkRectPriv.h.

56 {
57 return SkFitsInFixed(r.fLeft) && SkFitsInFixed(r.fTop) &&
59 }
static bool SkFitsInFixed(T x)
Definition: SkMathPriv.h:329
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ GrowToInclude()

static void SkRectPriv::GrowToInclude ( SkRect r,
const SkPoint pt 
)
inlinestatic

Definition at line 47 of file SkRectPriv.h.

47 {
48 r->fLeft = std::min(pt.fX, r->fLeft);
49 r->fRight = std::max(pt.fX, r->fRight);
50 r->fTop = std::min(pt.fY, r->fTop);
51 r->fBottom = std::max(pt.fY, r->fBottom);
52 }
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ HalfHeight()

static constexpr float SkRectPriv::HalfHeight ( const SkRect r)
inlinestaticconstexpr

Definition at line 66 of file SkRectPriv.h.

66 {
67 return sk_float_midpoint(-r.fTop, r.fBottom);
68 }
static constexpr float sk_float_midpoint(float a, float b)

◆ HalfWidth()

static constexpr float SkRectPriv::HalfWidth ( const SkRect r)
inlinestaticconstexpr

Definition at line 62 of file SkRectPriv.h.

62 {
63 return sk_float_midpoint(-r.fLeft, r.fRight);
64 }

◆ MakeILarge()

static SkIRect SkRectPriv::MakeILarge ( )
inlinestatic

Definition at line 22 of file SkRectPriv.h.

22 {
23 // SK_MaxS32 >> 1 seemed better, but it did not survive round-trip with SkRect and rounding.
24 // Also, 1 << 29 can be perfectly represented in float, while SK_MaxS32 >> 1 cannot.
25 const int32_t large = 1 << 29;
26 return { -large, -large, large, large };
27 }

◆ MakeILargestInverted()

static SkIRect SkRectPriv::MakeILargestInverted ( )
inlinestatic

Definition at line 29 of file SkRectPriv.h.

29 {
31 }
static constexpr int32_t SK_MinS32
Definition: SkMath.h:22
static constexpr int32_t SK_MaxS32
Definition: SkMath.h:21

◆ MakeLargeS32()

static SkRect SkRectPriv::MakeLargeS32 ( )
inlinestatic

Definition at line 33 of file SkRectPriv.h.

33 {
34 SkRect r;
35 r.set(MakeILarge());
36 return r;
37 }
static SkIRect MakeILarge()
Definition: SkRectPriv.h:22
void set(const SkIRect &src)
Definition: SkRect.h:849

◆ MakeLargest()

static SkRect SkRectPriv::MakeLargest ( )
inlinestatic

Definition at line 39 of file SkRectPriv.h.

39 {
41 }
#define SK_ScalarMin
Definition: SkScalar.h:25
#define SK_ScalarMax
Definition: SkScalar.h:24

◆ MakeLargestInverted()

static constexpr SkRect SkRectPriv::MakeLargestInverted ( )
inlinestaticconstexpr

Definition at line 43 of file SkRectPriv.h.

43 {
45 }

◆ QuadContainsRect() [1/2]

bool SkRectPriv::QuadContainsRect ( const SkM44 m,
const SkRect a,
const SkRect b,
float  tol = 0.f 
)
static

Definition at line 268 of file SkRect.cpp.

268 {
269 return all(QuadContainsRectMask(m, a, b, tol));
270}
static skvx::int4 QuadContainsRectMask(const SkM44 &m, const SkRect &a, const SkRect &b, float tol=0.f)
Definition: SkRect.cpp:272
struct MyStruct a[10]
SIT bool all(const Vec< 1, T > &x)
Definition: SkVx.h:582

◆ QuadContainsRect() [2/2]

bool SkRectPriv::QuadContainsRect ( const SkMatrix m,
const SkIRect a,
const SkIRect b,
float  tol = 0.f 
)
static

Definition at line 261 of file SkRect.cpp.

264 {
266}
Definition: SkM44.h:150
static bool QuadContainsRect(const SkMatrix &m, const SkIRect &a, const SkIRect &b, float tol=0.f)
Definition: SkRect.cpp:261
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669

◆ QuadContainsRectMask()

skvx::int4 SkRectPriv::QuadContainsRectMask ( const SkM44 m,
const SkRect a,
const SkRect b,
float  tol = 0.f 
)
static

Definition at line 272 of file SkRect.cpp.

275 {
276 SkDEBUGCODE(SkM44 inverse;)
277 SkASSERT(m.invert(&inverse));
278 // With empty rectangles, the calculated edges could give surprising results. If 'a' were not
279 // sorted, its normals would point outside the sorted rectangle, so lots of potential rects
280 // would be seen as "contained". If 'a' is all 0s, its edge equations are also (0,0,0) so every
281 // point has a distance of 0, and would be interpreted as inside.
282 if (a.isEmpty()) {
283 return skvx::int4(0); // all "false"
284 }
285 // However, 'b' is only used to define its 4 corners to check against the transformed edges.
286 // This is valid regardless of b's emptiness or sortedness.
287
288 // Calculate the 4 homogenous coordinates of 'a' transformed by 'm' where Z=0 and W=1.
289 auto ax = skvx::float4{a.fLeft, a.fRight, a.fRight, a.fLeft};
290 auto ay = skvx::float4{a.fTop, a.fTop, a.fBottom, a.fBottom};
291
292 auto max = m.rc(0,0)*ax + m.rc(0,1)*ay + m.rc(0,3);
293 auto may = m.rc(1,0)*ax + m.rc(1,1)*ay + m.rc(1,3);
294 auto maw = m.rc(3,0)*ax + m.rc(3,1)*ay + m.rc(3,3);
295
296 if (all(maw < 0.f)) {
297 // If all points of A are mapped to w < 0, then the edge equations end up representing the
298 // convex hull of projected points when A should in fact be considered empty.
299 return skvx::int4(0); // all "false"
300 }
301
302 // Cross product of adjacent vertices provides homogenous lines for the 4 sides of the quad
303 auto lA = may*skvx::shuffle<1,2,3,0>(maw) - maw*skvx::shuffle<1,2,3,0>(may);
304 auto lB = maw*skvx::shuffle<1,2,3,0>(max) - max*skvx::shuffle<1,2,3,0>(maw);
305 auto lC = max*skvx::shuffle<1,2,3,0>(may) - may*skvx::shuffle<1,2,3,0>(max);
306
307 // Before transforming, the corners of 'a' were in CW order, but afterwards they may become CCW,
308 // so the sign corrects the direction of the edge normals to point inwards.
309 float sign = (lA[0]*lB[1] - lB[0]*lA[1]) < 0 ? -1.f : 1.f;
310
311 // Calculate distance from 'b' to each edge. Since 'b' has presumably been transformed by 'm'
312 // *and* projected, this assumes W = 1.
313 SkRect bInset = b.makeInset(tol, tol);
314 auto d0 = sign * (lA*bInset.fLeft + lB*bInset.fTop + lC);
315 auto d1 = sign * (lA*bInset.fRight + lB*bInset.fTop + lC);
316 auto d2 = sign * (lA*bInset.fRight + lB*bInset.fBottom + lC);
317 auto d3 = sign * (lA*bInset.fLeft + lB*bInset.fBottom + lC);
318
319 // 'b' is contained in the mapped rectangle if all distances are >= 0
320 return (d0 >= 0.f) & (d1 >= 0.f) & (d2 >= 0.f) & (d3 >= 0.f);
321}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static int sign(SkScalar x)
Definition: SkPath.cpp:2205
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
Vec< 4, int32_t > int4
Definition: SkVx.h:1159
Definition: SkVx.h:83

◆ Subtract() [1/4]

static SkIRect SkRectPriv::Subtract ( const SkIRect a,
const SkIRect b 
)
inlinestatic

Definition at line 83 of file SkRectPriv.h.

83 {
84 SkIRect diff;
85 Subtract(a, b, &diff);
86 return diff;
87 }
static bool Subtract(const SkRect &a, const SkRect &b, SkRect *out)
Definition: SkRect.cpp:252
Definition: SkRect.h:32

◆ Subtract() [2/4]

bool SkRectPriv::Subtract ( const SkIRect a,
const SkIRect b,
SkIRect out 
)
static

Definition at line 256 of file SkRect.cpp.

256 {
257 return subtract<SkIRect>(a, b, out);
258}

◆ Subtract() [3/4]

static SkRect SkRectPriv::Subtract ( const SkRect a,
const SkRect b 
)
inlinestatic

Definition at line 78 of file SkRectPriv.h.

78 {
79 SkRect diff;
80 Subtract(a, b, &diff);
81 return diff;
82 }

◆ Subtract() [4/4]

bool SkRectPriv::Subtract ( const SkRect a,
const SkRect b,
SkRect out 
)
static

Definition at line 252 of file SkRect.cpp.

252 {
253 return subtract<SkRect>(a, b, out);
254}

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