示例#1
0
        public void VertexOuterFaceEdgeVertices()
        {
            var surface  = RectangularQuadGrid.Create(Vector2.right, Vector2.up, Vector3.zero, Quaternion.identity, false, false, new IntVector2(2, 2));
            var topology = TopologyUtility.BuildTopology(surface);

            var vertex = topology.vertices[surface.GetVertexIndex(1, 1)];
            var neighborVertexEdges = vertex.outerEdges.GetEnumerator();

            Assert.True(neighborVertexEdges.MoveNext());
            Assert.AreEqual(surface.GetVertexIndex(0, 0), neighborVertexEdges.Current.vertex.index);
            Assert.True(neighborVertexEdges.MoveNext());
            Assert.AreEqual(surface.GetVertexIndex(0, 1), neighborVertexEdges.Current.vertex.index);
            Assert.True(neighborVertexEdges.MoveNext());
            Assert.AreEqual(surface.GetVertexIndex(0, 2), neighborVertexEdges.Current.vertex.index);
            Assert.True(neighborVertexEdges.MoveNext());
            Assert.AreEqual(surface.GetVertexIndex(1, 2), neighborVertexEdges.Current.vertex.index);
            Assert.True(neighborVertexEdges.MoveNext());
            Assert.AreEqual(surface.GetVertexIndex(2, 2), neighborVertexEdges.Current.vertex.index);
            Assert.True(neighborVertexEdges.MoveNext());
            Assert.AreEqual(surface.GetVertexIndex(2, 1), neighborVertexEdges.Current.vertex.index);
            Assert.True(neighborVertexEdges.MoveNext());
            Assert.AreEqual(surface.GetVertexIndex(2, 0), neighborVertexEdges.Current.vertex.index);
            Assert.True(neighborVertexEdges.MoveNext());
            Assert.AreEqual(surface.GetVertexIndex(1, 0), neighborVertexEdges.Current.vertex.index);
            Assert.False(neighborVertexEdges.MoveNext());
        }
示例#2
0
        public void SpinEdgeBackwardThrowsOnInteriorVerticesWithTwoNeighbors()
        {
            var indexer = new ManualFaceNeighborIndexer(5, 12, 2, 1);

            indexer.AddFace(0, 1, 2, 4);
            indexer.AddFace(2, 3, 0, 4);
            var topology = TopologyUtility.BuildTopology(indexer);

            Assert.Throws <InvalidOperationException>(() => { topology.SpinEdgeBackward(topology.vertices[4].firstEdge); });
            Assert.Throws <InvalidOperationException>(() => { topology.SpinEdgeBackward(topology.vertices[4].firstEdge.next); });
        }
示例#3
0
        public void SpinEdgeBackwardThrowsOnBoundaryVerticesWithTwoNeighbors()
        {
            var indexer = new ManualFaceNeighborIndexer(3, 6, 1, 1);

            indexer.AddFace(0, 1, 2);
            var topology = TopologyUtility.BuildTopology(indexer);

            foreach (var edge in topology.vertexEdges)
            {
                Assert.Throws <InvalidOperationException>(() => { topology.SpinEdgeBackward(edge); });
            }
        }
示例#4
0
        public void SpinEdgeBetweenSquaresBackward()
        {
            // 0---1     0---1
            // | P |     |P ^|
            // 3-->2 --> 3 / 2
            // | N |     |/ N|
            // 4---5     4---5

            var indexer = new ManualFaceNeighborIndexer(6, 14, 2, 1);

            indexer.AddFace(0, 1, 2, 3);
            indexer.AddFace(5, 4, 3, 2);
            var topology = TopologyUtility.BuildTopology(indexer);

            Topology.VertexEdge edgeToSpin;
            Assert.IsTrue(topology.vertices[3].TryFindEdge(topology.vertices[2], out edgeToSpin));

            topology.SpinEdgeBackward(edgeToSpin);

            TopologyUtility.CheckVerticesForInvalidEdgeCycles(topology);
            TopologyUtility.CheckFacesForInvalidEdgeCycles(topology);

            Assert.AreEqual(2, topology.vertices[0].neighborCount);
            Assert.AreEqual(3, topology.vertices[1].neighborCount);
            Assert.AreEqual(2, topology.vertices[2].neighborCount);
            Assert.AreEqual(2, topology.vertices[3].neighborCount);
            Assert.AreEqual(3, topology.vertices[4].neighborCount);
            Assert.AreEqual(2, topology.vertices[5].neighborCount);

            Assert.AreEqual(4, topology.internalFaces[0].neighborCount);
            Assert.AreEqual(4, topology.internalFaces[1].neighborCount);

            Assert.AreEqual(topology.vertices[4], edgeToSpin.nearVertex);
            Assert.AreEqual(topology.vertices[1], edgeToSpin.farVertex);
            Assert.AreEqual(topology.internalFaces[0], edgeToSpin.prevFace);
            Assert.AreEqual(topology.internalFaces[1], edgeToSpin.nextFace);

            Assert.AreEqual(topology.vertices[3], edgeToSpin.prev.farVertex);
            Assert.AreEqual(topology.vertices[5], edgeToSpin.next.farVertex);
            Assert.AreEqual(topology.vertices[2], edgeToSpin.twin.prev.farVertex);
            Assert.AreEqual(topology.vertices[0], edgeToSpin.twin.next.farVertex);

            Assert.AreEqual(topology.vertices[1], edgeToSpin.faceEdge.nextVertex);
            Assert.AreEqual(topology.vertices[2], edgeToSpin.faceEdge.next.nextVertex);
            Assert.AreEqual(topology.vertices[5], edgeToSpin.faceEdge.next.next.nextVertex);
            Assert.AreEqual(topology.vertices[4], edgeToSpin.faceEdge.next.next.next.nextVertex);
            Assert.AreEqual(topology.vertices[1], edgeToSpin.faceEdge.next.next.next.next.nextVertex);
            Assert.AreEqual(topology.vertices[4], edgeToSpin.twin.faceEdge.nextVertex);
            Assert.AreEqual(topology.vertices[3], edgeToSpin.twin.faceEdge.next.nextVertex);
            Assert.AreEqual(topology.vertices[0], edgeToSpin.twin.faceEdge.next.next.nextVertex);
            Assert.AreEqual(topology.vertices[1], edgeToSpin.twin.faceEdge.next.next.next.nextVertex);
            Assert.AreEqual(topology.vertices[4], edgeToSpin.twin.faceEdge.next.next.next.next.nextVertex);
        }
