private bool signedTriangleSquareCheck(LineSegment other, IntersectionCheckOptions option)
 {
     int call1 = signedTriangleSquare(Start, End, other.Start);
     int call2 = signedTriangleSquare(Start, End, other.End);
     int call3 = signedTriangleSquare(other.Start, other.End, Start);
     int call4 = signedTriangleSquare(other.Start, other.End, End);
     return option == IntersectionCheckOptions.WithoutEdgePoints ? call1*call2 < 0 && call3*call4 < 0 : call1*call2 <= 0 && call3*call4 <= 0;
 }
 public Triangle(Point i, Point j, Point k)
 {
     I = i;
     J = j;
     K = k;
     IJ = new LineSegment(i, j);
     JK = new LineSegment(j, k);
     KI = new LineSegment(k, i);
     _square = null;
 }
 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);
     }
 }
 private bool projectionIntersectionCheck(LineSegment other, IntersectionCheckOptions option)
 {
     bool call1 = projectionIntersection(Start.X, End.X, other.Start.X, other.End.X, option);
     bool call2 = projectionIntersection(Start.Y, End.Y, other.Start.Y, other.End.Y, option);
     return call1 && call2;
 }
 public bool Intersects(LineSegment other, IntersectionCheckOptions option)
 {
     return projectionIntersectionCheck(other, option) && signedTriangleSquareCheck(other, option);
 }