示例#1
0
        public void NewClipperFileBasedTest()
        {
            var testData = LoadTestHelper.LoadFromFile("TestData/tests.txt");

            foreach (var test in testData.Values)
            {
                var clipper = new Clipper.Clipper();

                clipper.AddPath(test.Subjects, PolygonKind.Subject);
                clipper.AddPath(test.Clips, PolygonKind.Clip);

                var solution = new PolygonTree();
                Assert.IsTrue(clipper.Execute(test.ClipOperation, solution, false, test.FillType));

                var path = new PolygonPath(solution.AllPolygons.Select(n => n.Polygon).ToList());

                // TODO: reinclude these tests once test data is verified.
                var ignoreTestNumbers = new[] { 36, 38, 39, 44, 46, 48, 51, 52, 59, 64, 67, 69 };
                if (ignoreTestNumbers.Contains(test.TestNumber))
                {
                    continue;
                }

                Assert.AreEqual(test.Solution.Count, path.Count, $"{test.TestNumber}: {test.Caption}");

                // Match points, THIS IS DESTRUCTIVE TO BOTH THE TEST DATA AND RESULT DATA.
                Assert.IsTrue(AreSame(test, path));

                // If we had an exact match then both solutions should now be empty.
                Assert.AreEqual(0, test.Solution.Count, $"{test.TestNumber}: {test.Caption}");
                Assert.AreEqual(0, path.Count, $"{test.TestNumber}: {test.Caption}");
            }
        }
示例#2
0
        public void OriginalClipperFileBasedTest()
        {
            var testData = LoadTestHelper.LoadFromFile("TestData/tests.txt");

            foreach (var test in testData.Values)
            {
                var subjects = test.Subjects.ToOriginal();
                var clips    = test.Clips.ToOriginal();

                var clipper = new ClipperLib.Clipper();
                clipper.AddPaths(subjects, PolyType.ptSubject, true);
                clipper.AddPaths(clips, PolyType.ptClip, true);

                var originalSolution = new List <List <ClipperLib.IntPoint> >();
                var clipType         = (ClipType)Enum.Parse(typeof(ClipType), $"ct{test.ClipOperation}", true);
                var fillType         = (PolyFillType)Enum.Parse(typeof(PolyFillType), $"pft{test.FillType}", true);
                Assert.IsTrue(clipper.Execute(clipType, originalSolution, fillType));
                Assert.AreEqual(test.Solution.Count, originalSolution.Count, test.Caption);

                var solution = originalSolution.ToNew();

                // TODO: reinclude these tests once test data is verified.
                var ignoreTestNumbers = new[] { 36, 38, 39, 44, 46, 48, 51, 52, 59, 64, 67, 69 };
                if (ignoreTestNumbers.Contains(test.TestNumber))
                {
                    continue;
                }

                Assert.AreEqual(test.Solution.Count, solution.Count, $"{test.TestNumber}: {test.Caption}");

                // Match points, THIS IS DESTRUCTIVE TO BOTH THE TEST DATA AND RESULT DATA.
                Assert.IsTrue(AreSame(test, solution));

                // If we had an exact match then both solutions should now be empty.
                Assert.AreEqual(0, test.Solution.Count, $"{test.TestNumber}: {test.Caption}");
                Assert.AreEqual(0, solution.Count, $"{test.TestNumber}: {test.Caption}");
            }
        }