blob: 76470188e41bfa9dc41fe560fa849558b04f33a0 [file] [log] [blame]
Mike Reed242135a2018-02-22 13:41:39 -05001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkRRect.h"
Mike Reed242135a2018-02-22 13:41:39 -050012
Cary Clark1e447df2018-06-12 16:49:49 -040013class SkRBuffer;
14class SkWBuffer;
15
Mike Reed242135a2018-02-22 13:41:39 -050016class SkRRectPriv {
17public:
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 Dalton133944a2018-11-16 23:30:29 -050035 static const SkVector* GetRadiiArray(const SkRRect& rr) { return rr.fRadii; }
36
Mike Reed242135a2018-02-22 13:41:39 -050037 static bool AllCornersCircular(const SkRRect& rr, SkScalar tolerance = SK_ScalarNearlyZero);
Cary Clark1e447df2018-06-12 16:49:49 -040038
39 static bool ReadFromBuffer(SkRBuffer* buffer, SkRRect* rr);
40
41 static void WriteToBuffer(const SkRRect& rr, SkWBuffer* buffer);
Michael Ludwigeaeb9962020-04-17 12:11:21 -040042
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 Ludwig76312fb2020-04-20 18:21:42 -040048
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 Reed242135a2018-02-22 13:41:39 -050056};
57
58#endif