Example #1
0
        void MakePerimeterConvex(PerimeterEdge firstPerimeterEdge)
        {
            firstPerimeterEdge = FindPivot(firstPerimeterEdge);
            var           firstSite = firstPerimeterEdge.Start;
            var           a         = firstPerimeterEdge;
            PerimeterEdge b;

            do
            {
                b = a.Next;
                if (Point.GetTriangleOrientationWithNoEpsilon(a.Start.Point, a.End.Point, b.End.Point) == TriangleOrientation.Counterclockwise)
                {
                    a = ShortcutTwoListElements(a);
                    while (a.Start != firstSite)
                    {
                        var c = a.Prev;
                        if (Point.GetTriangleOrientationWithNoEpsilon(c.Start.Point, c.End.Point, a.End.Point) == TriangleOrientation.Counterclockwise)
                        {
                            a = ShortcutTwoListElements(c);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    a = b;
                }
            } while (a.End != firstSite);
        }
Example #2
0
        PerimeterEdge CreateDoubleLinkedListOfPerimeter()
        {
            CdtEdge       firstEdge = this.triangles.SelectMany(t => t.Edges).FirstOrDefault(e => e.CwTriangle == null || e.CcwTriangle == null);
            var           edge = firstEdge;
            PerimeterEdge pe, prevPe = null, listStart = null;

            do
            {
                pe   = CreatePerimeterElementFromEdge(edge);
                edge = FindNextEdgeOnPerimeter(edge);
                if (prevPe != null)
                {
                    pe.Prev     = prevPe;
                    prevPe.Next = pe;
                }
                else
                {
                    listStart = pe;
                }

                prevPe = pe;
            } while (edge != firstEdge);
            listStart.Prev = pe;
            pe.Next        = listStart;
            return(listStart);
        }
Example #3
0
        PerimeterEdge ShortcutTwoListElements(PerimeterEdge a)
        {
            var b = a.Next;

            Debug.Assert(a.End == b.Start);
            var t = new CdtTriangle(a.Start, a.End, b.End, a.Edge, b.Edge,
                                    createEdgeDelegate);

            Triangles.Insert(t);
            var newEdge = t.Edges[2];

            Debug.Assert(newEdge.IsAdjacent(a.Start) && newEdge.IsAdjacent(b.End));
            LegalizeEdge(a.Start, t.OppositeEdge(a.Start));
            t = newEdge.CcwTriangle ?? newEdge.CwTriangle;
            LegalizeEdge(b.End, t.OppositeEdge(b.End));
            var c = new PerimeterEdge(newEdge)
            {
                Start = a.Start, End = b.End
            };

            a.Prev.Next = c;
            c.Prev      = a.Prev;
            c.Next      = b.Next;
            b.Next.Prev = c;
            return(c);
        }
Example #4
0
        PerimeterEdge CreateDoubleLinkedListOfPerimeter()
        {
            var           firstEdge = front.First().Edge;
            var           edge = firstEdge;
            PerimeterEdge pe, prevPe = null, listStart = null;

            do
            {
                pe   = CreatePerimeterElementFromEdge(edge);
                edge = FindNextEdgeOnPerimeter(edge);
                if (prevPe != null)
                {
                    pe.Prev     = prevPe;
                    prevPe.Next = pe;
                }
                else
                {
                    listStart = pe;
                }

                prevPe = pe;
            } while (edge != firstEdge);
            listStart.Prev = pe;
            pe.Next        = listStart;
            return(listStart);
        }
 static PerimeterEdge FindPivot(PerimeterEdge firstPerimeterEdge) {
     var pivot = firstPerimeterEdge;
     var e=firstPerimeterEdge;
     do { 
         e=e.Next;
         if (e.Start.Point.X < pivot.Start.Point.X ||
             e.Start.Point.X == pivot.Start.Point.X && e.Start.Point.Y < pivot.Start.Point.Y)
             pivot = e;
     } while (e != firstPerimeterEdge);
     return pivot;
 }
Example #6
0
        static PerimeterEdge CreatePerimeterElementFromEdge(CdtEdge edge)
        {
            var pe = new PerimeterEdge(edge);

            if (edge.CwTriangle != null)
            {
                pe.Start = edge.upperSite;
                pe.End   = edge.lowerSite;
            }
            else
            {
                pe.End   = edge.upperSite;
                pe.Start = edge.lowerSite;
            }
            return(pe);
        }
Example #7
0
        static PerimeterEdge FindPivot(PerimeterEdge firstPerimeterEdge)
        {
            var pivot = firstPerimeterEdge;
            var e     = firstPerimeterEdge;

            do
            {
                e = e.Next;
                if (e.Start.Point.X < pivot.Start.Point.X ||
                    e.Start.Point.X == pivot.Start.Point.X && e.Start.Point.Y < pivot.Start.Point.Y)
                {
                    pivot = e;
                }
            } while (e != firstPerimeterEdge);
            return(pivot);
        }
 void MakePerimeterConvex(PerimeterEdge firstPerimeterEdge) {
     firstPerimeterEdge = FindPivot(firstPerimeterEdge);
     var firstSite = firstPerimeterEdge.Start;
     var a=firstPerimeterEdge;
     PerimeterEdge b;
     do { 
        b=a.Next;
        if (Point.GetTriangleOrientationWithNoEpsilon(a.Start.Point, a.End.Point, b.End.Point) == TriangleOrientation.Counterclockwise) {
            a = ShortcutTwoListElements(a);
            while (a.Start != firstSite) {
                var c=a.Prev;
                if (Point.GetTriangleOrientationWithNoEpsilon(c.Start.Point, c.End.Point, a.End.Point) == TriangleOrientation.Counterclockwise) {
                    a = ShortcutTwoListElements(c);
                } else break;
            }
        } else
            a = b;
     } while (a.End != firstSite); 
 }
 PerimeterEdge ShortcutTwoListElements(PerimeterEdge a) {
     var b = a.Next;
     Debug.Assert(a.End == b.Start);
     var t = new CdtTriangle(a.Start, a.End, b.End, a.Edge, b.Edge,
                                     createEdgeDelegate);
     Triangles.Insert(t);
     var newEdge = t.Edges[2];
     Debug.Assert(newEdge.IsAdjacent(a.Start) && newEdge.IsAdjacent(b.End));
     LegalizeEdge(a.Start, t.OppositeEdge(a.Start));
     t = newEdge.CcwTriangle ?? newEdge.CwTriangle;
     LegalizeEdge(b.End, t.OppositeEdge(b.End));
     var c = new PerimeterEdge(newEdge) { Start = a.Start, End = b.End };
     a.Prev.Next = c;
     c.Prev = a.Prev;
     c.Next = b.Next;
     b.Next.Prev = c;
     return c;
 }
 static PerimeterEdge CreatePerimeterElementFromEdge(CdtEdge edge) {
     var pe = new PerimeterEdge(edge);
     if (edge.CwTriangle != null) {
         pe.Start=edge.upperSite;
         pe.End = edge.lowerSite;
     } else {
         pe.End = edge.upperSite;
         pe.Start = edge.lowerSite;
     }
     return pe;
 }