Exemplo n.º 1
0
 public override Line2DBase Cut(float x, bool cutRight)
 {
     if (this.IsVertical || !this.ContainsAbsciss(x))
     {
         return null;
     }
     Line2DBase cutLine = null;
     PointF cutPoint = new PointF(x, this.ValueAtX(x));
     if (cutPoint == this.Point1) { return null; } // Don't create an empty segment
     if (this.VX > 0) // HalfLine is infinite on the right
     {
         if (cutRight)
         {
             cutLine = new Segment2D(this.Point1, cutPoint, this.Pen);
         }
         else
         {
             cutLine = new HalfLine2D(cutPoint, this.VX, this.VY, this.Pen);
         }
     }
     else // HalfLine is infinite on the left
     {
         if (cutRight)
         {
             cutLine = new HalfLine2D(cutPoint, this.VX, this.VY, this.Pen);
         }
         else
         {
             cutLine = new Segment2D(this.Point1, cutPoint, this.Pen);
         }
     }
     cutLine.Pen = this.Pen;
     return cutLine;
 }
Exemplo n.º 2
0
        public override float DistanceTo(PointF point)
        {
            if (this.Point1 == point || this.Point2 == point)
            {
                return 0;
            }
            // Calculate orhogonal line
            Line2D orthoLine = GetNormalLine(point);

            // Calculate Intersection
            PointF point3 = this.Intersection(orthoLine);

            // Calculate the length on the ortho segment
            if (point != point3)
            {
                Segment2D segment = new Segment2D(point, point3);
                return segment.Length();
            }
            else
            {
                return 0;
            }
        }
Exemplo n.º 3
0
 public Line2D(Segment2D segment)
     : base(segment.Point1, segment.Point2)
 {
 }
Exemplo n.º 4
0
        public List<Line2DBase> GetLines(Pen pen)
        {
            List<Line2DBase> lines = new List<Line2DBase>();

             if (this.Point1 == PointF.Empty || this.Point2 == PointF.Empty || this.Point3 == PointF.Empty)
             {
            return null;
             }
             // Calculate projected line
             Segment2D segment2D = new Segment2D(this.Point2, this.Point3);

             PointF endPoint = new PointF(this.Point3.X + segment2D.VX, this.Point3.Y + segment2D.VY);

             Line2DBase medianLine = new HalfLine2D(this.Point1, this.Point3, pen);
             lines.Add(medianLine);

             // Calculate channel lines.
             lines.Add(new HalfLine2D(this.Point2, medianLine.VX, medianLine.VY, pen));
             lines.Add(new HalfLine2D(endPoint, medianLine.VX, medianLine.VY, pen));
             lines.Add(new Segment2D(this.Point2, endPoint, pen));

             return lines;
        }
Exemplo n.º 5
0
        public override float DistanceTo(PointF point)
        {
            if (this.Point1 == point || this.Point2 == point)
            {
                return 0;
            }

            // Calculate orhogonal line
            Line2D orthoLine = this.GetNormalLine(point);

            // Calculate Intersection
            PointF point3 = new Line2D(this.Point1, this.Point2).Intersection(orthoLine);

            if (this.ContainsAbsciss(point3.X))
            {
                // Calculate the length on the ortho segment
                Segment2D segment = new Segment2D(point, point3);
                return segment.Length();
            }
            else
            {
                Segment2D segment1 = new Segment2D(point, this.Point1);
                Segment2D segment2 = new Segment2D(point, this.Point2);
                return Math.Min(segment1.Length(), segment2.Length());
            }
        }
Exemplo n.º 6
0
 public override Segment2D Trim(Rectangle2D rect)
 {
     Segment2D segment = new Segment2D();
     if (rect.Contains(this.Point1))
     {
         segment.Point1 = this.Point1;
         PointF[] points = this.Intersection(rect);
         if (points.Length == 1)
         {
             segment.Point2 = points[0];
         }
         else
         {
             StockLog.Write("Exception");
         }
     }
     else
     {
         return new Line2D(this.Point1, this.Point2).Trim(rect);
     }
     return segment;
 }
Exemplo n.º 7
0
 protected void DrawTmpSegment(Graphics graph, Pen pen, PointF point1, PointF point2, bool useTransform, bool temporary)
 {
     // Calculate intersection with bounding rectangle
      Rectangle2D rect2D = new Rectangle2D(GraphRectangle);
      Segment2D newLine = new Segment2D(point1, point2);
      if (useTransform)
      {
     newLine.Draw(graph, pen, this.matrixValueToScreen, rect2D, this.IsLogScale);
      }
      else
      {
     newLine.Draw(graph, pen, GraphControl.matrixIdentity, rect2D, false);
      }
 }
