Пример #1
0
 public void Remove()
 {
     Next.Last = Last;
     Last.Next = Next;
     Next      = null;
     Last      = null;
 }
Пример #2
0
        public Circular Prepend(Circular node)
        {
            node.Next = this;
            node.Last = Last;
            Last.Next = node;
            Last = node;

            return node;
        }
Пример #3
0
        public Circular Append(Circular node)
        {
            node.Last = this;
            node.Next = Next;
            Next.Last = node;
            Next = node;

            return node;
        }
Пример #4
0
        public Circular Append(Circular node)
        {
            node.Last = this;
            node.Next = Next;
            Next.Last = node;
            Next      = node;

            return(node);
        }
Пример #5
0
        public Circular Prepend(Circular node)
        {
            node.Next = this;
            node.Last = Last;
            Last.Next = node;
            Last      = node;

            return(node);
        }
Пример #6
0
        public void Duplicate(ref Point3[] Points, int i)
        {
            Circular node = this;

            do
            {
                Points[i++] = node.Point;
                node        = node.Next;
            } while (node != this);
        }
Пример #7
0
        public static Point3[] getConvexPolygon(Point3[] points)
        {
            int num = points.Length;

            sort(ref points, 0, points.Length - 1);

            Point3 left  = points[0];
            Point3 right = points[num - 1];


            Circular lower = new Circular(left);
            Circular upper = new Circular(left);

            for (int i = 0; i < num; i++)
            {
                double result = Point3.check(left, right, points[i]);
                if (result > 0)
                {
                    upper = upper.Append(new Circular(points[i]));
                }
                else if (result < 0)
                {
                    lower = lower.Prepend(new Circular(points[i]));
                }
            }
            lower = lower.Prepend(new Circular(right));
            upper = upper.Append(new Circular(right)).Next;


            minimize(lower);
            minimize(upper);


            if (lower.Last.Point.Equals(upper.Point))
            {
                lower.Last.Remove();
            }

            if (upper.Last.Point.Equals(lower.Point))
            {
                upper.Last.Remove();
            }


            Point3[] final = new Point3[lower.Length() + upper.Length() + 1];

            lower.Duplicate(ref final, 0);
            upper.Duplicate(ref final, lower.Length());
            final[lower.Length() + upper.Length()] = final[0];
            increase1pc(ref final);

            return(final);
        }
Пример #8
0
        public int Length()
        {
            int      num  = 0;
            Circular node = this;

            do
            {
                num++;
                node = node.Next;
            } while (node != this);

            return(num);
        }
Пример #9
0
        private static void minimize(Circular start)
        {
            Circular a   = start;
            Circular end = start.Last;

            bool finished = false;

            while (a.Next != start || !finished)
            {
                if (a.Next == end)
                {
                    finished = true;
                }
                if (Point3.check(a.Point, a.Next.Point, a.Next.Next.Point) < 0)
                {
                    a = a.Next;
                }
                else
                {
                    a.Next.Remove();
                    a = a.Last;
                }
            }
        }
Пример #10
0
 public void Remove()
 {
     Next.Last = Last;
     Last.Next = Next;
     Next = null;
     Last = null;
 }
Пример #11
0
 public Circular(Point3 point)
 {
     Point = point;
     Next = this;
     Last = this;
 }
Пример #12
0
        private static void minimize(Circular start)
        {
            Circular a = start;
            Circular end = start.Last;

            bool finished = false;

            while (a.Next != start || !finished)
            {
                if (a.Next == end)
                    finished = true;
                if (Point3.check(a.Point, a.Next.Point, a.Next.Next.Point) < 0)
                    a = a.Next;
                else
                {
                    a.Next.Remove();
                    a = a.Last;
                }
            }
        }
Пример #13
0
        public static Point3[] getConvexPolygon(Point3[] points)
        {
            int num = points.Length;
            sort(ref points,0,points.Length-1);

            Point3 left = points[0];
            Point3 right = points[num - 1];

               Circular lower = new Circular(left);
            Circular upper = new Circular(left);

            for (int i = 0; i < num; i++)
            {
                double result = Point3.check(left, right, points[i]);
                if (result > 0)
                    upper = upper.Append(new Circular(points[i]));
                else if (result < 0)
                    lower = lower.Prepend(new Circular(points[i]));
            }
            lower = lower.Prepend(new Circular(right));
            upper = upper.Append(new Circular(right)).Next;

            minimize(lower);
            minimize(upper);

            if (lower.Last.Point.Equals(upper.Point))
                lower.Last.Remove();

            if (upper.Last.Point.Equals(lower.Point))
                upper.Last.Remove();

            Point3[] final = new Point3[lower.Length() + upper.Length() + 1];

            lower.Duplicate(ref final, 0);
            upper.Duplicate(ref final, lower.Length());
            final[lower.Length() + upper.Length()] = final[0];
            increase1pc(ref final);

            return final;
        }
Пример #14
0
 public Circular(Point3 point)
 {
     Point = point;
     Next  = this;
     Last  = this;
 }