public bool FixRelations(DragablePoint point) { var atBeginning = Lines.Where(x => x.First == point).FirstOrDefault(); var atEnding = Lines.Where(x => x.Second == point).FirstOrDefault(); if (atBeginning == null || atEnding == null) { return(false); } if (atBeginning.Relation == Relation.NONE && atEnding.Relation == Relation.NONE) { return(true); } if (atBeginning.Relation != Relation.NONE) { FixRelationFromLine(atBeginning, true); } if (atEnding.Relation != Relation.NONE) { FixRelationFromLine(atEnding, false); } return(true); }
public void AddPoint(DragablePoint point, int index = -1) // index is Line in which we insert point { if (Points.Count == 0) { Points.Add(point); return; } if (index < 0) { if (Lines.Count > 0) { Lines.Last().Second = point; } else { Lines.Add(new Line(Points.First(), point)); } Lines.Add(new Line(point, Points.First())); Points.Add(point); return; } else { var oldEnd = Lines[index].Second; Lines[index].Second = point; Lines.Insert(index + 1, new Line(point, oldEnd)); Points.Insert(index + 1, point); } }
public void AddMiddlePoint(object arg) { var line = arg as Line; if (line == null) { return; } if (SelectedPolygon == null) { return; } line.RemoveRelation(); var index = SelectedPolygon.Lines.IndexOf(line); var toAdd = new DragablePoint((line.First.X + line.Second.X) / 2, (line.First.Y + line.Second.Y) / 2); SelectedPolygon.AddPoint(toAdd, index); SelectedPolygon.RenderBitmap(); }
public void DeletePoint(DragablePoint point) { var pos = Points.IndexOf(point); if (pos == -1) { return; } var atBeginning = Lines.Where(x => x.First == point).FirstOrDefault(); var atEnding = Lines.Where(x => x.Second == point).FirstOrDefault(); if (atBeginning != null && atEnding != null) { atBeginning.RemoveRelation(); atEnding.RemoveRelation(); DragablePoint toJoin = atBeginning.Second; atEnding.Second = toJoin; Lines.Remove(atBeginning); } Points.Remove(point); }
public Line(DragablePoint first, DragablePoint second) { First = first; Second = second; }