コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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;
                }
            }
        }