@@ -67,7 +67,7 @@ private extension LayerTree.Path {
6767
6868 for p in subpaths {
6969 let node = SubPathNode ( p)
70- if let idx = nodes. firstIndex ( where: { $0. bounds . contains ( point : node. bounds . center ) } ) {
70+ if let idx = nodes. firstIndex ( where: { $0. containsNode ( node) } ) {
7171 nodes [ idx] . append ( node)
7272 } else {
7373 nodes. append ( node)
@@ -77,8 +77,16 @@ private extension LayerTree.Path {
7777 }
7878}
7979
80+ #if canImport(CoreGraphics)
81+ import CoreGraphics
82+ #endif
83+
8084private struct SubPathNode {
8185 let path : LayerTree . Path
86+ #if canImport(CoreGraphics)
87+ let cgPath : CGPath
88+ #endif
89+
8290 let bounds : LayerTree . Rect
8391 let direction : LayerTree . Path . Direction
8492 var children : [ SubPathNode ] = [ ]
@@ -87,10 +95,14 @@ private struct SubPathNode {
8795 self . path = path
8896 self . bounds = path. bounds
8997 self . direction = path. segments. direction
98+
99+ #if canImport(CoreGraphics)
100+ self . cgPath = CGProvider ( ) . createPath ( from: . path( path) )
101+ #endif
90102 }
91103
92104 mutating func append( _ node: SubPathNode ) {
93- if let idx = children. firstIndex ( where: { $0. bounds . contains ( point : node. bounds . center ) } ) {
105+ if let idx = children. firstIndex ( where: { $0. containsNode ( node) } ) {
94106 children [ idx] . append ( node)
95107 } else {
96108 children. append ( node)
@@ -101,6 +113,20 @@ private struct SubPathNode {
101113 windPaths ( direction)
102114 }
103115
116+ func containsNode( _ node: SubPathNode ) -> Bool {
117+ #if canImport(CoreGraphics)
118+ let provider = CGProvider ( )
119+ for point in node. path. segments. compactMap ( \. location) {
120+ if cgPath. contains ( provider. createPoint ( from: point) ) {
121+ return true
122+ }
123+ }
124+ return false
125+ #else
126+ return bounds. contains ( point: node. bounds. center)
127+ #endif
128+ }
129+
104130 func windPaths( _ direction: LayerTree . Path . Direction ) -> [ LayerTree . Path ] {
105131 var paths = [ LayerTree . Path] ( )
106132
0 commit comments