Beispiel #1
0
 public HalfEdge(Vertex a_Vertex)
 {
     // Using new here prevents reference equality. Is it really necessary to copy?
     m_Origin = new Vertex(a_Vertex.X, a_Vertex.Y, a_Vertex.Ownership);
     Triangle = null;
     Twin = null;
     Next = null;
     Prev = null;
 }
Beispiel #2
0
        protected void AddVertex(Triangle a_Triangle, Vertex a_Vertex)
        {
            m_Vertices.Add(a_Vertex);

            m_Triangles.Remove(a_Triangle);

            HalfEdge h1 = a_Triangle.HalfEdge;
            HalfEdge h2 = h1.Next;
            HalfEdge h3 = h2.Next;

            HalfEdge h4 = new HalfEdge(h1.Origin);
            HalfEdge h5 = new HalfEdge(h2.Origin);
            HalfEdge h6 = new HalfEdge(h3.Origin);
            HalfEdge h7 = new HalfEdge(a_Vertex);
            HalfEdge h8 = new HalfEdge(a_Vertex);
            HalfEdge h9 = new HalfEdge(a_Vertex);
            m_HalfEdges.AddRange(new List<HalfEdge>() { h4, h5, h6, h7, h8, h9 });

            h4.Twin = h7;
            h7.Twin = h4;
            h5.Twin = h8;
            h8.Twin = h5;
            h6.Twin = h9;
            h9.Twin = h6;

            // Set all next
            h1.Next = h5;
            h5.Prev = h1;
            h5.Next = h7;
            h7.Prev = h5;
            h7.Next = h1;
            h1.Prev = h7;

            h2.Next = h6;
            h6.Prev = h2;
            h6.Next = h8;
            h8.Prev = h6;
            h8.Next = h2;
            h2.Prev = h8;

            h3.Next = h4;
            h4.Prev = h3;
            h4.Next = h9;
            h9.Prev = h4;
            h9.Next = h3;
            h3.Prev = h9;

            m_Triangles.Add(new Triangle(h1));
            m_Triangles.Add(new Triangle(h2));
            m_Triangles.Add(new Triangle(h3));
        }
Beispiel #3
0
        private void LegalizeEdge(Vertex a_Vertex, HalfEdge a_HalfEdge, Triangle a_Triangle)
        {
            if (a_Vertex == null || a_HalfEdge == null || a_Triangle == null)
            {
                Debug.LogError("Invalid call to LegalizeEdge");
                return;
            }

            Vertex v1, v2, v3;
            try
            {
                // Points to test
                v1 = a_HalfEdge.Twin.Next.Next.Origin;
                v2 = a_HalfEdge.Next.Twin.Next.Next.Origin;
                v3 = a_HalfEdge.Next.Next.Twin.Next.Next.Origin;
            }
            catch (NullReferenceException)
            {
                Debug.LogError("Null pointers in call to LegalizeEdge");
                return;
            }

            if (v1 == null || v2 == null || v3 == null)
            {
                Debug.LogError("Invalid halfedge in call to LegalizeEdge");
                return;
            }

            if (a_Triangle.InsideCircumcenter(v1) || a_Triangle.InsideCircumcenter(v2) || a_Triangle.InsideCircumcenter(v3))
            {
                HalfEdge h1 = a_HalfEdge.Twin.Next.Twin;
                HalfEdge h2 = a_HalfEdge.Twin.Prev.Twin;

                Flip(a_HalfEdge);

                LegalizeEdge(a_Vertex, h1.Twin, h1.Twin.Triangle);
                LegalizeEdge(a_Vertex, h2.Twin, h2.Twin.Triangle);
            }
        }
Beispiel #4
0
 public void DrawTriangle(Triangle t, Color c)
 {
     DrawTriangle(t.Point1, t.Point2, t.Point3, c);
 }
Beispiel #5
0
        public void DrawPolygon(Triangle t, Color c)
        {
            var plist = new List<Point>()
            {
                t.Point1,
                t.Point2,
                t.Point3
            };

            DrawPolygon(plist,c);
        }