public void TestFuzzedEdgeCases(Vector2[] clipVertices, Vector2[] subjectVertices) { var clipPolygon = new SimpleConvexPolygon(clipVertices); var subjectPolygon = new SimpleConvexPolygon(subjectVertices); clip(clipPolygon, subjectPolygon); }
private static Vector2[] clip(SimpleConvexPolygon poly1, SimpleConvexPolygon poly2) { var clipper = new ConvexPolygonClipper <SimpleConvexPolygon, SimpleConvexPolygon>(ref poly1, ref poly2); Span <Vector2> buffer = stackalloc Vector2[clipper.GetClipBufferSize()]; return(clipper.Clip(buffer).ToArray()); }
public void RunTest() { Task[] tasks = new Task[parallelism]; for (int i = 0; i < tasks.Length; i++) { tasks[i] = Task.Factory.StartNew(() => { while (true) { int count1 = getRand(possible_sizes); int count2 = getRand(possible_sizes); HashSet <Vector2> vertices1 = new HashSet <Vector2>(); HashSet <Vector2> vertices2 = new HashSet <Vector2>(); while (vertices1.Count < count1) { vertices1.Add(new Vector2(getRand(possible_values), getRand(possible_values))); } while (vertices2.Count < count2) { vertices2.Add(new Vector2(getRand(possible_values), getRand(possible_values))); } SimpleConvexPolygon poly1 = new SimpleConvexPolygon(vertices1.ToArray()); SimpleConvexPolygon poly2 = new SimpleConvexPolygon(vertices2.ToArray()); try { clip(poly1, poly2); } catch (Exception ex) { Assert.Fail($"Failed.\nPoly1: {poly1}\nPoly2: {poly2}\n\nException: {ex}"); return; } try { clip(poly2, poly1); } catch (Exception ex) { Assert.Fail($"Failed.\nPoly1: {poly2}\nPoly2: {poly1}\n\nException: {ex}"); return; } } }, TaskCreationOptions.LongRunning); } Task.WaitAny(tasks); }
public void TestClipFullyContained(Vector2[] subjectVertices, Vector2[] clipVertices) { var clipPolygon = new SimpleConvexPolygon(clipVertices); var subjectPolygon = new SimpleConvexPolygon(subjectVertices); assertPolygonEquals(clipPolygon, new SimpleConvexPolygon(clip(clipPolygon, subjectPolygon).ToArray()), false); Array.Reverse(clipVertices); Array.Reverse(subjectVertices); assertPolygonEquals(clipPolygon, new SimpleConvexPolygon(clip(clipPolygon, subjectPolygon).ToArray()), true); }
public void TestGeneralClipping(Vector2[] clipVertices, Vector2[] subjectVertices, Vector2[] resultingVertices) { var clipPolygon = new SimpleConvexPolygon(clipVertices); var subjectPolygon = new SimpleConvexPolygon(subjectVertices); assertPolygonEquals(new SimpleConvexPolygon(resultingVertices), new SimpleConvexPolygon(clip(clipPolygon, subjectPolygon).ToArray()), false); Array.Reverse(clipVertices); Array.Reverse(subjectVertices); // The expected polygon is never reversed assertPolygonEquals(new SimpleConvexPolygon(resultingVertices), new SimpleConvexPolygon(clip(clipPolygon, subjectPolygon).ToArray()), false); }
public void TestExternalPolygon(Vector2[] polygonVertices1, Vector2[] polygonVertices2) { var poly1 = new SimpleConvexPolygon(polygonVertices1); var poly2 = new SimpleConvexPolygon(polygonVertices2); Assert.That(clip(poly1, poly2).Length, Is.Zero); Assert.That(clip(poly2, poly1).Length, Is.Zero); Array.Reverse(polygonVertices1); Array.Reverse(polygonVertices2); Assert.That(clip(poly1, poly2).Length, Is.Zero); Assert.That(clip(poly2, poly1).Length, Is.Zero); }
private Span <Vector2> clip(SimpleConvexPolygon clipPolygon, SimpleConvexPolygon subjectPolygon) => new ConvexPolygonClipper <SimpleConvexPolygon, SimpleConvexPolygon>(ref clipPolygon, ref subjectPolygon).Clip();