Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
GrRect.h File Reference
#include "include/core/SkMatrix.h"
#include "include/core/SkRect.h"
#include "include/core/SkTypes.h"

Go to the source code of this file.

Functions

static bool GrRectsOverlap (const SkRect &a, const SkRect &b)
 
static bool GrRectsTouchOrOverlap (const SkRect &a, const SkRect &b)
 
static void GrMapRectPoints (const SkRect &inRect, const SkRect &outRect, const SkPoint inPts[], SkPoint outPts[], int ptCount)
 
static bool GrClipSrcRectAndDstPoint (const SkISize &dstSize, SkIPoint *dstPoint, const SkISize &srcSize, SkIRect *srcRect)
 

Function Documentation

◆ GrClipSrcRectAndDstPoint()

static bool GrClipSrcRectAndDstPoint ( const SkISize dstSize,
SkIPoint dstPoint,
const SkISize srcSize,
SkIRect srcRect 
)
inlinestatic

Clips the srcRect and the dstPoint to the bounds of the srcSize and dstSize respectively. Returns true if the srcRect and dstRect intersect the srcRect and dst rect (dstPoint with srcRect width/height). Returns false otherwise. The clipped values are stored back into 'dstPoint' and 'srcRect'

Definition at line 48 of file GrRect.h.

51 {
52 // clip the left edge to src and dst bounds, adjusting dstPoint if necessary
53 if (srcRect->fLeft < 0) {
54 dstPoint->fX -= srcRect->fLeft;
55 srcRect->fLeft = 0;
56 }
57 if (dstPoint->fX < 0) {
58 srcRect->fLeft -= dstPoint->fX;
59 dstPoint->fX = 0;
60 }
61
62 // clip the top edge to src and dst bounds, adjusting dstPoint if necessary
63 if (srcRect->fTop < 0) {
64 dstPoint->fY -= srcRect->fTop;
65 srcRect->fTop = 0;
66 }
67 if (dstPoint->fY < 0) {
68 srcRect->fTop -= dstPoint->fY;
69 dstPoint->fY = 0;
70 }
71
72 // clip the right edge to the src and dst bounds.
73 if (srcRect->fRight > srcSize.width()) {
74 srcRect->fRight = srcSize.width();
75 }
76 if (dstPoint->fX + srcRect->width() > dstSize.width()) {
77 srcRect->fRight = srcRect->fLeft + dstSize.width() - dstPoint->fX;
78 }
79
80 // clip the bottom edge to the src and dst bounds.
81 if (srcRect->fBottom > srcSize.height()) {
82 srcRect->fBottom = srcSize.height();
83 }
84 if (dstPoint->fY + srcRect->height() > dstSize.height()) {
85 srcRect->fBottom = srcRect->fTop + dstSize.height() - dstPoint->fY;
86 }
87
88 // The above clipping steps may have inverted the rect if it didn't intersect either the src or
89 // dst bounds.
90 return !srcRect->isEmpty();
91}
int32_t fX
x-axis value
int32_t fY
y-axis value
int32_t fBottom
larger y-axis bounds
Definition SkRect.h:36
constexpr int32_t height() const
Definition SkRect.h:165
int32_t fTop
smaller y-axis bounds
Definition SkRect.h:34
constexpr int32_t width() const
Definition SkRect.h:158
bool isEmpty() const
Definition SkRect.h:202
int32_t fLeft
smaller x-axis bounds
Definition SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition SkRect.h:35
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37

◆ GrMapRectPoints()

static void GrMapRectPoints ( const SkRect inRect,
const SkRect outRect,
const SkPoint  inPts[],
SkPoint  outPts[],
int  ptCount 
)
inlinestatic

Apply the transform from 'inRect' to 'outRect' to each point in 'inPts', storing the mapped point into the parallel index of 'outPts'.

Definition at line 37 of file GrRect.h.

38 {
39 SkMatrix::RectToRect(inRect, outRect).mapPoints(outPts, inPts, ptCount);
40}
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition SkMatrix.h:157
void mapPoints(SkPoint dst[], const SkPoint src[], int count) const
Definition SkMatrix.cpp:770

◆ GrRectsOverlap()

static bool GrRectsOverlap ( const SkRect a,
const SkRect b 
)
inlinestatic

Returns true if the rectangles have a nonzero area of overlap. It assumed that rects can be infinitely small but not "inverted".

Definition at line 17 of file GrRect.h.

17 {
18 // See skbug.com/6607 about the isFinite() checks.
19 SkASSERT(!a.isFinite() || (a.fLeft <= a.fRight && a.fTop <= a.fBottom));
20 SkASSERT(!b.isFinite() || (b.fLeft <= b.fRight && b.fTop <= b.fBottom));
21 return a.fRight > b.fLeft && a.fBottom > b.fTop && b.fRight > a.fLeft && b.fBottom > a.fTop;
22}
#define SkASSERT(cond)
Definition SkAssert.h:116
static bool b
struct MyStruct a[10]

◆ GrRectsTouchOrOverlap()

static bool GrRectsTouchOrOverlap ( const SkRect a,
const SkRect b 
)
inlinestatic

Returns true if the rectangles overlap or share an edge or corner. It assumed that rects can be infinitely small but not "inverted".

Definition at line 26 of file GrRect.h.

26 {
27 // See skbug.com/6607 about the isFinite() checks.
28 SkASSERT(!a.isFinite() || (a.fLeft <= a.fRight && a.fTop <= a.fBottom));
29 SkASSERT(!b.isFinite() || (b.fLeft <= b.fRight && b.fTop <= b.fBottom));
30 return a.fRight >= b.fLeft && a.fBottom >= b.fTop && b.fRight >= a.fLeft && b.fBottom >= a.fTop;
31}