@@ -120,7 +120,7 @@ public ComplexPolygon(params IPath[] paths)
120120 public int MaxIntersections { get ; }
121121
122122 /// <summary>
123- /// the distance of the point from the outline of the shape, if the value is negative it is inside the polygon bounds
123+ /// The distance of the point from the outline of the shape, if the value is negative it is inside the polygon bounds
124124 /// </summary>
125125 /// <param name="point">The point.</param>
126126 /// <returns>
@@ -162,81 +162,43 @@ public PointInfo Distance(PointF point)
162162 return pointInfo ;
163163 }
164164
165- /// <summary>
166- /// Based on a line described by <paramref name="start"/> and <paramref name="end"/>
167- /// populate a buffer for all points on all the polygons, that make up this complex shape,
168- /// that the line intersects.
169- /// </summary>
170- /// <param name="start">The start point of the line.</param>
171- /// <param name="end">The end point of the line.</param>
172- /// <param name="buffer">The buffer that will be populated with intersections.</param>
173- /// <param name="offset">The offset within the buffer</param>
174- /// <returns>
175- /// The number of intersections populated into the buffer.
176- /// </returns>
177- public int FindIntersections ( PointF start , PointF end , PointF [ ] buffer , int offset )
178- => this . FindIntersections ( start , end , buffer , offset , IntersectionRule . OddEven ) ;
179-
180165 /// <inheritdoc />
181- public int FindIntersections ( PointF start , PointF end , Span < PointF > buffer )
182- => this . FindIntersections ( start , end , buffer , IntersectionRule . OddEven ) ;
183-
184- /// <summary>
185- /// Based on a line described by <paramref name="start"/> and <paramref name="end"/>
186- /// populate a buffer for all points on all the polygons, that make up this complex shape,
187- /// that the line intersects.
188- /// </summary>
189- /// <param name="start">The start point of the line.</param>
190- /// <param name="end">The end point of the line.</param>
191- /// <param name="buffer">The buffer that will be populated with intersections.</param>
192- /// <param name="offset">The offset within the buffer</param>
193- /// <param name="intersectionRule">The intersection rule to use</param>
194- /// <returns>
195- /// The number of intersections populated into the buffer.
196- /// </returns>
197- public int FindIntersections ( PointF start , PointF end , PointF [ ] buffer , int offset , IntersectionRule intersectionRule )
198- {
199- Span < PointF > subBuffer = buffer . AsSpan ( offset ) ;
200- return this . FindIntersections ( start , end , subBuffer , intersectionRule ) ;
201- }
166+ public int FindIntersections ( PointF start , PointF end , Span < PointF > intersections , Span < PointOrientation > orientations )
167+ => this . FindIntersections ( start , end , intersections , orientations , IntersectionRule . OddEven ) ;
202168
203169 /// <inheritdoc />
204- public int FindIntersections ( PointF start , PointF end , Span < PointF > buffer , IntersectionRule intersectionRule )
170+ public int FindIntersections (
171+ PointF start ,
172+ PointF end ,
173+ Span < PointF > intersections ,
174+ Span < PointOrientation > orientations ,
175+ IntersectionRule intersectionRule )
205176 {
206177 this . EnsureInternalPathsInitalized ( ) ;
207178
208179 int totalAdded = 0 ;
209- InternalPath . PointOrientation [ ] orientations = ArrayPool < InternalPath . PointOrientation > . Shared . Rent ( buffer . Length ) ; // the largest number of intersections of any sub path of the set is the max size with need for this buffer.
210- Span < InternalPath . PointOrientation > orientationsSpan = orientations ;
211- try
180+ foreach ( InternalPath ip in this . internalPaths )
212181 {
213- foreach ( var ip in this . internalPaths )
214- {
215- Span < PointF > subBuffer = buffer . Slice ( totalAdded ) ;
216- Span < InternalPath . PointOrientation > subOrientationsSpan = orientationsSpan . Slice ( totalAdded ) ;
182+ Span < PointF > subBuffer = intersections . Slice ( totalAdded ) ;
183+ Span < PointOrientation > subOrientationsSpan = orientations . Slice ( totalAdded ) ;
217184
218- var position = ip . FindIntersectionsWithOrientation ( start , end , subBuffer , subOrientationsSpan ) ;
219- totalAdded += position ;
220- }
185+ int position = ip . FindIntersectionsWithOrientation ( start , end , subBuffer , subOrientationsSpan ) ;
186+ totalAdded += position ;
187+ }
221188
222- Span < float > distances = stackalloc float [ totalAdded ] ;
223- for ( int i = 0 ; i < totalAdded ; i ++ )
224- {
225- distances [ i ] = Vector2 . DistanceSquared ( start , buffer [ i ] ) ;
226- }
189+ Span < float > distances = stackalloc float [ totalAdded ] ;
190+ for ( int i = 0 ; i < totalAdded ; i ++ )
191+ {
192+ distances [ i ] = Vector2 . DistanceSquared ( start , intersections [ i ] ) ;
193+ }
227194
228- var activeBuffer = buffer . Slice ( 0 , totalAdded ) ;
229- var activeOrientationsSpan = orientationsSpan . Slice ( 0 , totalAdded ) ;
230- SortUtility . Sort ( distances , activeBuffer , activeOrientationsSpan ) ;
195+ Span < PointF > activeIntersections = intersections . Slice ( 0 , totalAdded ) ;
196+ Span < PointOrientation > activeOrientations = orientations . Slice ( 0 , totalAdded ) ;
197+ SortUtility . Sort ( distances , activeIntersections , activeOrientations ) ;
231198
232- if ( intersectionRule == IntersectionRule . Nonzero )
233- {
234- totalAdded = InternalPath . ApplyNonZeroIntersectionRules ( activeBuffer , activeOrientationsSpan ) ;
235- }
236- }
237- finally
199+ if ( intersectionRule == IntersectionRule . Nonzero )
238200 {
239- ArrayPool < InternalPath . PointOrientation > . Shared . Return ( orientations ) ;
201+ totalAdded = InternalPath . ApplyNonZeroIntersectionRules ( activeIntersections , activeOrientations ) ;
240202 }
241203
242204 return totalAdded ;
@@ -252,9 +214,9 @@ private void EnsureInternalPathsInitalized()
252214 {
253215 this . internalPaths = new List < InternalPath > ( this . paths . Length ) ;
254216
255- foreach ( var p in this . paths )
217+ foreach ( IPath p in this . paths )
256218 {
257- foreach ( var s in p . Flatten ( ) )
219+ foreach ( ISimplePath s in p . Flatten ( ) )
258220 {
259221 var ip = new InternalPath ( s . Points , s . IsClosed ) ;
260222 this . internalPaths . Add ( ip ) ;
@@ -361,7 +323,7 @@ public IPath AsClosedPath()
361323 /// </returns>
362324 public SegmentInfo PointAlongPath ( float distanceAlongPath )
363325 {
364- distanceAlongPath = distanceAlongPath % this . Length ;
326+ distanceAlongPath %= this . Length ;
365327
366328 foreach ( IPath p in this . Paths )
367329 {
0 commit comments