Beispiel #1
0
        private static LinkedListNode <EarPoint> GetClosest(List <LinkedListNode <EarPoint> > pointsOrdered, int index, EarPolygon poly, LinkedListNode <EarPoint> innerPoint, EarPolygon polychild)
        {
            LinkedListNode <EarPoint> a = innerPoint;
            LinkedListNode <EarPoint> b = pointsOrdered[index];
            LinkedListNode <EarPoint> c = poly.Get();
            bool intersection           = false;

            do
            {
                intersection = DoIntersect(a.Value, b.Value, c.Value, poly.Next(c).Value);
                c            = c.Next;
            } while ((!intersection) && (c != null));
            if (!intersection)
            {
                c = a;
                do
                {
                    intersection = DoIntersect(a.Value, b.Value, c.Value, polychild.Next(c).Value);
                    c            = polychild.Next(c);
                } while ((!intersection) && (c.Value != a.Value));
                if (!intersection)
                {
                    return(b);
                }
            }
            return(GetClosest(pointsOrdered, index + 1, poly, innerPoint, polychild));
        }
Beispiel #2
0
        private static bool RecordEars(EarPolygon poly)
        {
            LinkedListNode <EarPoint> active = poly.Get();
            int NumPoints = poly.NumPoints() - 2;

            while (poly.NumPoints() >= 3)
            {
                int num = poly.NumPoints();
                int idx = active.Value.mIndex;
                do
                {
                    if (IsConvex(active, poly))
                    {
                        if (IsEar(active, poly))
                        {
                            break;
                        }
                    }
                    active = poly.Next(active);
                } while (idx != active.Value.mIndex);

                poly.AddResult(poly.Previous(active).Value[0], poly.Previous(active).Value[1], active.Value[0], active.Value[1], poly.Next(active).Value[0], poly.Next(active).Value[1]);
                active = poly.Next(active);
                poly.Remove(poly.Previous(active));
                continue;
            }
            return(true);
        }
        private static bool RecordEars(EarPolygon poly)
        {
            LinkedListNode <EarPoint> active = poly.Get();
            int NumPoints = poly.NumPoints() - 2;

            while (poly.NumPoints() >= 3)
            {
                int num = poly.NumPoints();
                int idx = active.Value.mIndex;
                //do
                //{
                //    if (IsConvex(active, poly))
                //    {
                //        if (IsEar(active, poly))
                //        {
                //            break;
                //        }
                //    }
                //    active = poly.Next(active);
                //} while (idx != active.Value.mIndex);

                List <LinkedListNode <EarPoint> > candidate = new List <LinkedListNode <EarPoint> >();
                do
                {
                    if (IsConvex(active, poly))
                    {
                        if (IsEar(active, poly))
                        {
                            candidate.Add(active);
                        }
                    }
                    active = poly.Next(active);
                } while (idx != active.Value.mIndex);
                List <KeyValuePair <int, float> > temp = new List <KeyValuePair <int, float> >();
                for (int i = 0; i < candidate.Count; ++i)
                {
                    LinkedListNode <EarPoint> ear = candidate[i];
                    float angle = AngleWithUp(ear, poly);
                    temp.Add(new KeyValuePair <int, float>(i, angle));
                }
                temp.Sort((x, y) => { return(-x.Value.CompareTo(y.Value)); });
                active = candidate[temp[0].Key];
                temp.Clear();
                candidate.Clear();
                poly.AddResult(poly.Previous(active).Value.mPoint, active.Value.mPoint, poly.Next(active).Value.mPoint);
                poly.AddResult(poly.Previous(active).Value.mVertex, active.Value.mVertex, poly.Next(active).Value.mVertex);
                active = poly.Next(active);
                poly.Remove(poly.Previous(active));
                continue;
            }
            return(true);
        }
        private static List <LinkedListNode <EarPoint> > OrderPoints(EarPolygon poly, LinkedListNode <EarPoint> point)
        {
            LinkedListNode <EarPoint>         head           = poly.Get();
            List <LinkedListNode <EarPoint> > pointContainer = new List <LinkedListNode <EarPoint> >();
            LinkedListNode <EarPoint>         activePoint    = point;

            while (head != null)
            {
                pointContainer.Add(head);
                head = head.Next;
            }
            pointContainer.Sort(new EarNodeValueCompare(activePoint));
            return(pointContainer);
        }
Beispiel #5
0
        private static KeyValuePair <LinkedListNode <EarPoint>, LinkedListNode <EarPoint> > GetSplit(EarPolygon outer, EarPolygon inner, float smallestX)
        {
            LinkedListNode <EarPoint> smallest = inner.Get();

            do
            {
                if (smallest.Value[0] == smallestX)
                {
                    break;
                }
                smallest = smallest.Next;
            } while (smallest != null);

            LinkedListNode <EarPoint> closest = GetClosest(OrderPoints(outer, smallest), 0, outer, smallest, inner);
            KeyValuePair <LinkedListNode <EarPoint>, LinkedListNode <EarPoint> > split = new KeyValuePair <LinkedListNode <EarPoint>, LinkedListNode <EarPoint> >(smallest, closest);

            return(split);
        }
Beispiel #6
0
        private static List <LinkedListNode <EarPoint> > OrderPoints(EarPolygon poly, LinkedListNode <EarPoint> point)
        {
            LinkedListNode <EarPoint>         head           = poly.Get();
            List <LinkedListNode <EarPoint> > pointContainer = new List <LinkedListNode <EarPoint> >();

            activePoint = point;
            while (head != null)
            {
                pointContainer.Add(head);
                head = head.Next;
            }
            pointContainer.Sort((i, j) =>
            {
                Vector2 t1 = i.Value.mPoint - activePoint.Value.mPoint;
                Vector2 t2 = j.Value.mPoint - activePoint.Value.mPoint;
                return(t1.sqrMagnitude.CompareTo(t2.sqrMagnitude));
            });
            return(pointContainer);
        }