diff --git a/Scripts/ShapeEditor/Decomposition/PolyBoolCS/PolyboolExtensions.cs b/Scripts/ShapeEditor/Decomposition/PolyBoolCS/PolyboolExtensions.cs index e61ea2b..b2f6784 100644 --- a/Scripts/ShapeEditor/Decomposition/PolyBoolCS/PolyboolExtensions.cs +++ b/Scripts/ShapeEditor/Decomposition/PolyBoolCS/PolyboolExtensions.cs @@ -41,13 +41,14 @@ public static List ToPolygons(this PolyboolPolygon poly, PolyBool polyB { // make sure out polygon is clean poly = polyBool.polygon(polyBool.segments(poly)); + var simpleRegions = SingularRegionSplitter.Split(poly.regions); var roots = newNode(null); // add all regions to the root - for (var i = 0; i < poly.regions.Count; i++) + for (var i = 0; i < simpleRegions.Count; i++) { - var region = poly.regions[i]; + var region = simpleRegions[i]; if (region.Count < 3) // regions must have at least 3 points (sanity check) continue; addChild(roots, region); @@ -83,13 +84,27 @@ public static List ToPolygons(this PolyboolPolygon poly, PolyBool polyB // test if r1 is inside r2 private static bool regionInsideRegion(Region r1, Region r2) { - // we're guaranteed no lines intersect (because the polygon is clean), but a vertex - // could be on the edge -- so we just average pt[0] and pt[1] to produce a point on the - // edge of the first line, which cannot be on an edge - return Epsilon.pointInsideRegion(new Point( - (r1[0].x + r1[1].x) * 0.5, - (r1[0].y + r1[1].y) * 0.5 - ), r2); + for (int i = 0; i < r1.Count; i++) + { + var next = r1[(i + 1) % r1.Count]; + var midpoint = new Point((r1[i].x + next.x) * 0.5, (r1[i].y + next.y) * 0.5); + if (!PointOnBoundary(midpoint, r2)) + return Epsilon.pointInsideRegion(midpoint, r2); + } + return false; + } + + private static bool PointOnBoundary(Point point, Region region) + { + for (int i = 0; i < region.Count; i++) + { + var a = region[i]; + var b = region[(i + 1) % region.Count]; + if (Epsilon.pointsSame(point, a) || + (Epsilon.pointsCollinear(a, b, point) && Epsilon.pointBetween(point, a, b))) + return true; + } + return false; } // calculate inside hierarchy @@ -187,4 +202,4 @@ private static Region getInterior(MyNode node, List polygons) } } -#endif \ No newline at end of file +#endif diff --git a/Scripts/ShapeEditor/Decomposition/PolyBoolCS/SingularRegionSplitter.cs b/Scripts/ShapeEditor/Decomposition/PolyBoolCS/SingularRegionSplitter.cs new file mode 100644 index 0000000..dd5d98e --- /dev/null +++ b/Scripts/ShapeEditor/Decomposition/PolyBoolCS/SingularRegionSplitter.cs @@ -0,0 +1,77 @@ +#if UNITY_EDITOR +using System.Collections.Generic; + +namespace AeternumGames.ShapeEditor.PolyBoolCS +{ + internal static class SingularRegionSplitter + { + internal static List Split(List regions) + { + var result = new List(); + foreach (var region in regions) + { + var boundary = InsertContacts(region); + var path = new PointList(); + for (int i = 0; i <= boundary.Count && boundary.Count > 0; i++) + { + var point = boundary[i % boundary.Count]; + var previous = FindPoint(path, point); + if (previous < 0) + { + path.Add(point); + continue; + } + + var loop = new PointList(); + for (int j = previous; j < path.Count; j++) + loop.Add(path[j]); + if (loop.Count >= 3) + result.Add(loop); + path.RemoveRange(previous + 1, path.Count - previous - 1); + } + } + return result; + } + + private static PointList InsertContacts(PointList region) + { + var boundary = new PointList(); + for (int i = 0; i < region.Count; i++) + { + var left = region[i]; + var right = region[(i + 1) % region.Count]; + if (Epsilon.pointsSame(left, right)) + continue; + boundary.Add(left); + var contacts = new PointList(); + for (int j = 0; j < region.Count; j++) + { + var candidate = region[j]; + if (Epsilon.pointsCollinear(left, right, candidate) && + Epsilon.pointBetween(candidate, left, right) && + FindPoint(contacts, candidate) < 0) + contacts.Add(candidate); + } + contacts.Sort((a, b) => DistanceSquared(left, a).CompareTo(DistanceSquared(left, b))); + boundary.AddRange(contacts); + } + return boundary; + } + + private static int FindPoint(PointList points, Point candidate) + { + for (int i = 0; i < points.Count; i++) + if (Epsilon.pointsSame(points[i], candidate)) + return i; + return -1; + } + + private static double DistanceSquared(Point a, Point b) + { + var x = a.x - b.x; + var y = a.y - b.y; + return x * x + y * y; + } + } +} +#endif diff --git a/Scripts/ShapeEditor/Decomposition/PolyBoolCS/SingularRegionSplitter.cs.meta b/Scripts/ShapeEditor/Decomposition/PolyBoolCS/SingularRegionSplitter.cs.meta new file mode 100644 index 0000000..17e4955 --- /dev/null +++ b/Scripts/ShapeEditor/Decomposition/PolyBoolCS/SingularRegionSplitter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 58193ab09f9eeb04eae9a96da97ec40b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests~/Fixtures/Crash.s2d b/Tests~/Fixtures/Crash.s2d new file mode 100644 index 0000000..c7c532d --- /dev/null +++ b/Tests~/Fixtures/Crash.s2d @@ -0,0 +1 @@ +{"version":2,"shapes":[{"segments":[{"_position":{"x":-0.5,"y":-0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.0,"y":-0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-0.5,"y":0.0},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":0,"symmetryAxes":0},{"segments":[{"_position":{"x":0.0,"y":-0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.5,"y":-0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.5,"y":0.0},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":0,"symmetryAxes":0},{"segments":[{"_position":{"x":0.5,"y":0.0},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.5,"y":0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.0,"y":0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":0,"symmetryAxes":0},{"segments":[{"_position":{"x":-0.5,"y":0.0},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.0,"y":0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-0.5,"y":0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":0,"symmetryAxes":0}],"globalPivot":{"_position":{"x":0.0,"y":0.0}}} \ No newline at end of file diff --git a/Tests~/Fixtures/Crash2.s2d b/Tests~/Fixtures/Crash2.s2d new file mode 100644 index 0000000..7e697f4 --- /dev/null +++ b/Tests~/Fixtures/Crash2.s2d @@ -0,0 +1 @@ +{"version":2,"shapes":[{"segments":[{"_position":{"x":-0.5,"y":-0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.0,"y":-0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-0.5,"y":0.0},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":0,"symmetryAxes":0},{"segments":[{"_position":{"x":0.0,"y":-0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.5,"y":-0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.5,"y":0.0},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":0,"symmetryAxes":0},{"segments":[{"_position":{"x":0.5,"y":0.0},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.5,"y":0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.0,"y":0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":0,"symmetryAxes":0},{"segments":[{"_position":{"x":-0.5,"y":0.0},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.0,"y":0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-0.5,"y":0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":0,"symmetryAxes":0},{"segments":[{"_position":{"x":0.75,"y":0.25},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":1.125,"y":0.75},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":1.25,"y":0.25},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.75,"y":0.625},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":0,"symmetryAxes":0},{"segments":[{"_position":{"x":0.5,"y":-1.75},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":1.5,"y":-1.75},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":1.5,"y":-0.75},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.5,"y":-0.75},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":0,"symmetryAxes":0},{"segments":[{"_position":{"x":0.8749999403953552,"y":-1.375},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":1.125,"y":-1.375},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":1.125,"y":-1.125},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.8749999403953552,"y":-1.125},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":1,"symmetryAxes":0}],"globalPivot":{"_position":{"x":0.0,"y":0.0}}} \ No newline at end of file diff --git a/Tests~/Fixtures/ExtrudeFail.s2d b/Tests~/Fixtures/ExtrudeFail.s2d new file mode 100644 index 0000000..bb213f3 --- /dev/null +++ b/Tests~/Fixtures/ExtrudeFail.s2d @@ -0,0 +1 @@ +{"version":2,"shapes":[{"segments":[{"_position":{"x":-0.25,"y":0.25},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-0.625,"y":-0.75},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.0,"y":0.0},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-0.1499999761581421,"y":-0.2999999523162842},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.0,"y":-0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.0,"y":0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-1.0,"y":0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":0,"symmetryAxes":1}],"globalPivot":{"_position":{"x":0.0,"y":0.0}}} \ No newline at end of file diff --git a/Tests~/Fixtures/PolygonFail.s2d b/Tests~/Fixtures/PolygonFail.s2d new file mode 100644 index 0000000..355dc2a --- /dev/null +++ b/Tests~/Fixtures/PolygonFail.s2d @@ -0,0 +1 @@ +{"version":2,"shapes":[{"segments":[{"_position":{"x":-1.125,"y":-0.25},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-1.0,"y":-0.5},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":0.0,"y":-1.125},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-0.25,"y":-0.875},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-0.125,"y":-0.625},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-0.5,"y":-0.375},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-0.375,"y":-0.125},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}},{"_position":{"x":-1.0,"y":0.0},"generator":{"bezierDetail":8,"bezierGridSnapSize":0.0,"bezierPivot1":{"_position":{"x":0.0,"y":0.0}},"bezierPivot2":{"_position":{"x":0.0,"y":0.0}},"repeatSegments":2,"repeatTimes":4,"sineDetail":64,"sineFrequency":-3.5,"sineGridSnapSize":0.0,"sinePivot1":{"_position":{"x":0.0,"y":0.0}},"type":0}}],"booleanOperator":0,"symmetryAxes":3}],"globalPivot":{"_position":{"x":0.0,"y":0.0}}} \ No newline at end of file diff --git a/Tests~/README.md b/Tests~/README.md new file mode 100644 index 0000000..723ec2e --- /dev/null +++ b/Tests~/README.md @@ -0,0 +1,23 @@ +# Point-contact region regressions + +The standalone Unity Editor harness exercises the production `Project.GenerateConvexPolygons` and `SegmentListToConvexPolygonMesh` paths. It checks positive convex output, repeated vertices, finite coordinates, signed filled area for synthetic cases, Unity error logs, and an independent 21 × 21 point grid against the input contours. Owner fixtures use their original shape contours and boolean operators as the grid oracle. + +The four `.s2d` fixtures are the owner's original [issue #17 examples](https://github.com/Henry00IS/ShapeEditor/files/9568260/S2D.Projects.Bad.zip). They are initialized with `Project.Validate()`, matching the production importer, and tested with both `useHoles` settings. Fixtures remain unmodified. The repository's MIT license is preserved. + +To prepare a new project outside this repository: + +```text +python Tests~/prepare_validation.py --project +``` + +Run the installed Unity Editor: + +```text +Unity -batchmode -nographics -quit -projectPath -executeMethod ShapeEditorSingularityTests.Run -logFile +``` + +The harness writes `results.json` in the project root and exits with code 0 when every case passes, or 2 on a test failure. `-resultPath ` can select a different report file. The project includes the package's Mathematics dependency and required built-in modules; no RealtimeCSG installation is needed for this region-conversion regression suite. + +The supplied final receipt records 27/27 passing cases on Windows Unity 2022.3.22f1, with 11,907 filled-point comparisons. `baseline-initialized-results.json` records 16 passing and 11 failing cases on original master `695aa8931981610a77f068a7d68a1c05e91654d5`, after fixing fixture initialization. Baseline results predate the added point-grid checks; those checks strengthen the final suite and are not represented as baseline executions. + +Coverage includes vertex-on-edge contacts, two tips on one edge, multiple lobes, ordinary concavity, separate regions, ordinary and small holes, touching holes, an exterior touching a hole, and tiny touching squares with total area `2e-12`. This validates the tested geometry and APIs; it does not claim exhaustive geometry coverage, older Unity compatibility, or CSG/editor UI interaction testing. diff --git a/Tests~/ShapeEditorSingularityTests.cs b/Tests~/ShapeEditorSingularityTests.cs new file mode 100644 index 0000000..698cd9d --- /dev/null +++ b/Tests~/ShapeEditorSingularityTests.cs @@ -0,0 +1,169 @@ +#if UNITY_EDITOR +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using AeternumGames.ShapeEditor; +using AeternumGames.ShapeEditor.PolyBoolCS; +using UnityEditor; +using UnityEngine; +using ShapePolygon = AeternumGames.ShapeEditor.Polygon; +using BoolPolygon = AeternumGames.ShapeEditor.PolyBoolCS.Polygon; + +public static class ShapeEditorSingularityTests +{ + [Serializable] public class Result { public string name; public bool passed; public string detail; } + [Serializable] public class Report { public string unity; public int passed; public int failed; public List tests = new List(); } + private static readonly MethodInfo Decompose = typeof(Project).GetMethod("SegmentListToConvexPolygonMesh", BindingFlags.Instance | BindingFlags.NonPublic); + private static int errors; + + public static void Run() + { + var report = new Report { unity = Application.unityVersion }; + Application.logMessageReceived += CountErrors; + Case(report, "two-squares-one-vertex", () => Verify(new[] { R(0,0, 1,0, 1,1, 0,1, 0,0, -1,0, -1,-1, 0,-1) }, 2, false)); + Case(report, "vertex-on-edge-triangle", () => Verify(new[] { R(0,0, 2,0, 2,2, 0,2), R(1,0, 0.5,-1, 1.5,-1) }, 4.5, false)); + Case(report, "two-tips-on-one-edge", () => Verify(new[] { R(0,0, 4,0, 4,2, 0,2), R(1,0, 0.5,-1, 1.5,-1), R(3,0, 2.5,-1, 3.5,-1) }, 9, false)); + Case(report, "ordinary-concave", () => Verify(new[] { R(0,0, 3,0, 3,1, 1,1, 1,3, 0,3) }, 5, false)); + Case(report, "small-square", () => Verify(new[] { R(0,0, 0.000001,0, 0.000001,0.000001, 0,0.000001) }, 1e-12, false)); + Case(report, "small-hole", () => Verify(new[] { R(0,0, 1,0, 1,1, 0,1), R(0.4,0.4, 0.4,0.405, 0.405,0.405, 0.405,0.4) }, 1 - 0.000025, true)); + Case(report, "ordinary-hole", () => Verify(new[] { R(0,0, 4,0, 4,4, 0,4), R(1,1, 1,3, 3,3, 3,1) }, 12, true)); + Case(report, "point-contact-with-hole", () => Verify(new[] { R(0,0, 4,0, 4,4, 0,4), R(1,1, 1,3, 3,3, 3,1), R(4,2, 5,1, 5,3) }, 13, true)); + foreach (var holes in new[] { false, true }) + { + Case(report, "touching-square-holes-" + holes, () => Verify(new[] { R(0,0, 10,0, 10,10, 0,10), R(2,2, 2,4, 4,4, 4,2), R(4,4, 4,6, 6,6, 6,4) }, 92, holes)); + Case(report, "exterior-touching-hole-" + holes, () => Verify(new[] { R(0,0, 10,0, 10,10, 0,10), R(5,10, 7,7, 5,4, 3,7) }, 88, holes)); + Case(report, "three-lobes-at-one-point-" + holes, () => Verify(new[] { R(0,0, 2,0, 1,1), R(0,0, -1,1, -2,0), R(0,0, -1,-1, 1,-1) }, 3, holes)); + Case(report, "three-diagonal-squares-" + holes, () => Verify(new[] { R(0,0, 1,0, 1,1, 0,1), R(1,1, 2,1, 2,2, 1,2), R(2,2, 3,2, 3,3, 2,3) }, 3, holes)); + Case(report, "small-touching-squares-" + holes, () => Verify(new[] { R(0,0, 0.000001,0, 0.000001,0.000001, 0,0.000001), R(0,0, -0.000001,0, -0.000001,-0.000001, 0,-0.000001) }, 2e-12, holes)); + } + Case(report, "separate-polygons", () => Verify(new[] { R(0,0, 1,0, 1,1, 0,1), R(2,0, 3,0, 3,1, 2,1) }, 2, false)); + foreach (var file in Directory.GetFiles(Path.Combine(Application.dataPath, "OwnerFixtures"), "*.s2d")) + { + var name = Path.GetFileName(file); + foreach (var holes in new[] { false, true }) + Case(report, "owner-" + name + "-holes-" + holes, () => { + var project = JsonUtility.FromJson(File.ReadAllText(file)); + project.Validate(); + var mesh = project.GenerateConvexPolygons(holes); + ValidateMesh(mesh); + VerifyOwnerCoverage(project, mesh); + if (errors != 0) throw new Exception("Unity error logs: " + errors); + }); + } + Application.logMessageReceived -= CountErrors; + var args = Environment.GetCommandLineArgs(); + var target = Path.Combine(Application.dataPath, "../results.json"); + for (int i = 0; i + 1 < args.Length; i++) if (args[i] == "-resultPath") target = args[i + 1]; + File.WriteAllText(target, JsonUtility.ToJson(report, true)); + EditorApplication.Exit(report.failed == 0 ? 0 : 2); + } + + private static void CountErrors(string message, string stack, LogType type) { if (type == LogType.Error || type == LogType.Assert || type == LogType.Exception) errors++; } + private static void Case(Report report, string name, Action action) + { + errors = 0; + try { action(); report.passed++; report.tests.Add(new Result { name = name, passed = true, detail = "Passed in Unity Editor" }); } + catch (Exception e) { report.failed++; report.tests.Add(new Result { name = name, passed = false, detail = (e.InnerException ?? e).Message }); } + } + private static PointList R(params double[] xy) + { + var result = new PointList(); + for (int i = 0; i < xy.Length; i += 2) result.Add(new Point(xy[i], xy[i+1])); + return result; + } + private static void Verify(PointList[] regions, double area, bool holes) + { + var polyBool = new PolyBool(); + var poly = new BoolPolygon { regions = new List(regions) }; + var mesh = (PolygonMesh)Decompose.Invoke(new Project(), new object[] { polyBool, polyBool.segments(poly), holes }); + ValidateMesh(mesh); + double actual = 0; + foreach (var p in mesh) actual += Math.Abs(p.GetSignedArea2D()) * (p.booleanOperator == PolygonBooleanOperator.Difference ? -1 : 1); + var tolerance = Math.Max(Math.Abs(area) * 0.000002, 1e-17); + if (Math.Abs(actual - area) > tolerance) throw new Exception("Area " + actual.ToString("R") + "; expected " + area.ToString("R")); + VerifyCoverage(regions, mesh); + if (errors != 0) throw new Exception("Unity error logs: " + errors); + } + private static void ValidateMesh(PolygonMesh mesh) + { + if (mesh.Count == 0) throw new Exception("No polygons returned"); + foreach (var p in mesh) + { + if (p.Count < 3 || p.GetSignedArea2D() <= 0) throw new Exception("Degenerate or reversed output"); + for (int i = 0; i < p.Count; i++) + { + if (float.IsNaN(p[i].x) || float.IsInfinity(p[i].x) || float.IsNaN(p[i].y) || float.IsInfinity(p[i].y)) throw new Exception("Nonfinite output"); + for (int j = i + 1; j < p.Count; j++) + if (p[i].x == p[j].x && p[i].y == p[j].y) throw new Exception("Repeated nonadjacent vertex"); + var a = p[i]; var b = p.NextVertex(i); var c = p.NextVertex(p.NextIndex(i)); + double cross = (double)(b.x-a.x)*(c.y-b.y) - (double)(b.y-a.y)*(c.x-b.x); + if (cross < -1e-12) throw new Exception("Nonconvex output"); + } + } + } + + private static void VerifyCoverage(PointList[] regions, PolygonMesh mesh) + { + SampleCoverage(regions, mesh, (x, y) => { + var inside = false; + foreach (var region in regions) if (Inside(region, x, y)) inside = !inside; + return inside; + }); + } + + private static void VerifyOwnerCoverage(Project project, PolygonMesh mesh) + { + var all = new List(); + var byShape = new List>(); + foreach (var shape in project.shapes) + { + var regions = new List(); + foreach (var polygon in shape.GenerateConcavePolygons(true)) + { + var region = new PointList(); + foreach (var v in polygon) region.Add(new Point(v.x, v.y)); + regions.Add(region); all.Add(region); + } + byShape.Add(regions); + } + SampleCoverage(all.ToArray(), mesh, (x, y) => { + var inside = false; + for (int i = 0; i < project.shapes.Count; i++) + foreach (var region in byShape[i]) + if (Inside(region, x, y)) inside = project.shapes[i].booleanOperator == PolygonBooleanOperator.Union; + return inside; + }); + } + + private static void SampleCoverage(PointList[] regions, PolygonMesh mesh, Func expected) + { + double minX = double.PositiveInfinity, minY = minX, maxX = double.NegativeInfinity, maxY = maxX; + foreach (var r in regions) foreach (var p in r) { minX = Math.Min(minX, p.x); minY = Math.Min(minY, p.y); maxX = Math.Max(maxX, p.x); maxY = Math.Max(maxY, p.y); } + for (int xi = 0; xi < 21; xi++) for (int yi = 0; yi < 21; yi++) + { + var x = minX + (maxX-minX) * (xi + 0.37) / 21; + var y = minY + (maxY-minY) * (yi + 0.61) / 21; + bool additive = false, subtractive = false; + var position = new Vector3((float)x, (float)y, 0); + foreach (var polygon in mesh) + if (polygon.ContainsPoint2D(ref position) >= 0) + { + if (polygon.booleanOperator == PolygonBooleanOperator.Difference) subtractive = true; + else additive = true; + } + if (expected(x, y) != (additive && !subtractive)) throw new Exception("Filled-point mismatch at " + x.ToString("R") + ", " + y.ToString("R")); + } + } + + private static bool Inside(PointList region, double x, double y) + { + bool inside = false; + for (int i = 0, j = region.Count - 1; i < region.Count; j = i++) + if ((region[i].y > y) != (region[j].y > y) && + x < (region[j].x-region[i].x)*(y-region[i].y)/(region[j].y-region[i].y) + region[i].x) + inside = !inside; + return inside; + } +} +#endif diff --git a/Tests~/baseline-initialized-results.json b/Tests~/baseline-initialized-results.json new file mode 100644 index 0000000..5427c2f --- /dev/null +++ b/Tests~/baseline-initialized-results.json @@ -0,0 +1,142 @@ +{ + "unity": "2022.3.22f1", + "passed": 16, + "failed": 11, + "tests": [ + { + "name": "two-squares-one-vertex", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "vertex-on-edge-triangle", + "passed": false, + "detail": "Repeated nonadjacent vertex" + }, + { + "name": "two-tips-on-one-edge", + "passed": false, + "detail": "Repeated nonadjacent vertex" + }, + { + "name": "ordinary-concave", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "small-square", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "small-hole", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "ordinary-hole", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "point-contact-with-hole", + "passed": false, + "detail": "Area 5; expected 13" + }, + { + "name": "touching-square-holes-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "exterior-touching-hole-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "three-lobes-at-one-point-False", + "passed": false, + "detail": "Area 2; expected 3" + }, + { + "name": "three-diagonal-squares-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "small-touching-squares-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "touching-square-holes-True", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "exterior-touching-hole-True", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "three-lobes-at-one-point-True", + "passed": false, + "detail": "Area 2; expected 3" + }, + { + "name": "three-diagonal-squares-True", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "small-touching-squares-True", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "separate-polygons", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "owner-Crash.s2d-holes-False", + "passed": false, + "detail": "Nonconvex output" + }, + { + "name": "owner-Crash.s2d-holes-True", + "passed": false, + "detail": "Nonconvex output" + }, + { + "name": "owner-Crash2.s2d-holes-False", + "passed": false, + "detail": "Nonconvex output" + }, + { + "name": "owner-Crash2.s2d-holes-True", + "passed": false, + "detail": "Nonconvex output" + }, + { + "name": "owner-ExtrudeFail.s2d-holes-False", + "passed": false, + "detail": "Repeated nonadjacent vertex" + }, + { + "name": "owner-ExtrudeFail.s2d-holes-True", + "passed": false, + "detail": "Repeated nonadjacent vertex" + }, + { + "name": "owner-PolygonFail.s2d-holes-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "owner-PolygonFail.s2d-holes-True", + "passed": true, + "detail": "Passed in Unity Editor" + } + ] +} \ No newline at end of file diff --git a/Tests~/final-results.json b/Tests~/final-results.json new file mode 100644 index 0000000..e945cae --- /dev/null +++ b/Tests~/final-results.json @@ -0,0 +1,142 @@ +{ + "unity": "2022.3.22f1", + "passed": 27, + "failed": 0, + "tests": [ + { + "name": "two-squares-one-vertex", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "vertex-on-edge-triangle", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "two-tips-on-one-edge", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "ordinary-concave", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "small-square", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "small-hole", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "ordinary-hole", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "point-contact-with-hole", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "touching-square-holes-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "exterior-touching-hole-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "three-lobes-at-one-point-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "three-diagonal-squares-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "small-touching-squares-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "touching-square-holes-True", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "exterior-touching-hole-True", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "three-lobes-at-one-point-True", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "three-diagonal-squares-True", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "small-touching-squares-True", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "separate-polygons", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "owner-Crash.s2d-holes-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "owner-Crash.s2d-holes-True", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "owner-Crash2.s2d-holes-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "owner-Crash2.s2d-holes-True", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "owner-ExtrudeFail.s2d-holes-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "owner-ExtrudeFail.s2d-holes-True", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "owner-PolygonFail.s2d-holes-False", + "passed": true, + "detail": "Passed in Unity Editor" + }, + { + "name": "owner-PolygonFail.s2d-holes-True", + "passed": true, + "detail": "Passed in Unity Editor" + } + ] +} \ No newline at end of file diff --git a/Tests~/prepare_validation.py b/Tests~/prepare_validation.py new file mode 100644 index 0000000..56d5a96 --- /dev/null +++ b/Tests~/prepare_validation.py @@ -0,0 +1,32 @@ +from pathlib import Path +import argparse +import json +import os +import shutil + +parser = argparse.ArgumentParser() +parser.add_argument('--project', type=Path) +parser.add_argument('--unity-version', default='2022.3.22f1') +args = parser.parse_args() +tests = Path(__file__).resolve().parent +repo = tests.parent +project = (args.project or repo.parent / (repo.name + '-singularity-validation')).resolve() +if project == repo or repo in project.parents: + raise SystemExit('Use a new validation directory outside the source repository') +relative_source = os.path.relpath(repo, project / 'Packages').replace('\\', '/') +project.mkdir(parents=True, exist_ok=False) +for sub in ('Assets/Editor', 'Assets/OwnerFixtures', 'Packages', 'ProjectSettings'): + (project / sub).mkdir(parents=True, exist_ok=True) +(project / 'Packages/manifest.json').write_text(json.dumps({'dependencies': { + 'com.aeternumgames.shapeeditor': 'file:' + relative_source, + 'com.unity.mathematics': '1.1.0', + 'com.unity.modules.imgui': '1.0.0', + 'com.unity.modules.jsonserialize': '1.0.0', + 'com.unity.modules.physics': '1.0.0', + 'com.unity.modules.imageconversion': '1.0.0' +}}, indent=2), encoding='utf-8') +(project / 'ProjectSettings/ProjectVersion.txt').write_text('m_EditorVersion: ' + args.unity_version + '\n', encoding='utf-8') +shutil.copyfile(tests / 'ShapeEditorSingularityTests.cs', project / 'Assets/Editor/ShapeEditorSingularityTests.cs') +for fixture in (tests / 'Fixtures').glob('*.s2d'): + shutil.copyfile(fixture, project / 'Assets/OwnerFixtures' / fixture.name) +print(project)