Example #1
0
        public void HalfedgeGraphMergeHoleTest()
        {
            // filling polygon hole with two other subject polygons

            IPolygon polygon = _factory.CreatePolygon(
                _factory.CreatePoint(0, 0),
                _factory.CreatePoint(10, 0),
                _factory.CreatePoint(10, 10),
                _factory.CreatePoint(0, 10));

            polygon.AddHole(_factory.CreateLinearRing(
                                _factory.CreatePoint(2, 2),
                                _factory.CreatePoint(2, 8),
                                _factory.CreatePoint(8, 8),
                                _factory.CreatePoint(8, 2)));
            Assert.IsTrue(polygon.IsValid);
            _graph.MergePolygon(polygon);

            _graph.MergePolygon(_factory.CreatePolygon(
                                    _factory.CreatePoint(2, 2),
                                    _factory.CreatePoint(8, 2),
                                    _factory.CreatePoint(8, 8)));
            _graph.MergePolygon(_factory.CreatePolygon(
                                    _factory.CreatePoint(2, 2),
                                    _factory.CreatePoint(8, 8),
                                    _factory.CreatePoint(2, 8)));

            _graph.VerifyTopology();
            Assert.AreEqual(3, _graph.Faces.Count());
            Assert.AreEqual(9, _graph.Edges.Count());
            Assert.AreEqual(18, _graph.Halfedges.Count());
            Assert.AreEqual(8, _graph.Vertices.Count());

            Assert.AreEqual(1, _graph.Faces.Count(face => face.Vertices.Count() == 4 && face.Edges.Count() == 4));
            Assert.AreEqual(2, _graph.Faces.Count(face => face.Vertices.Count() == 3 && face.Edges.Count() == 3));
            Assert.AreEqual(2, _graph.Faces.Sum(face => face.Holes.Count()));


            // a polygon hole containing a polygon with a hole is intersected with another subject polygon

            _graph.Clear();
            polygon = _factory.CreatePolygon(
                _factory.CreatePoint(0, 0),
                _factory.CreatePoint(20, 0),
                _factory.CreatePoint(20, 20),
                _factory.CreatePoint(0, 20));
            polygon.AddHole(_factory.CreateLinearRing(
                                _factory.CreatePoint(5, 5),
                                _factory.CreatePoint(5, 15),
                                _factory.CreatePoint(15, 15),
                                _factory.CreatePoint(15, 5)));
            Assert.IsTrue(polygon.IsValid);
            _graph.MergePolygon(polygon);

            polygon = _factory.CreatePolygon(
                _factory.CreatePoint(5, 5),
                _factory.CreatePoint(15, 5),
                _factory.CreatePoint(15, 15),
                _factory.CreatePoint(5, 15));
            polygon.AddHole(_factory.CreateLinearRing(
                                _factory.CreatePoint(8, 8),
                                _factory.CreatePoint(8, 12),
                                _factory.CreatePoint(12, 12),
                                _factory.CreatePoint(12, 8)));
            Assert.IsTrue(polygon.IsValid);
            _graph.MergePolygon(polygon);

            _graph.VerifyTopology();
            Assert.AreEqual(2, _graph.Faces.Count());
            Assert.AreEqual(12, _graph.Edges.Count());
            Assert.AreEqual(24, _graph.Halfedges.Count());
            Assert.AreEqual(12, _graph.Vertices.Count());
            Assert.AreEqual(2, _graph.Faces.Sum(face => face.Holes.Count()));

            _graph.MergePolygon(_factory.CreatePolygon(
                                    _factory.CreatePoint(9, -5),
                                    _factory.CreatePoint(11, -5),
                                    _factory.CreatePoint(11, 25),
                                    _factory.CreatePoint(9, 25)));

            _graph.VerifyTopology();
            Assert.AreEqual(11, _graph.Faces.Count());
            Assert.AreEqual(40, _graph.Edges.Count());
            Assert.AreEqual(80, _graph.Halfedges.Count());
            Assert.AreEqual(28, _graph.Vertices.Count());
            Assert.AreEqual(0, _graph.Faces.Sum(face => face.Holes.Count()));
        }
 /// <summary>
 /// Add a hole to the polygon.
 /// </summary>
 /// <param name="hole">The hole.</param>
 /// <exception cref="System.ArgumentNullException">hole;The hole is null.</exception>
 /// <exception cref="System.ArgumentException">The reference system of the hole does not match the reference system of the polygon.;hole</exception>
 public void AddHole(ILinearRing hole)
 {
     _polygon.AddHole(hole);
 }