示例#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
        private void SetTest()
        {
            if (!_testData.ContainsKey(_testNumber))
            {
                return;
            }

            // Get test of interest.
            var test = _testData[_testNumber];

            _testSubject  = test.Subjects.FirstOrDefault();
            _testClip     = test.Clips.FirstOrDefault();
            _testSolution = test.Solution;

            _newClipperSolution = new PolygonPath();

            var clipper = new Clipper.Clipper();

            clipper.AddPath(test.Subjects, PolygonKind.Subject);
            clipper.AddPath(test.Clips, PolygonKind.Clip);
            clipper.Execute(ClipOperation.Union, _newClipperSolution);

            _testBoundary = _testSolution.Any()
                ? BoundaryBuilder
                            .BuildPolygonBoundary(_testSolution.First(), PolygonKind.Subject)
                            .ToList()
                : null;

            _newClipperBoundary = _newClipperSolution.Any()
                ? BoundaryBuilder
                                  .BuildPolygonBoundary(_newClipperSolution.First(), PolygonKind.Subject)
                                  .ToList()
                : null;

            var originalClipperSolution = new List <List <IntPoint> >();
            var originalClipper         = new ClipperLib.Clipper();

            originalClipper.AddPaths(test.Subjects.ToOriginal(), PolyType.ptSubject, true);
            originalClipper.AddPaths(test.Clips.ToOriginal(), PolyType.ptClip, true);
            originalClipper.Execute(ClipType.ctUnion, originalClipperSolution);
            _originalClipperSolution = originalClipperSolution.ToNew();

            _originalClipperBoundary = _originalClipperSolution.Any()
                ? BoundaryBuilder
                                       .BuildPolygonBoundary(_originalClipperSolution.First(), PolygonKind.Subject)
                                       .ToList()
                : null;

            Program.VisualizerForm.ClipperViewControl.Subjects = new[]
            {
                new PolygonViewModel
                {
                    IsOpen      = false,
                    EdgeColor   = Color.LawnGreen,
                    VertexColor = Color.DarkGreen,
                    Items       = _testSubject?.ToVertices()
                }
            };

            Program.VisualizerForm.ClipperViewControl.Clips = new[]
            {
                new PolygonViewModel
                {
                    IsOpen      = false,
                    EdgeColor   = Color.Blue,
                    VertexColor = Color.DarkBlue,
                    Items       = _testClip?.ToVertices()
                }
            };

            _solutionType = SolutionType.Test;
            SetSolution();
            solutionComboBox.SelectedIndex = 0;
        }
示例#3
0
        public static bool SimplifyPolygon <T>(PolygonPath paths, T solution) where T : IClipSolution
        {
            var clipper = new Clipper();

            return(clipper.Execute(ClipOperation.Union, paths, null, solution, true));
        }