1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.graphics.shapes
18 
19 import androidx.annotation.FloatRange
20 import kotlin.jvm.JvmField
21 
22 /**
23  * CornerRounding defines the amount and quality around a given vertex of a shape. [radius] defines
24  * the radius of the circle which forms the basis of the rounding for the vertex. [smoothing]
25  * defines the amount by which the curve is extended from the circular arc around the corner to the
26  * edge between vertices.
27  *
28  * Each corner of a shape can be thought of as either: <em>
29  * <li> unrounded (with a corner radius of 0 and no smoothing) </li>
30  * <li> rounded with only a circular arc (with smoothing of 0). In this case, the rounding around
31  *   the corner follows an approximated circular arc between the edges to adjacent vertices. </li>
32  * <li> rounded with three curves: There is an inner circular arc and two symmetric flanking curves.
33  *   The flanking curves determine the curvature from the inner curve to the edges, with a value of
34  *   0 (no smoothing) meaning that it is purely a circular curve and a value of 1 meaning that the
35  *   flanking curves are maximized between the inner curve and the edges. </em>
36  *
37  * @param radius a value of 0 or greater, representing the radius of the circle which defines the
38  *   inner rounding arc of the corner. A value of 0 indicates that the corner is sharp, or
39  *   completely unrounded. A positive value is the requested size of the radius. Note that this
40  *   radius is an absolute size that should relate to the overall size of its shape. Thus if the
41  *   shape is in screen coordinate size, the radius should be sized appropriately. If the shape is
42  *   in some canonical form (bounds of (-1,-1) to (1,1), for example, which is the default when
43  *   creating a [RoundedPolygon] from a number of vertices), then the radius should be relative to
44  *   that size. The radius will be scaled if the shape itself is transformed, since it will produce
45  *   curves which round the corner and thus get transformed along with the overall shape.
46  * @param smoothing the amount by which the arc is "smoothed" by extending the curve from the inner
47  *   circular arc to the edge between vertices. A value of 0 (no smoothing) indicates that the
48  *   corner is rounded by only a circular arc; there are no flanking curves. A value of 1 indicates
49  *   that there is no circular arc in the center; the flanking curves on either side meet at the
50  *   middle.
51  */
52 class CornerRounding(
53     @FloatRange(from = 0.0) val radius: Float = 0f,
54     @FloatRange(from = 0.0, to = 1.0) val smoothing: Float = 0f
55 ) {
56 
57     companion object {
58         /** [Unrounded] has a rounding radius of zero, producing a sharp corner at a vertex. */
59         @JvmField val Unrounded = CornerRounding()
60     }
61 }
62