/// <summary>
        /// Creates the result of the overlay operation.
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <param name="otherGeometry">The other geometry.</param>
        /// <param name="predicate">The overlay predicate.</param>
        /// <returns>The result of the overlay.</returns>
        private IGeometry CreateResult(IGeometry geometry, IGeometry otherGeometry, Func <IFace, Boolean> predicate)
        {
            // merge the geometries into a single graph
            HalfedgeGraph graph = new HalfedgeGraph(new HalfedgeGraph.FixedIdentifierProvider(1));

            graph.MergeGeometry(geometry);
            _aIdentifiers = new HashSet <Int32>(graph.Vertices.SelectMany(v => v.Identifiers));

            HalfedgeGraph otherGraph = new HalfedgeGraph(new HalfedgeGraph.FixedIdentifierProvider(2));

            otherGraph.MergeGeometry(otherGeometry);
            _bIdentifiers = new HashSet <Int32>(otherGraph.Vertices.SelectMany(v => v.Identifiers));

            graph.MergeGraph(otherGraph);

            // query the results
            IGeometryFactory factory = _geometryFactory ?? geometry.Factory;
            List <IPolygon>  result  = graph.Faces.Where(predicate).Select(face => face.ToGeometry(factory)).ToList();

            if (result.Count == 0)
            {
                return(null);
            }
            if (result.Count == 1)
            {
                return(result[0]);
            }

            return(factory.CreateGeometryCollection(result));
        }
예제 #2
0
        public void HalfedgeGraphMergeGraphTest()
        {
            // graph A: merging two adjacent and one intersecting polygons
            _graph.MergePolygon(_factory.CreatePolygon(
                                    _factory.CreatePoint(0, 0),
                                    _factory.CreatePoint(8, 0),
                                    _factory.CreatePoint(8, 8),
                                    _factory.CreatePoint(0, 8)));
            _graph.MergePolygon(_factory.CreatePolygon(
                                    _factory.CreatePoint(8, 0),
                                    _factory.CreatePoint(14, 0),
                                    _factory.CreatePoint(8, 8)));
            _graph.MergePolygon(_factory.CreatePolygon(
                                    _factory.CreatePoint(-4, -6),
                                    _factory.CreatePoint(4, -6),
                                    _factory.CreatePoint(4, 2),
                                    _factory.CreatePoint(-4, 2)));

            _graph.VerifyTopology();
            Assert.AreEqual(4, _graph.Faces.Count());
            Assert.AreEqual(14, _graph.Edges.Count());
            Assert.AreEqual(28, _graph.Halfedges.Count());
            Assert.AreEqual(11, _graph.Vertices.Count());

            // graph B: two intersecting polygons
            HalfedgeGraph graphB = new HalfedgeGraph();

            graphB.MergePolygon(_factory.CreatePolygon(
                                    _factory.CreatePoint(-2, 6),
                                    _factory.CreatePoint(14, 6),
                                    _factory.CreatePoint(4, 14)));
            graphB.MergePolygon(_factory.CreatePolygon(
                                    _factory.CreatePoint(2, 1),
                                    _factory.CreatePoint(6, 1),
                                    _factory.CreatePoint(6, 13),
                                    _factory.CreatePoint(2, 13)));

            graphB.VerifyTopology();
            Assert.AreEqual(7, graphB.Faces.Count());
            Assert.AreEqual(19, graphB.Edges.Count());
            Assert.AreEqual(38, graphB.Halfedges.Count());
            Assert.AreEqual(13, graphB.Vertices.Count());

            // graph merge: numerous intersections
            _graph.MergeGraph(graphB);

            _graph.VerifyTopology();
            Assert.AreEqual(17, _graph.Faces.Count());
            Assert.AreEqual(47, _graph.Edges.Count());
            Assert.AreEqual(94, _graph.Halfedges.Count());
            Assert.AreEqual(31, _graph.Vertices.Count());
        }
예제 #3
0
        /// <summary>
        /// Merges the specified geometries.
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <param name="otherGeometry">The other geometry.</param>
        /// <returns>The halfedge graph containing the geometries.</returns>
        private void Merge(IGeometry geometry, IGeometry otherGeometry)
        {
            _graph = new HalfedgeGraph(new HalfedgeGraph.FixedIdentifierProvider(1));
            _graph.MergeGeometry(geometry);
            _aIdentifiers = new HashSet <Int32>(_graph.Vertices.SelectMany(v => v.Identifiers));

            HalfedgeGraph otherGraph = new HalfedgeGraph(new HalfedgeGraph.FixedIdentifierProvider(2));

            otherGraph.MergeGeometry(otherGeometry);
            _bIdentifiers = new HashSet <Int32>(otherGraph.Vertices.SelectMany(v => v.Identifiers));

            _graph.MergeGraph(otherGraph);
        }
예제 #4
0
 public void TestInitialize()
 {
     _graph = new HalfedgeGraph();
 }