1 /*
2  * Copyright 2018 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.compose.ui.graphics
18 
19 import androidx.compose.runtime.Immutable
20 
21 /**
22  * Strategies for combining paths.
23  *
24  * See also:
25  * * [Path.combine], which uses this enum to decide how to combine two paths.
26  */
27 // Must be kept in sync with SkPathOp
28 @Immutable
29 @kotlin.jvm.JvmInline
30 value class PathOperation internal constructor(@Suppress("unused") private val value: Int) {
31     companion object {
32         /**
33          * Subtract the second path from the first path.
34          *
35          * For example, if the two paths are overlapping circles of equal diameter but differing
36          * centers, the result would be a crescent portion of the first circle that was not
37          * overlapped by the second circle.
38          *
39          * See also:
40          * * [ReverseDifference], which is the same but subtracting the first path from the second.
41          */
42         val Difference = PathOperation(0)
43         /**
44          * Create a new path that is the intersection of the two paths, leaving the overlapping
45          * pieces of the path.
46          *
47          * For example, if the two paths are overlapping circles of equal diameter but differing
48          * centers, the result would be only the overlapping portion of the two circles.
49          *
50          * See also:
51          * * [Xor], which is the inverse of this operation
52          */
53         val Intersect = PathOperation(1)
54 
55         /**
56          * Create a new path that is the union (inclusive-or) of the two paths.
57          *
58          * For example, if the two paths are overlapping circles of equal diameter but differing
59          * centers, the result would be a figure-eight like shape matching the outer boundaries of
60          * both circles.
61          */
62         val Union = PathOperation(2)
63 
64         /**
65          * Create a new path that is the exclusive-or of the two paths, leaving everything but the
66          * overlapping pieces of the path.
67          *
68          * For example, if the two paths are overlapping circles of equal diameter but differing
69          * centers, the figure-eight like shape less the overlapping parts
70          *
71          * See also:
72          * * [Intersect], which is the inverse of this operation
73          */
74         val Xor = PathOperation(3)
75 
76         /**
77          * Subtract the first path from the second path.
78          *
79          * For example, if the two paths are overlapping circles of equal diameter but differing
80          * centers, the result would be a crescent portion of the second circle that was not
81          * overlapped by the first circle.
82          *
83          * See also:
84          * * [Difference], which is the same but subtracting the second path from the first.
85          */
86         val ReverseDifference = PathOperation(4)
87     }
88 
toStringnull89     override fun toString() =
90         when (this) {
91             Difference -> "Difference"
92             Intersect -> "Intersect"
93             Union -> "Union"
94             Xor -> "Xor"
95             ReverseDifference -> "ReverseDifference"
96             else -> "Unknown"
97         }
98 }
99 
100 @Deprecated(
101     message = "Use PathOperation.Difference instead",
102     ReplaceWith("PathOperation.Difference", "androidx.compose.ui.graphics.PathOperation.Difference")
103 )
104 val PathOperation.Companion.difference: PathOperation
105     get() = Difference
106 
107 @Deprecated(
108     message = "Use PathOperation.Intersect instead",
109     ReplaceWith("PathOperation.Intersect", "androidx.compose.ui.graphics.PathOperation.Intersect")
110 )
111 val PathOperation.Companion.intersect: PathOperation
112     get() = Intersect
113 
114 @Deprecated(
115     message = "Use PathOperation.Union instead",
116     ReplaceWith("PathOperation.Union", "androidx.compose.ui.graphics.PathOperation.Union")
117 )
118 val PathOperation.Companion.union: PathOperation
119     get() = Union
120 
121 @Deprecated(
122     message = "Use PathOperation.ReverseDifference instead",
123     ReplaceWith(
124         "PathOperation.ReverseDifference",
125         "androidx.compose.ui.graphics.PathOperation.ReverseDifference"
126     )
127 )
128 val PathOperation.Companion.reverseDifference: PathOperation
129     get() = ReverseDifference
130 
131 @Deprecated(
132     message = "Use PathOperation.Xor instead",
133     ReplaceWith("PathOperation.Xor", "androidx.compose.ui.graphics.PathOperation.Xor")
134 )
135 val PathOperation.Companion.xor: PathOperation
136     get() = Xor
137