@@ -153,7 +153,8 @@ public Polygon Run()
153153 }
154154
155155 Box2 clippingBB = new ( min , max ) ;
156- if ( TryTrivialOperationForNonOverlappingBoundingBoxes ( subject , clipping , subjectBB , clippingBB , operation , out result ) )
156+ if ( TryTrivialOperationForNonOverlappingBoundingBoxes ( subject , clipping , subjectBB , clippingBB , operation ,
157+ out result ) )
157158 {
158159 return result ;
159160 }
@@ -221,17 +222,15 @@ public Polygon Run()
221222 sweepEvent = sweepEvent . OtherEvent ;
222223 int it = sweepEvent . PosSL ;
223224 prevEvent = statusLine . Prev ( it ) ;
224-
225- statusLine . RemoveAt ( it ) ;
226-
227- // Shift `next` to account for the removal
228- nextEvent = statusLine . Next ( it - 1 ) ;
225+ nextEvent = statusLine . Next ( it ) ;
229226
230227 // Check intersection between neighbors
231228 if ( prevEvent != null && nextEvent != null )
232229 {
233230 _ = PossibleIntersection ( prevEvent , nextEvent , eventQueue ) ;
234231 }
232+
233+ statusLine . RemoveAt ( it ) ;
235234 }
236235 }
237236
@@ -364,25 +363,13 @@ private static void ProcessSegment(
364363 e1 . ContourId = e2 . ContourId = contourId ;
365364
366365 // Determine which endpoint is the left endpoint
367- //if (s.Min == s.Source)
368- //{
369- // e2.Left = false;
370- //}
371- //else if (s.Min == s.Target)
372- //{
373- // e1.Left = false;
374- //}
375- //else
376- {
377- // As a fallback, use the comparator for floating-point precision issues
378- if ( eventQueue . Comparer . Compare ( e1 , e2 ) < 0 )
379- {
380- e2 . Left = false ;
381- }
382- else
383- {
384- e1 . Left = false ;
385- }
366+ if ( eventQueue . Comparer . Compare ( e1 , e2 ) < 0 )
367+ {
368+ e2 . Left = false ;
369+ }
370+ else
371+ {
372+ e1 . Left = false ;
386373 }
387374
388375 min = Vertex . Min ( min , s . Min ) ;
@@ -503,8 +490,9 @@ private static bool InResult(SweepEvent sweepEvent, BooleanOperation operation)
503490 {
504491 BooleanOperation . Intersection => ! sweepEvent . OtherInOut ,
505492 BooleanOperation . Union => sweepEvent . OtherInOut ,
506- BooleanOperation . Difference => ( sweepEvent . OtherInOut && sweepEvent . PolygonType == PolygonType . Subject ) ||
507- ( ! sweepEvent . OtherInOut && sweepEvent . PolygonType == PolygonType . Clipping ) ,
493+ BooleanOperation . Difference =>
494+ ( sweepEvent . OtherInOut && sweepEvent . PolygonType == PolygonType . Subject ) ||
495+ ( ! sweepEvent . OtherInOut && sweepEvent . PolygonType == PolygonType . Clipping ) ,
508496 BooleanOperation . Xor => true ,
509497 _ => false ,
510498 } ,
@@ -711,7 +699,7 @@ private static void DivideSegment(
711699 {
712700 // TODO: enabling this line makes a single test issue76.geojson fail.
713701 // The files are different in the two reference repositories but both fail.
714- // p = new Vertex(NextAfter( p.X, true ), p.Y);
702+ p = new Vertex ( p . X . NextAfter ( double . PositiveInfinity ) , p . Y ) ;
715703 }
716704
717705 // Create the right event for the left segment (new right endpoint)
@@ -740,34 +728,6 @@ private static void DivideSegment(
740728 eventQueue . Enqueue ( r ) ;
741729 }
742730
743- /// <summary>
744- /// Returns the next representable double-precision floating-point value in the given direction.
745- /// <see href="https://docs.rs/float_next_after/latest/float_next_after/trait.NextAfter.html"/>
746- /// </summary>
747- /// <param name="x">The starting double value.</param>
748- /// <param name="up">If true, moves towards positive infinity; otherwise, towards negative infinity.</param>
749- /// <returns>The next representable double in the given direction.</returns>
750- private static double NextAfter ( double x , bool up )
751- {
752- if ( double . IsNaN ( x ) || x == double . PositiveInfinity || x == double . NegativeInfinity )
753- {
754- return x ; // NaN and infinity stay the same
755- }
756-
757- // Convert double to its IEEE 754 bit representation
758- long bits = BitConverter . DoubleToInt64Bits ( x ) ;
759- if ( up )
760- {
761- bits += ( bits >= 0 ) ? 1 : - 1 ; // Increase magnitude
762- }
763- else
764- {
765- bits += ( bits > 0 ) ? - 1 : 1 ; // Decrease magnitude
766- }
767-
768- return BitConverter . Int64BitsToDouble ( bits ) ;
769- }
770-
771731 /// <summary>
772732 /// Connects edges in the result polygon by processing the sweep events
773733 /// and constructing contours for the final result.
@@ -860,8 +820,7 @@ private static Polygon ConnectEdges(List<SweepEvent> sortedEvents, SweepEventCom
860820 resultEvents [ pos ] . OutputContourId = contourId ;
861821 contour . AddVertex ( resultEvents [ pos ] . Point ) ;
862822 pos = NextPos ( pos , resultEvents , processed , originalPos ) ;
863- }
864- while ( pos != originalPos && pos < resultEvents . Count ) ;
823+ } while ( pos != originalPos && pos < resultEvents . Count ) ;
865824
866825 result . Push ( contour ) ;
867826 }
@@ -878,7 +837,8 @@ private static Polygon ConnectEdges(List<SweepEvent> sortedEvents, SweepEventCom
878837 polygon . Push ( contour ) ;
879838
880839 // Followed by holes if any
881- for ( int j = 0 ; j < contour . HoleCount ; j ++ ) {
840+ for ( int j = 0 ; j < contour . HoleCount ; j ++ )
841+ {
882842 int holeId = contour . GetHoleIndex ( j ) ;
883843 polygon . Push ( result [ holeId ] ) ;
884844 }
0 commit comments