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