Exemplo n.º 8
0
        public PointF Intersection(Segment2D segment)
        {
            Line2D line1 = new Line2D(this.Point1, this.Point2);
            Line2D line2 = new Line2D(segment.Point1, segment.Point2);
            PointF result = line1.Intersection(line2);

            if (result != PointF.Empty)
            {
                if (!new Rectangle2D(this.Point1, this.Point2).Contains(result) || !new Rectangle2D(segment.Point1, segment.Point2).Contains(result))
                {
                    result = PointF.Empty;
                }
            }
            return result;
        }
Exemplo n.º 9
0
 private void MouseClickDrawing(System.Windows.Forms.MouseEventArgs e, ref PointF mousePoint, ref PointF mouseValuePoint)
 {
     switch (this.DrawingMode)
     {
         case GraphDrawMode.AddLine:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Selecting the first point
                     selectedValuePoint = mouseValuePoint;
                     this.DrawingStep = GraphDrawingStep.ItemSelected;
                     break;
                 case GraphDrawingStep.ItemSelected: // Selecting second point
                     PointF point1 = selectedValuePoint;
                     PointF point2 = mouseValuePoint;
                     try
                     {
                         Line2D newLine = new Line2D(point1, point2, this.DrawingPen);
                         drawingItems.Add(newLine);
                         AddToUndoBuffer(GraphActionType.AddItem, newLine);
                         this.DrawingStep = GraphDrawingStep.SelectItem;
                         this.BackgroundDirty = true; // The new line becomes a part of the background
                         selectedLineIndex = -1;
                     }
                     catch (System.ArithmeticException)
                     {
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.AddSegment:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Selecting the first point
                     selectedValuePoint = mouseValuePoint;
                     this.DrawingStep = GraphDrawingStep.ItemSelected;
                     break;
                 case GraphDrawingStep.ItemSelected: // Selecting second point
                     PointF point1 = selectedValuePoint;
                     PointF point2 = mouseValuePoint;
                     try
                     {
                         Segment2D newSegment = new Segment2D(point1, point2, this.DrawingPen);
                         drawingItems.Add(newSegment);
                         AddToUndoBuffer(GraphActionType.AddItem, newSegment);
                         this.DrawingStep = GraphDrawingStep.SelectItem;
                         this.BackgroundDirty = true; // The new line becomes a part of the background
                         selectedLineIndex = -1;
                     }
                     catch (System.ArithmeticException)
                     {
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.AddHalfLine:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Selecting the first point
                     selectedValuePoint = mouseValuePoint;
                     this.DrawingStep = GraphDrawingStep.ItemSelected;
                     break;
                 case GraphDrawingStep.ItemSelected: // Selecting second point
                     PointF point1 = selectedValuePoint;
                     PointF point2 = mouseValuePoint;
                     try
                     {
                         HalfLine2D newhalfLine = new HalfLine2D(point1, point2, this.DrawingPen);
                         drawingItems.Add(newhalfLine);
                         AddToUndoBuffer(GraphActionType.AddItem, newhalfLine);
                         this.DrawingStep = GraphDrawingStep.SelectItem;
                         this.BackgroundDirty = true; // The new line becomes a part of the background
                         selectedLineIndex = -1;
                     }
                     catch (System.ArithmeticException)
                     {
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.FanLine:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Selecting the first point
                     selectedValuePoint = mouseValuePoint;
                     this.DrawingStep = GraphDrawingStep.ItemSelected;
                     break;
                 case GraphDrawingStep.ItemSelected: // Selecting second point
                     PointF point1 = selectedValuePoint;
                     PointF point2 = mouseValuePoint;
                     try
                     {
                         Line2D newLine = (Line2D)new Line2D(point1, point2, this.DrawingPen);
                         drawingItems.Add(newLine);
                         AddToUndoBuffer(GraphActionType.AddItem, newLine);
                         this.BackgroundDirty = true; // The new line becomes a part of the background
                         selectedLineIndex = -1;
                     }
                     catch (System.ArithmeticException)
                     {
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.AndrewPitchFork:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Selecting the first point
                     if (andrewPitchFork == null)
                     {
                         andrewPitchFork = new AndrewPitchFork(mouseValuePoint, PointF.Empty, PointF.Empty);
                     }
                     else
                     {
                         // Selecting second point
                         andrewPitchFork.Point2 = mouseValuePoint;
                         this.DrawingStep = GraphDrawingStep.ItemSelected;
                     }
                     break;
                 case GraphDrawingStep.ItemSelected: // Selecting third point
                     andrewPitchFork.Point3 = mouseValuePoint;
                     try
                     {
                         foreach (Line2DBase newLine in andrewPitchFork.GetLines(this.DrawingPen))
                         {
                             drawingItems.Add(newLine);
                             AddToUndoBuffer(GraphActionType.AddItem, newLine);
                         }
                         this.BackgroundDirty = true; // The new line becomes a part of the background
                         selectedLineIndex = -1;
                         this.DrawingStep = GraphDrawingStep.SelectItem;
                         andrewPitchFork = null;
                     }
                     catch (System.ArithmeticException)
                     {
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.CopyLine:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Select the line to copy
                     selectedLineIndex = FindClosestLine(mousePoint);
                     if (selectedLineIndex != -1)
                     {
                         this.DrawingStep = GraphDrawingStep.ItemSelected;
                     }
                     break;
                 case GraphDrawingStep.ItemSelected: // Create new // line
                     if (selectedLineIndex != -1)
                     {
                         Line2D newLine = ((Line2DBase)this.drawingItems[selectedLineIndex]).GetParallelLine(mouseValuePoint);
                         newLine.Pen = this.DrawingPen;
                         drawingItems.Add(newLine);
                         AddToUndoBuffer(GraphActionType.AddItem, newLine);
                         this.DrawingStep = GraphDrawingStep.SelectItem;
                         selectedLineIndex = -1;
                         this.BackgroundDirty = true; // The new line becomes a part of the background
                         HighlightClosestLine(e);
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.DeleteItem:
             switch (this.DrawingStep)
             {
                 case GraphDrawingStep.SelectItem: // Delete element
                     selectedLineIndex = FindClosestLine(mousePoint);
                     if (selectedLineIndex != -1)
                     {
                         DrawingItem removeLine = this.drawingItems.ElementAt(selectedLineIndex);
                         this.drawingItems.RemoveAt(selectedLineIndex);
                         AddToUndoBuffer(GraphActionType.DeleteItem, removeLine);
                         this.BackgroundDirty = true; // New to redraw the background
                         HighlightClosestLine(e);
                     }
                     break;
                 default:   // Shouldn't come there
                     break;
             }
             break;
         case GraphDrawMode.CutLine:
             if (this.DrawingStep == GraphDrawingStep.SelectItem)
             {
                 selectedLineIndex = FindClosestLine(mousePoint);
                 if (selectedLineIndex != -1) // #### Check if visible to avoid cutting out of scope items
                 {
                     Line2DBase itemToCut = (Line2DBase)this.drawingItems.ElementAt(selectedLineIndex);
                     Line2DBase cutItem = itemToCut.Cut(mouseValuePoint.X, (Control.ModifierKeys & Keys.Control) == 0);
                     if (cutItem != null)
                     {
                         this.drawingItems.RemoveAt(selectedLineIndex);
                         this.drawingItems.Add(cutItem);
                         AddToUndoBuffer(GraphActionType.CutItem, itemToCut, cutItem);
                         this.BackgroundDirty = true; // New to redraw the background
                         HighlightCutLine(e, mouseValuePoint, (Control.ModifierKeys & Keys.Control) == 0);
                     }
                 }
             }
             break;
         default:
             break;
     }
 }
Exemplo n.º 10
0
 private PointF FindClosestExtremum(PointF mouseValuePoint)
 {
     int selectedIndex = (int)Math.Round(mouseValuePoint.X);
     PointF returnPoint;
     Segment2D segment1, segment2;
     FloatSerie highSerie = highCurveType.DataSerie;
     FloatSerie lowSerie = lowCurveType.DataSerie;
     segment1 = new Segment2D(mouseValuePoint.X, mouseValuePoint.Y, selectedIndex, highSerie[selectedIndex]);
     segment2 = new Segment2D(mouseValuePoint.X, mouseValuePoint.Y, selectedIndex, lowSerie[selectedIndex]);
     if (segment1.Length() < segment2.Length())
     {
         returnPoint = new PointF(selectedIndex, highSerie[selectedIndex]);
     }
     else
     {
         returnPoint = new PointF(selectedIndex, lowSerie[selectedIndex]);
     }
     return returnPoint;
 }