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 | static bool EqualRadii(const SkRRect& rr) { |
32 | return rr.isRect() || SkRRectPriv::IsCircle(rr) || SkRRectPriv::IsSimpleCircular(rr); |
33 | } |
34 | |
35 | static const SkVector* GetRadiiArray(const SkRRect& rr) { return rr.fRadii; } |
36 | |
37 | static bool AllCornersCircular(const SkRRect& rr, SkScalar tolerance = SK_ScalarNearlyZero); |
38 | |
39 | static bool ReadFromBuffer(SkRBuffer* buffer, SkRRect* rr); |
40 | |
41 | static void WriteToBuffer(const SkRRect& rr, SkWBuffer* buffer); |
42 | |
43 | // Test if a point is in the rrect, if it were a closed set. |
44 | static bool ContainsPoint(const SkRRect& rr, const SkPoint& p) { |
45 | return rr.getBounds().contains(p.fX, p.fY) && rr.checkCornerContainment(p.fX, p.fY); |
46 | } |
47 | |
48 | // Compute an approximate largest inscribed bounding box of the rounded rect. For empty, |
49 | // rect, oval, and simple types this will be the largest inscribed rectangle. Otherwise it may |
50 | // not be the global maximum, but will be non-empty, touch at least one edge and be contained |
51 | // in the round rect. |
52 | static SkRect InnerBounds(const SkRRect& rr); |
53 | |
54 | // Attempt to compute the intersection of two round rects. The intersection is not necessarily |
55 | // a round rect. This returns intersections only when the shape is representable as a new |
56 | // round rect (or rect). Empty is returned if 'a' and 'b' do not intersect or if the |
57 | // intersection is too complicated. This is conservative, it may not always detect that an |
58 | // intersection could be represented as a round rect. However, when it does return a round rect |
59 | // that intersection will be exact (i.e. it is NOT just a subset of the actual intersection). |
60 | static SkRRect ConservativeIntersect(const SkRRect& a, const SkRRect& b); |
61 | }; |
62 | |
63 | #endif |
64 | |