Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrRect.h
Go to the documentation of this file.
1/*
2 * Copyright 2010 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrRect_DEFINED
9#define GrRect_DEFINED
10
12#include "include/core/SkRect.h"
14
15/** Returns true if the rectangles have a nonzero area of overlap. It assumed that rects can be
16 infinitely small but not "inverted". */
17static inline bool GrRectsOverlap(const SkRect& a, const SkRect& b) {
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}
23
24/** Returns true if the rectangles overlap or share an edge or corner. It assumed that rects can be
25 infinitely small but not "inverted". */
26static inline bool GrRectsTouchOrOverlap(const SkRect& a, const SkRect& b) {
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}
32
33/**
34 * Apply the transform from 'inRect' to 'outRect' to each point in 'inPts', storing the mapped point
35 * into the parallel index of 'outPts'.
36 */
37static inline void GrMapRectPoints(const SkRect& inRect, const SkRect& outRect,
38 const SkPoint inPts[], SkPoint outPts[], int ptCount) {
39 SkMatrix::RectToRect(inRect, outRect).mapPoints(outPts, inPts, ptCount);
40}
41
42/**
43 * Clips the srcRect and the dstPoint to the bounds of the srcSize and dstSize respectively. Returns
44 * true if the srcRect and dstRect intersect the srcRect and dst rect (dstPoint with srcRect
45 * width/height). Returns false otherwise. The clipped values are stored back into 'dstPoint'
46 * and 'srcRect'
47 */
48static inline bool GrClipSrcRectAndDstPoint(const SkISize& dstSize,
49 SkIPoint* dstPoint,
50 const SkISize& srcSize,
51 SkIRect* srcRect) {
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}
92
93#endif
static bool GrClipSrcRectAndDstPoint(const SkISize &dstSize, SkIPoint *dstPoint, const SkISize &srcSize, SkIRect *srcRect)
Definition GrRect.h:48
static bool GrRectsOverlap(const SkRect &a, const SkRect &b)
Definition GrRect.h:17
static void GrMapRectPoints(const SkRect &inRect, const SkRect &outRect, const SkPoint inPts[], SkPoint outPts[], int ptCount)
Definition GrRect.h:37
static bool GrRectsTouchOrOverlap(const SkRect &a, const SkRect &b)
Definition GrRect.h:26
#define SkASSERT(cond)
Definition SkAssert.h:116
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
static bool b
struct MyStruct a[10]
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