示例#5
0
        public void SpinEdgeBetweenTrianglesForward()
        {
            //   1         1
            //  /^\       /P\
            // 0P|N3 --> 0-->3
            //  \|/       \N/
            //   2         2

            var indexer = new ManualFaceNeighborIndexer(4, 10, 2, 1);

            indexer.AddFace(0, 1, 2);
            indexer.AddFace(3, 2, 1);
            var topology = TopologyUtility.BuildTopology(indexer);

            Topology.VertexEdge edgeToSpin;
            Assert.IsTrue(topology.vertices[2].TryFindEdge(topology.vertices[1], out edgeToSpin));

            topology.SpinEdgeForward(edgeToSpin);

            TopologyUtility.CheckVerticesForInvalidEdgeCycles(topology);
            TopologyUtility.CheckFacesForInvalidEdgeCycles(topology);

            Assert.AreEqual(3, topology.vertices[0].neighborCount);
            Assert.AreEqual(2, topology.vertices[1].neighborCount);
            Assert.AreEqual(2, topology.vertices[2].neighborCount);
            Assert.AreEqual(3, topology.vertices[3].neighborCount);

            Assert.AreEqual(3, topology.internalFaces[0].neighborCount);
            Assert.AreEqual(3, topology.internalFaces[1].neighborCount);

            Assert.AreEqual(topology.vertices[0], edgeToSpin.nearVertex);
            Assert.AreEqual(topology.vertices[3], edgeToSpin.farVertex);
            Assert.AreEqual(topology.internalFaces[0], edgeToSpin.prevFace);
            Assert.AreEqual(topology.internalFaces[1], edgeToSpin.nextFace);

            Assert.AreEqual(topology.vertices[1], edgeToSpin.prev.farVertex);
            Assert.AreEqual(topology.vertices[2], edgeToSpin.next.farVertex);
            Assert.AreEqual(topology.vertices[2], edgeToSpin.twin.prev.farVertex);
            Assert.AreEqual(topology.vertices[1], edgeToSpin.twin.next.farVertex);

            Assert.AreEqual(topology.vertices[3], edgeToSpin.faceEdge.nextVertex);
            Assert.AreEqual(topology.vertices[2], edgeToSpin.faceEdge.next.nextVertex);
            Assert.AreEqual(topology.vertices[0], edgeToSpin.faceEdge.next.next.nextVertex);
            Assert.AreEqual(topology.vertices[3], edgeToSpin.faceEdge.next.next.next.nextVertex);
            Assert.AreEqual(topology.vertices[0], edgeToSpin.twin.faceEdge.nextVertex);
            Assert.AreEqual(topology.vertices[1], edgeToSpin.twin.faceEdge.next.nextVertex);
            Assert.AreEqual(topology.vertices[3], edgeToSpin.twin.faceEdge.next.next.nextVertex);
            Assert.AreEqual(topology.vertices[0], edgeToSpin.twin.faceEdge.next.next.next.nextVertex);
        }
示例#6
0
        public void FaceNeighborFaces()
        {
            var surface  = RectangularQuadGrid.Create(Vector2.right, Vector2.up, Vector3.zero, Quaternion.identity, false, false, new IntVector2(3, 3));
            var topology = TopologyUtility.BuildTopology(surface);

            var face = topology.faces[surface.GetFaceIndex(1, 1)];
            var neighborFaceEdges = face.edges.GetEnumerator();

            Assert.True(neighborFaceEdges.MoveNext());
            Assert.AreEqual(surface.GetFaceIndex(1, 0), neighborFaceEdges.Current.farFace.index);
            Assert.True(neighborFaceEdges.MoveNext());
            Assert.AreEqual(surface.GetFaceIndex(0, 1), neighborFaceEdges.Current.farFace.index);
            Assert.True(neighborFaceEdges.MoveNext());
            Assert.AreEqual(surface.GetFaceIndex(1, 2), neighborFaceEdges.Current.farFace.index);
            Assert.True(neighborFaceEdges.MoveNext());
            Assert.AreEqual(surface.GetFaceIndex(2, 1), neighborFaceEdges.Current.farFace.index);
            Assert.False(neighborFaceEdges.MoveNext());
        }