Пример #1
0
        /// <summary>
        /// Replaces two vertices.
        /// </summary>
        /// <param name="previousVertex">The vertex to replace.</param>
        /// <param name="newVertex">The new vertex.</param>
        /// <returns>true when vertex was replaced, false otherwise.</returns>
        public bool Replace(Vertex previousVertex, Vertex newVertex)
        {
            if (Contains(previousVertex) && Contains(newVertex))
            {
                return(false);
            }

            if (Vertex1 == previousVertex && Vertex2 == previousVertex)
            {
                Vertex1.RemoveTriangle(this);
                return(false);
            }
            if (Vertex2 == previousVertex && Vertex3 == previousVertex)
            {
                Vertex1.RemoveTriangle(this);
                return(false);
            }
            if (Vertex1 == previousVertex && Vertex3 == previousVertex)
            {
                Vertex1.RemoveTriangle(this);
                return(false);
            }

            if (Vertex1 == previousVertex)
            {
                Vertex1 = newVertex;
                Vertex1.AddTriangle(this);
            }
            else if (Vertex2 == previousVertex)
            {
                Vertex2 = newVertex;
                Vertex2.AddTriangle(this);
            }
            else if (Vertex3 == previousVertex)
            {
                Vertex3 = newVertex;
                Vertex3.AddTriangle(this);
            }
            else
            {
                return(false);
            }

            Vertex1.Replace(previousVertex, newVertex);
            Vertex2.Replace(previousVertex, newVertex);
            Vertex3.Replace(previousVertex, newVertex);

            m_ReplacedBefore = true;
            return(true);
        }