@@ -171,6 +171,9 @@ public struct AffineTransform: Equatable, CustomDebugStringConvertible {
171171}
172172
173173public struct Path {
174+ /// A rectangle in 2-D space.
175+ ///
176+ /// This type is inspired by `CGRect`.
174177 public struct Rect : Equatable {
175178 public var origin : SIMD2 < Double >
176179 public var size : SIMD2 < Double >
@@ -186,6 +189,8 @@ public struct Path {
186189 public var height : Double { size. y }
187190
188191 public var center : SIMD2 < Double > { size * 0.5 + origin }
192+ public var maxX : Double { size. x + origin. x }
193+ public var maxY : Double { size. y + origin. y }
189194
190195 public init ( x: Double , y: Double , width: Double , height: Double ) {
191196 origin = SIMD2 ( x: x, y: y)
@@ -209,7 +214,6 @@ public struct Path {
209214 clockwise: Bool
210215 )
211216 case transform( AffineTransform )
212- case subpath( [ Action ] , FillRule )
213217 }
214218
215219 /// A list of every action that has been performed on this path.
@@ -286,10 +290,14 @@ public struct Path {
286290 }
287291
288292 public consuming func addSubpath( _ subpath: Path ) -> Path {
289- actions. append ( . subpath ( subpath . actions , subpath. fillRule ) )
293+ actions. append ( contentsOf : subpath. actions )
290294 return self
291295 }
292296
297+ /// Set the default stroke style for the path.
298+ ///
299+ /// This is not necessarily respected; it can be overridden by ``Shape/stroke(_:style:)``,
300+ /// and is lost when the path is passed to ``addSubpath(_:)``.
293301 public consuming func stroke( style: StrokeStyle ) -> Path {
294302 strokeStyle = style
295303 return self
@@ -300,3 +308,18 @@ public struct Path {
300308 return self
301309 }
302310}
311+
312+ extension Path {
313+ @inlinable
314+ public consuming func `if`(
315+ _ condition: Bool ,
316+ then ifTrue: ( consuming Path ) -> Path ,
317+ else ifFalse: ( consuming Path ) -> Path = { $0 }
318+ ) -> Path {
319+ if condition {
320+ ifTrue ( self )
321+ } else {
322+ ifFalse ( self )
323+ }
324+ }
325+ }
0 commit comments