Skip to content

Commit 141e358

Browse files
committed
Refactor the sorting
* moved tests which are green now
1 parent a5a8774 commit 141e358

File tree

6 files changed

+21
-85
lines changed

6 files changed

+21
-85
lines changed

src/PolygonClipper/PolygonClipper.cs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,7 @@ public PolygonClipper(Polygon subject, Polygon clip, BooleanOperation operation)
5959
public static Polygon Intersection(Polygon subject, Polygon clip)
6060
{
6161
PolygonClipper clipper = new(subject, clip, BooleanOperation.Intersection);
62-
Polygon a = clipper.Run();
63-
64-
Polygon polygons = new();
65-
66-
67-
for (int i = 0; i < a.ContourCount; i++) {
68-
Contour contour = a[i];
69-
if (contour.IsExternal) {
70-
// The exterior ring goes first
71-
polygons.Push(contour);
72-
// Followed by holes if any
73-
for (int j = 0; j < contour.HoleCount; j++) {
74-
int holeId = contour.GetHoleIndex(j);
75-
polygons.Push(a[holeId]);
76-
}
77-
// polygons.Push(contour);
78-
}
79-
}
80-
81-
82-
return polygons;
62+
return clipper.Run();
8363
}
8464

8565
/// <summary>
@@ -886,7 +866,26 @@ private static Polygon ConnectEdges(List<SweepEvent> sortedEvents, SweepEventCom
886866
result.Push(contour);
887867
}
888868

889-
return result;
869+
Polygon polygon = new();
870+
871+
872+
for (int i = 0; i < result.ContourCount; i++)
873+
{
874+
Contour contour = result[i];
875+
if (contour.IsExternal)
876+
{
877+
// The exterior ring goes first
878+
polygon.Push(contour);
879+
880+
// Followed by holes if any
881+
for (int j = 0; j < contour.HoleCount; j++) {
882+
int holeId = contour.GetHoleIndex(j);
883+
polygon.Push(result[holeId]);
884+
}
885+
}
886+
}
887+
888+
return polygon;
890889
}
891890

892891
/// <summary>

tests/TestData/Generic/failing/collapsed_edges_removed.geojson

Lines changed: 0 additions & 63 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)