| 1 |
/* |
| 2 |
* Copyright 2018 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 SkRRectPriv_DEFINED |
| 9 |
#define SkRRectPriv_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRRect.h" |
| 12 |
|
| 13 |
class SkRBuffer; |
| 14 |
class SkWBuffer; |
| 15 |
|
| 16 |
class SkRRectPriv { |
| 17 |
public: |
| 18 |
static bool IsCircle(const SkRRect& rr) { |
| 19 |
return rr.isOval() && SkScalarNearlyEqual(rr.fRadii[0].fX, rr.fRadii[0].fY); |
| 20 |
} |
| 21 |
|
| 22 |
static SkVector GetSimpleRadii(const SkRRect& rr) { |
| 23 |
SkASSERT(!rr.isComplex()); |
| 24 |
return rr.fRadii[0]; |
| 25 |
} |
| 26 |
|
| 27 |
static bool IsSimpleCircular(const SkRRect& rr) { |
| 28 |
return rr.isSimple() && SkScalarNearlyEqual(rr.fRadii[0].fX, rr.fRadii[0].fY); |
| 29 |
} |
| 30 |
|
| 31 |
// Looser version of IsSimpleCircular, where the x & y values of the radii |
| 32 |
// only have to be nearly equal instead of strictly equal. |
| 33 |
static bool IsNearlySimpleCircular(const SkRRect& rr, float tolerance = SK_ScalarNearlyZero); |
| 34 |
|
| 35 |
static bool EqualRadii(const SkRRect& rr) { |
| 36 |
return rr.isRect() || SkRRectPriv::IsCircle(rr) || SkRRectPriv::IsSimpleCircular(rr); |
| 37 |
} |
| 38 |
|
| 39 |
static const SkVector* GetRadiiArray(const SkRRect& rr) { return rr.fRadii; } |
| 40 |
|
| 41 |
static bool AllCornersCircular(const SkRRect& rr, float tolerance = SK_ScalarNearlyZero); |
| 42 |
|
| 43 |
// Prefer this over AllCornersCircular, which compares radii by absolute difference, which is |
| 44 |
// a less stable decision as scale changes. |
| 45 |
static bool AllCornersRelativelyCircular(const SkRRect& rr, |
| 46 |
float tolerance = SK_ScalarNearlyZero); |
| 47 |
|
| 48 |
// The same test used in AllCornersRelativelyCircular, but for provided radii. |
| 49 |
static bool IsRelativelyCircular(float rx, float ry, float tolerance = SK_ScalarNearlyZero); |
| 50 |
|
| 51 |
static bool ReadFromBuffer(SkRBuffer* buffer, SkRRect* rr); |
| 52 |
|
| 53 |
static void WriteToBuffer(const SkRRect& rr, SkWBuffer* buffer); |
| 54 |
|
| 55 |
// Test if a point is in the rrect, if it were a closed set. |
| 56 |
static bool ContainsPoint(const SkRRect& rr, const SkPoint& p) { |
| 57 |
return rr.getBounds().contains(p.fX, p.fY) && rr.checkCornerContainment(p.fX, p.fY); |
| 58 |
} |
| 59 |
|
| 60 |
// Compute an approximate largest inscribed bounding box of the rounded rect. For empty, |
| 61 |
// rect, oval, and simple types this will be the largest inscribed rectangle. Otherwise it may |
| 62 |
// not be the global maximum, but will be non-empty, touch at least one edge and be contained |
| 63 |
// in the round rect. |
| 64 |
static SkRect InnerBounds(const SkRRect& rr); |
| 65 |
|
| 66 |
// Attempt to compute the intersection of two round rects. The intersection is not necessarily |
| 67 |
// a round rect. This returns intersections only when the shape is representable as a new |
| 68 |
// round rect (or rect). Empty is returned if 'a' and 'b' do not intersect or if the |
| 69 |
// intersection is too complicated. This is conservative, it may not always detect that an |
| 70 |
// intersection could be represented as a round rect. However, when it does return a round rect |
| 71 |
// that intersection will be exact (i.e. it is NOT just a subset of the actual intersection). |
| 72 |
static SkRRect ConservativeIntersect(const SkRRect& a, const SkRRect& b); |
| 73 |
}; |
| 74 |
|
| 75 |
#endif |