Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        private static bool RecordEars(EarPolygon poly)
        {
            LinkedListNode <EarPoint> active = poly.Get();

            while (poly.NumPoints() >= 3)
            {
                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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }