@@ -131,7 +131,8 @@ public Polygon Run()
131
131
int clippingVertexCount = clipping . GetVertexCount ( ) ;
132
132
int eventCount = ( subjectVertexCount + clippingVertexCount ) * 2 ;
133
133
134
- StablePriorityQueue < SweepEvent , SweepEventComparer > eventQueue = new ( new SweepEventComparer ( ) , eventCount ) ;
134
+ SweepEventComparer comparer = new ( ) ;
135
+ List < SweepEvent > unorderedEventQueue = new ( eventCount ) ;
135
136
int contourId = 0 ;
136
137
137
138
for ( int i = 0 ; i < subject . ContourCount ; i ++ )
@@ -140,7 +141,14 @@ public Polygon Run()
140
141
contourId ++ ;
141
142
for ( int j = 0 ; j < contour . VertexCount - 1 ; j ++ )
142
143
{
143
- ProcessSegment ( contourId , contour . Segment ( j ) , PolygonType . Subject , eventQueue , ref min , ref max ) ;
144
+ ProcessSegment (
145
+ contourId ,
146
+ contour . Segment ( j ) ,
147
+ PolygonType . Subject ,
148
+ unorderedEventQueue ,
149
+ comparer ,
150
+ ref min ,
151
+ ref max ) ;
144
152
}
145
153
}
146
154
@@ -155,7 +163,14 @@ public Polygon Run()
155
163
156
164
for ( int j = 0 ; j < contour . VertexCount - 1 ; j ++ )
157
165
{
158
- ProcessSegment ( contourId , contour . Segment ( j ) , PolygonType . Clipping , eventQueue , ref min , ref max ) ;
166
+ ProcessSegment (
167
+ contourId ,
168
+ contour . Segment ( j ) ,
169
+ PolygonType . Clipping ,
170
+ unorderedEventQueue ,
171
+ comparer ,
172
+ ref min ,
173
+ ref max ) ;
159
174
}
160
175
}
161
176
@@ -166,14 +181,14 @@ public Polygon Run()
166
181
}
167
182
168
183
// Sweep line algorithm: process events in the priority queue
184
+ StablePriorityQueue < SweepEvent , SweepEventComparer > eventQueue = new ( comparer , unorderedEventQueue ) ;
169
185
List < SweepEvent > sortedEvents = new ( eventCount ) ;
170
186
171
187
// Heuristic capacity for the sweep line status structure.
172
188
// At any given point during the sweep, only a subset of segments
173
189
// are active, so we preallocate half the subject's vertex count
174
190
// to reduce resizing without overcommitting memory.
175
191
StatusLine statusLine = new ( subjectVertexCount >> 1 ) ;
176
- SweepEventComparer comparer = eventQueue . Comparer ;
177
192
double subjectMaxX = subjectBB . Max . X ;
178
193
double minMaxX = Vertex . Min ( subjectBB . Max , clippingBB . Max ) . X ;
179
194
@@ -348,14 +363,16 @@ private static bool TryTrivialOperationForNonOverlappingBoundingBoxes(
348
363
/// <param name="contourId">The identifier of the contour to which the segment belongs.</param>
349
364
/// <param name="s">The segment to process.</param>
350
365
/// <param name="pt">The polygon type to which the segment belongs.</param>
351
- /// <param name="eventQueue">The event queue to add the generated events to.</param>
366
+ /// <param name="eventQueue">The unordered event queue to add the generated events to.</param>
367
+ /// <param name="comparer">The comparer used to determine the order of sweep events in the queue.</param>
352
368
/// <param name="min">The minimum vertex of the bounding box.</param>
353
369
/// <param name="max">The maximum vertex of the bounding box.</param>
354
370
private static void ProcessSegment (
355
371
int contourId ,
356
372
Segment s ,
357
373
PolygonType pt ,
358
- StablePriorityQueue < SweepEvent , SweepEventComparer > eventQueue ,
374
+ List < SweepEvent > eventQueue ,
375
+ SweepEventComparer comparer ,
359
376
ref Vertex min ,
360
377
ref Vertex max )
361
378
{
@@ -372,7 +389,7 @@ private static void ProcessSegment(
372
389
e1 . ContourId = e2 . ContourId = contourId ;
373
390
374
391
// Determine which endpoint is the left endpoint
375
- if ( eventQueue . Comparer . Compare ( e1 , e2 ) < 0 )
392
+ if ( comparer . Compare ( e1 , e2 ) < 0 )
376
393
{
377
394
e2 . Left = false ;
378
395
}
@@ -385,8 +402,8 @@ private static void ProcessSegment(
385
402
max = Vertex . Max ( max , s . Max ) ;
386
403
387
404
// Add the events to the event queue
388
- eventQueue . Enqueue ( e1 ) ;
389
- eventQueue . Enqueue ( e2 ) ;
405
+ eventQueue . Add ( e1 ) ;
406
+ eventQueue . Add ( e2 ) ;
390
407
}
391
408
392
409
/// <summary>
0 commit comments