public void MonotoneSubdivisionAlgorithmConstructorTest()
        {
            // predefined polygon (which is extended)

            MonotoneSubdivisionAlgorithm algorithm = new MonotoneSubdivisionAlgorithm(_shell);

            Assert.AreEqual(_shell.Count + 1, algorithm.Shell.Count);
            Assert.IsTrue(_shell.SequenceEqual(algorithm.Shell.Take(_shell.Count)));
            Assert.AreEqual(algorithm.Shell[0], algorithm.Shell[algorithm.Shell.Count - 1]);

            // random polygon

            IBasicPolygon polygon = RandomPolygonGenerator.CreateRandomPolygon(100, new Coordinate(10, 10), new Coordinate(50, 50));

            algorithm = new MonotoneSubdivisionAlgorithm(polygon.Shell.Coordinates);

            Assert.IsTrue(polygon.Shell.SequenceEqual(algorithm.Shell));


            // exceptions

            Assert.IsTrue(polygon.Shell.SequenceEqual(algorithm.Shell));

            Assert.Throws <ArgumentNullException>(() => algorithm = new MonotoneSubdivisionAlgorithm(null));
        }
Exemplo n.º 2
0
        public void MonotoneSubdivisionAlgorithmComputeTest()
        {
            MonotoneSubdivisionAlgorithm algorithm = new MonotoneSubdivisionAlgorithm(this.source, null);

            algorithm.Compute();

            algorithm.Result.Count.ShouldBe(4);
            algorithm.Result[0].ShouldBe(new[] { new Coordinate(10, 10), new Coordinate(5, 20), new Coordinate(5, -10) });
            algorithm.Result[1].ShouldBe(new[] { new Coordinate(0, 0), new Coordinate(-10, 5), new Coordinate(10, 10) });
            algorithm.Result[2].ShouldBe(new[] { new Coordinate(0, 0), new Coordinate(10, 10), new Coordinate(5, -10) });
            algorithm.Result[3].ShouldBe(new[] { new Coordinate(0, 0), new Coordinate(5, -10), new Coordinate(-10, -10) });
        }
Exemplo n.º 3
0
        public void MonotoneSubdivisionTriangulateTest()
        {
            for (Int32 polygonNumber = 1; polygonNumber < 10; polygonNumber++)
            {
                IBasicPolygon polygon = RandomPolygonGenerator.CreateRandomPolygon(10 * polygonNumber, new Coordinate(10, 10), new Coordinate(50, 50));
                IReadOnlyList <Coordinate[]> triangles = MonotoneSubdivisionAlgorithm.Triangulate(polygon.Shell);

                triangles.Count.ShouldBe(polygon.Shell.Count - 3);

                foreach (Coordinate[] triangle in triangles)
                {
                    triangle.Length.ShouldBe(3);
                    triangle.ShouldBeSubsetOf(polygon.Shell);
                }
            }
        }
        public void MonotoneSubdivisionAlgorithmComputeTest()
        {
            MonotoneSubdivisionAlgorithm algorithm = new MonotoneSubdivisionAlgorithm(_shell);

            algorithm.Compute();

            Assert.AreEqual(4, algorithm.Result.Count);
            Assert.IsTrue(algorithm.Result[0].SequenceEqual(new List <Coordinate> {
                new Coordinate(10, 10), new Coordinate(5, 20), new Coordinate(5, -10)
            }));
            Assert.IsTrue(algorithm.Result[1].SequenceEqual(new List <Coordinate> {
                new Coordinate(0, 0), new Coordinate(-10, 5), new Coordinate(10, 10)
            }));
            Assert.IsTrue(algorithm.Result[2].SequenceEqual(new List <Coordinate> {
                new Coordinate(0, 0), new Coordinate(10, 10), new Coordinate(5, -10)
            }));
            Assert.IsTrue(algorithm.Result[3].SequenceEqual(new List <Coordinate> {
                new Coordinate(0, 0), new Coordinate(5, -10), new Coordinate(-10, -10)
            }));
        }
        public void MonotoneSubdivisionTriangulateTest()
        {
            for (Int32 polygonNumber = 1; polygonNumber < 10; polygonNumber++)
            {
                IBasicPolygon        polygon   = RandomPolygonGenerator.CreateRandomPolygon(10 * polygonNumber, new Coordinate(10, 10), new Coordinate(50, 50));
                IList <Coordinate[]> triangles = MonotoneSubdivisionAlgorithm.Triangulate(polygon.Shell.Coordinates);

                Assert.AreEqual(polygon.Shell.Count - 3, triangles.Count);

                foreach (Coordinate[] triangle in triangles)
                {
                    Assert.AreEqual(3, triangle.Length);

                    foreach (Coordinate coordinate in triangle)
                    {
                        Assert.IsTrue(polygon.Shell.Contains(coordinate));
                    }
                }
            }
        }
Exemplo n.º 6
0
        public void MonotoneSubdivisionAlgorithmConstructorTest()
        {
            // predefined polygon (which is extended)

            MonotoneSubdivisionAlgorithm algorithm = new MonotoneSubdivisionAlgorithm(this.source, null);

            algorithm.Source.Count().ShouldBe(this.source.Count + 1);
            algorithm.Source.Take(this.source.Count).ShouldBe(this.source);
            algorithm.Source.Last().ShouldBe(this.source[0]);

            // random polygon

            IBasicPolygon polygon = RandomPolygonGenerator.CreateRandomPolygon(100, new Coordinate(10, 10), new Coordinate(50, 50));

            algorithm = new MonotoneSubdivisionAlgorithm(polygon.Shell, null);

            algorithm.Source.ShouldBeSameAs(polygon.Shell);

            // exceptions

            Should.Throw <ArgumentNullException>(() => algorithm = new MonotoneSubdivisionAlgorithm(null, null));
        }