public void addPnt(Point p) { ColoredPoint c1 = new ColoredPoint(Convert.ToDouble(p.X), Convert.ToDouble(p.Y)); if (clockwise) { if (vertices.Count != 0) { link(vertices.Count, vertices.Count - 1); if (vertices.Count != 2) unlink(vertices.Count - 1, 0); link(vertices.Count, 0); } c1.index = vertices.Count; } else { for (int i = vertices.Count; i > 0; i--) { vertices[i].index = i; } vertices.Insert(0, c1); link(vertices.Count, vertices.Count - 1); link(vertices.Count, 0); unlink(vertices.Count - 1, 0); c1.index = 0; } OnPropertyChanged("vertices"); vertices.Add(c1); }
public ColoredPoint(ColoredPoint point) { this.vertex = point.vertex; this.point = point.point; this.index = point.index; this.vertexColor = point.vertexColor; this.isGuard = point.IsGuard; this.isGuard = point.IsDuplicate; this.IsFromMouse = point.IsFromMouse; }
internal void readCoordinateFile(string inputFile) { 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])); this.AddVertex(c1); } } } 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 void AddVertex(ColoredPoint vertex) { this.vertices.Add(vertex); OnPropertyChanged("vertices"); }
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 containsWithinRange(ColoredPoint point) { foreach (ColoredPoint coloredPoint in this.vertices) { if(point.withinRoot(coloredPoint)) { return true; } } return false; }
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; } } }
public void AddVertex(ColoredPoint vertex) { ColoredPoint tmpPoint = new ColoredPoint(vertex); if (!this.vertices.Contains(vertex)) { if (tmpPoint.index == -1) { tmpPoint.index = this.vertices.Count; } this.vertices.Add(tmpPoint); OnPropertyChanged("vertices"); } }
public bool withinRoot(ColoredPoint p) { // If parameter is null return false: if ((object)p == null) { return false; } return ((Math.Abs(this.point.X - p.point.X) < 4)) && (Math.Abs(this.point.Y - p.point.Y) < 4); }
public bool Equals(ColoredPoint p) { // If parameter is null return false: if ((object)p == null) { return false; } return (this.point.X == p.point.X) && (this.point.Y == p.point.Y); }
void line_MouseDown(object sender, MouseButtonEventArgs e) { Point p = e.GetPosition(SubLayout); ColoredPoint coloredPoint = new ColoredPoint(p.X, p.Y, true); GeometryCollection g1 = new GeometryCollection(); if (p1.AddVertexFromMouseClick(coloredPoint)) { if (p1.vertices.Count >= 3 && p1.closed == true) { print_input_file.IsEnabled = true; calculate_guards.IsEnabled = true; save_to_output.IsEnabled = true; create_from_file.IsEnabled = false; } } }