Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkRRect.h" |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 12 | |
Cary Clark | 1e447df | 2018-06-12 16:49:49 -0400 | [diff] [blame] | 13 | class SkRBuffer; |
| 14 | class SkWBuffer; |
| 15 | |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 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 | |
Chris Dalton | 133944a | 2018-11-16 23:30:29 -0500 | [diff] [blame] | 35 | static const SkVector* GetRadiiArray(const SkRRect& rr) { return rr.fRadii; } |
| 36 | |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 37 | static bool AllCornersCircular(const SkRRect& rr, SkScalar tolerance = SK_ScalarNearlyZero); |
Cary Clark | 1e447df | 2018-06-12 16:49:49 -0400 | [diff] [blame] | 38 | |
| 39 | static bool ReadFromBuffer(SkRBuffer* buffer, SkRRect* rr); |
| 40 | |
| 41 | static void WriteToBuffer(const SkRRect& rr, SkWBuffer* buffer); |
Michael Ludwig | eaeb996 | 2020-04-17 12:11:21 -0400 | [diff] [blame] | 42 | |
| 43 | // Compute an approximate largest inscribed bounding box of the rounded rect. For empty, |
| 44 | // rect, oval, and simple types this will be the largest inscribed rectangle. Otherwise it may |
| 45 | // not be the global maximum, but will be non-empty, touch at least one edge and be contained |
| 46 | // in the round rect. |
| 47 | static SkRect InnerBounds(const SkRRect& rr); |
Michael Ludwig | 76312fb | 2020-04-20 18:21:42 -0400 | [diff] [blame] | 48 | |
| 49 | // Attempt to compute the intersection of two round rects. The intersection is not necessarily |
| 50 | // a round rect. This returns intersections only when the shape is representable as a new |
| 51 | // round rect (or rect). Empty is returned if 'a' and 'b' do not intersect or if the |
| 52 | // intersection is too complicated. This is conservative, it may not always detect that an |
| 53 | // intersection could be represented as a round rect. However, when it does return a round rect |
| 54 | // that intersection will be exact (i.e. it is NOT just a subset of the actual intersection). |
| 55 | static SkRRect ConservativeIntersect(const SkRRect& a, const SkRRect& b); |
Mike Reed | 242135a | 2018-02-22 13:41:39 -0500 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | #endif |