public Face2D AddPoints(params Point2D[] points)
        {
            //newEdges = new List<Edge2D>();
            int size = points.Length;

            if (size < 3)
            {
                throw new System.Exception("The points count cannot less than 3.");
            }


            List <Edge2D> edges = new List <Edge2D>();

            for (int i = 0, j = 1; i < size; i++, j = (i + 1) % size)
            {
                edges.Add(new Edge2D(points[i], points[j]));
            }

            bool[] isEdgeExits = new bool[size];

            List <Edge2D> allEdges = AllExistedEdges;

            foreach (var ss in allEdges)// allEdges)
            {
                for (int i = 0; i < size; i++)
                {
                    if (edges[i].IsMatchFor(ss))
                    {
                        Edge2D match = edges[i];
                        foreach (var p in match.Points)
                        {
                            p.Edges.Remove(match);
                        }

                        edges[i]       = ss;
                        isEdgeExits[i] = true;
                    }
                }
            }

            for (int i = 0; i < size; i++)
            {
                if (!isEdgeExits[i])
                {
                    allEdges.Add(edges[i]);
                }
            }



            /*Face2D result = new Face2D(edges.ToArray());*/
            /*AddFace(new Face2D(edges.ToArray()));*/



            /*Debug.Log("Local variable allEdges count :" + allEdges.Count);
             * Debug.Log("world variable GetAllEdges count :" + GetAllEdges().Count);*/

            return(AddFace(new Face2D(edges.ToArray())));
        }
        /*Point2D FirstPoint { get { return BasicEdges.First().PointInBoth(BasicEdges.Last()); } }*/

        public List <Point2D> GetActualPointsInWindingOrder()
        {
            List <Point2D> points = new List <Point2D>();

            Edge2D  first      = BasicEdges.First();
            Edge2D  last       = BasicEdges.Last();
            Point2D firstPoint = first.PointInBoth(last);

            points.Add(firstPoint);
            foreach (var currect in BasicEdges)//.Skip(1).Take(BasicEdges.Count - 2))
            {
                currect.AddAllMiddlePoints(points);

                Point2D nextPoint = currect.PointOnlyInThis(last);
                if (nextPoint == firstPoint)
                {
                    break;
                }
                points.Add(nextPoint);

                last = currect;
            }

            return(points);
        }
        private List <Point2D> DivideBasicEdges()
        {
            List <Point2D> points = new List <Point2D>();

            Edge2D  first      = BasicEdges.First();
            Edge2D  last       = BasicEdges.Last();
            Point2D firstPoint = first.PointInBoth(last);

            points.Add(firstPoint);
            foreach (var currect in BasicEdges)//.Skip(1).Take(BasicEdges.Count - 2))
            {
                //currect.OnDivide();
                points.Add(currect.OnDivide());

                Point2D nextPoint = currect.PointOnlyInThis(last);
                if (nextPoint == firstPoint)
                {
                    break;
                }
                points.Add(nextPoint);

                last = currect;
            }

            return(points);
        }
        private List <Point2D> GetBasiclPointsInWindingOrder()
        {
            //return Edges.SelectMany(e => e.Points).Distinct().ToList();
            List <Point2D> points = new List <Point2D>();
            // The edges were added in order, but we don't know if the points within the edges are in order.
            // Therefore we look at the previous edge to figoure out which point has already been visited

            Edge2D previous = BasicEdges.First();

            foreach (var current in BasicEdges.Skip(1).Take(BasicEdges.Count - 2))
            {
                if (points.Count == 0)
                {
                    Point2D firstPoint = previous.PointOnlyInThis(current);
                    points.Add(firstPoint);

                    Point2D secondPoint = previous.PointInBoth(current);
                    points.Add(secondPoint);
                }

                Point2D nextPoint = current.PointOnlyInThis(previous);
                points.Add(nextPoint);

                previous = current;
            }

            return(points);
        }
        public void AddAllMiddlePoints(List <Point2D> allPoints)
        {
            if (MiddlePoint == null)
            {
                //Debug.Log(string.Format("Edge {{{0}, {1}}} Do not have a middle point", Points[0].Name, Points[1].Name));
                return;
            }

            if (allPoints.Count < 1)
            {
                throw new System.Exception("The Middle Points List must has a point!");
            }

            Point2D firstPoint = allPoints[allPoints.Count - 1];

            if (!Points.Contains(firstPoint))
            {
                //Debug.Log(string.Format("Edge {{{0}, {1}}} Do not contains allPoints 's last point", Points[0].Name, Points[1].Name));
                return;
            }
            Point2D lastPoint = Points[0] == firstPoint ? Points[1] : Points[0];
            Edge2D  firstEdge = MiddlePoint.Edges.Find(e => e.Points.Contains(firstPoint));

            if (firstEdge != null)
            {
                firstEdge.AddAllMiddlePoints(allPoints);
            }
            allPoints.Add(MiddlePoint);
            Edge2D lastEdge = MiddlePoint.Edges.Find(e => e.Points.Contains(lastPoint));

            if (lastEdge != null)
            {
                lastEdge.AddAllMiddlePoints(allPoints);
            }
        }
        public Point2D PointOnlyInThis(Edge2D other)
        {
            Point2D p1 = Points[0];

            if (!other.Points.Contains(p1))
            {
                return(p1);
            }
            else
            {
                return(Points[1]);
            }
        }
        public Point2D PointInBoth(Edge2D other)
        {
            Point2D p1 = Points[0];

            if (other.Points.Contains(p1))
            {
                return(p1);
            }
            else
            {
                return(Points[1]);
            }
        }
 public bool IsMatchFor(Edge2D edge)
 {
     return(IsMatchFor(edge.Points[0], edge.Points[1]));
 }