private void Calculate_Vertex_Guards(object sender, RoutedEventArgs e)
        {
            Triangulation t1 = new Triangulation();
            if (!p1.closed)
            {
                p1.close();
            }

            if (p1.clockwise && (p1.area() < 0)) p1.reverseCollection();
            else if (!p1.clockwise && (p1.area() < 0)) p1.reverseCollection();
            //the algo deletes points from the List so we create a backup list
            p1.doBackup();
            DiagonalSet d1 = t1.triangulate(p1);
            p1.addDiagonals(d1);
            p1.Diagonals = d1;
            //restore the points
            p1.restorePoints();
            TriangulationColoring CSet = t1.color(d1, p1); 		// 3 color the polygon
            CSet.setGuards(p1);
            Triangulation t2 = new Triangulation();
        }
        internal void readCoordinateFile(string inputFile)
        {
            Triangulation triangulation = new Triangulation();
            try
            {
                using (StreamReader sr = File.OpenText(inputFile))
                {
                    String input;
                    while ((input = sr.ReadLine()) != null)
                    {
                        String[] words = input.Split(',');
                        if (words.Length > 2)
                        {
                            throw new FormatException("Length: " + words.Length.ToString());
                        }
                        ColoredPoint c1 = new ColoredPoint(Convert.ToDouble(words[0]), Convert.ToDouble(words[1]));

                        if (this.vertices.Count == 0 ||
                            triangulation.noIntersection(this.vertices[0].point.X, this.vertices[0].point.Y, c1.point.X, c1.point.Y, this))
                        {
                            //this.vertices.Add(c1);
                            this.AddVertex(c1);
                        }
                        else
                        {
                            //error, we have an intersection
                        }
                    }
                    if (this.vertices.Count > 3)
                    {
                        this.close();
                    }
                }
            }
            catch (Exception e)
            {
                // Configure the message box to be displayed
                string messageBoxText = e.Message;
                string caption = "Error";
                MessageBoxButton button = MessageBoxButton.OK;
                MessageBoxImage icon = MessageBoxImage.Error;
                MessageBox.Show(messageBoxText, caption, button, icon);
                return;
            }
        }
        public bool AddVertexFromMouseClick(ColoredPoint vertex)
        {
            Triangulation triangulation = new Triangulation();
            if (this.closed == true) return false;
            if (!containsWithinRange(vertex))
            {

                if (this.vertices.Count == 0 ||
                    triangulation.noIntersection(this.vertices[0].point.X, this.vertices[0].point.Y, vertex.point.X, vertex.point.Y, this))
                {
                    vertex.index = this.vertices.Count;
                    this.vertices.Add(vertex);
                    OnPropertyChanged("vertices");
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                //if we click on the first point, then we are closing the polygon
                if (vertex.withinRoot(this.vertices[0]))
                {
                    this.closed = true;
                    OnPropertyChanged("vertices");
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }