public void PointsInputHandler(object sender, MouseEventArgs e) { Contour currentContour = Contours.FirstOrDefault(x => !x.IsCompleted); if (currentContour == null) { currentContour = new Contour(Contours.Count + 1); Contours.Add(currentContour); } var newPoint = new Point(e.X, _drawer.CanvasHeight - e.Y) { Index = _lastPointIndex + 1 }; if (currentContour.Head == null) { currentContour.Add(newPoint); _drawer.DrawPoints(Pens.Black, newPoint); //Ekaterina _drawer.RefreshImage(); //end Ekaterina _lastPointIndex++; } else { if (currentContour.Tail == null) { var newLineSegment = new LineSegment(currentContour.Head, newPoint); if (Contours.Where(x => x != currentContour).Any(x => x.IntersectsWithLineSegment(newLineSegment, IntersectionCheckOptions.WithEdgePoints)) || currentContour.IntersectsWithLineSegment(newLineSegment, IntersectionCheckOptions.WithoutEdgePoints)) { MessageBox.Show(ErrorMessageBoxMessage, ErrorMessageBoxTitle); } else { currentContour.Add(newPoint); _drawer.DrawLineSegments(Pens.Black, newLineSegment); _lastPointIndex++; } } else { var newLineSegment = new LineSegment(currentContour.Tail, newPoint); if (Contours.Where(x => x != currentContour).Any(x => x.IntersectsWithLineSegment(newLineSegment, IntersectionCheckOptions.WithEdgePoints)) || currentContour.IntersectsWithLineSegment(newLineSegment, IntersectionCheckOptions.WithoutEdgePoints)) { MessageBox.Show(ErrorMessageBoxMessage, ErrorMessageBoxTitle); } else { currentContour.Add(newPoint); if (!currentContour.IsCompleted) { _drawer.DrawLineSegments(Pens.Black, newLineSegment); _lastPointIndex++; } else { _drawer.DrawLineSegments(Pens.Black, new LineSegment(currentContour.Tail, currentContour.Head)); } } } } if (currentContour.IsCompleted) { _tabControlHelper.CreatePageForContour(currentContour); } }