private double GetMouseDistance_Helper(Point p, double _FromX, double _FromY, double _ToX, double _ToY) { double max = 99999; Line2D l2d = Geometry2D.GetLine2DFromPoints(_FromX, _FromY, _ToX, _ToY); if (p.X + Diagram.lineSelectionDelta < Math.Min(_FromX, _ToX) || p.X - Diagram.lineSelectionDelta > Math.Max(_FromX, _ToX) || p.Y + Diagram.lineSelectionDelta < Math.Min(_FromY, _ToY) || p.Y - Diagram.lineSelectionDelta > Math.Max(_FromY, _ToY)) { return(max); } return(Geometry2D.GetPointDistanceFrom2DLine(l2d, p)); }
public override Point GetLineAnchorLocation(DiagramItemBase toItem, Point toPoint, int toItemDiagramLinesCount, int toItemDiagramLinesNumber, bool isSelfStart) { Point p = new Point(); Point p2 = new Point(); Point pTo = new Point(); Line2D firstLineSelf; if (toItem != null) { pTo.X = Canvas.GetLeft(toItem) + toItem.ActualWidth / 2; pTo.Y = Canvas.GetTop(toItem) + toItem.ActualHeight / 2; } else { pTo = toPoint; } double tX = Canvas.GetLeft(this) + this.ActualWidth / 2; double tY = Canvas.GetTop(this) + this.ActualHeight / 2; double testX = pTo.X - tX; double testY = pTo.Y - tY; if (testX == 0) { testX = 0.001; } if (testY == 0) { testY = 0.001; } double ovalX = Canvas.GetLeft(this) + this.Width / 2; double ovalY = Canvas.GetTop(this) + this.Height / 2; double ovalR2 = this.Width / 2; double ovalR1 = this.Height / 2; Oval o = new Oval(ovalX, ovalY, ovalR1, ovalR2); if (toItemDiagramLinesCount > 1) { if (toItem == this) { if (isSelfStart) { p.X = Canvas.GetLeft(this) + ((((double)toItemDiagramLinesNumber) / 2 + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p.Y = tY - this.ActualHeight / 2; p2.X = Canvas.GetLeft(this) + ((((double)toItemDiagramLinesNumber) / 2 + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p2.Y = tY - this.ActualHeight; firstLineSelf = Geometry2D.GetLine2DFromPoints(p, p2); return(Geometry2D.GetOvalLineCross(firstLineSelf, o)[0]); } else { p.X = tX + this.ActualWidth / 2; p.Y = Canvas.GetTop(this) + (((double)(toItemDiagramLinesCount - ((double)toItemDiagramLinesNumber) / 2)) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); p2.X = tX + this.ActualWidth; p2.Y = Canvas.GetTop(this) + (((double)(toItemDiagramLinesCount - ((double)toItemDiagramLinesNumber) / 2)) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); firstLineSelf = Geometry2D.GetLine2DFromPoints(p, p2); return(Geometry2D.GetOvalLineCross(firstLineSelf, o)[1]); } } Point pFrom = new Point(); pFrom.X = tX; if (testY <= 0) { pFrom.Y = Canvas.GetTop(this) + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight / 2); } else { pFrom.Y = tY + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight / 2); } Line2D firstLine = Geometry2D.GetLine2DFromPoints(pTo, pFrom); // we have two: // - line from pTo to pFrom (firstLine) // - oval if (testY <= 0 && testX <= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[0]); } if (testY <= 0 && testX >= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[1]); } if (testY >= 0 && testX >= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[1]); } if (testY >= 0 && testX <= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[0]); } } else { if (toItem == this) { if (isSelfStart) { p.X = tX; p.Y = tY - this.ActualHeight / 2; return(p); } else { p.X = tX + this.ActualWidth / 2; p.Y = tY; return(p); } } Point pFrom = new Point(); pFrom.X = tX; pFrom.Y = tY; Line2D firstLine = Geometry2D.GetLine2DFromPoints(pTo, pFrom); if (testY <= 0 && testX <= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[0]); } if (testY <= 0 && testX >= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[1]); } if (testY >= 0 && testX >= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[1]); } if (testY >= 0 && testX <= 0) { return(Geometry2D.GetOvalLineCross(firstLine, o)[0]); } } return(p); }
public override Point GetLineAnchorLocation(DiagramItemBase toItem, Point toPoint, int toItemDiagramLinesCount, int toItemDiagramLinesNumber, bool isSelfStart) { Point p = new Point(); Point p2 = new Point(); Point pTo = new Point(); Point pRhombus1 = new Point(); Point pRhombus2 = new Point(); Line2D secondLine, firstLineSelf; if (toItem != null) { pTo.X = Canvas.GetLeft(toItem) + toItem.ActualWidth / 2; pTo.Y = Canvas.GetTop(toItem) + toItem.ActualHeight / 2; } else { pTo = toPoint; } double tX = Canvas.GetLeft(this) + this.ActualWidth / 2; double tY = Canvas.GetTop(this) + this.ActualHeight / 2; double testX = pTo.X - tX; double testY = pTo.Y - tY; if (testX == 0) { testX = 0.001; } if (testY == 0) { testY = 0.001; } if (toItemDiagramLinesCount > 1) { if (toItem == this) { if (isSelfStart) { p.X = Canvas.GetLeft(this) + ((((double)toItemDiagramLinesNumber) / 2 + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p.Y = tY - this.ActualHeight / 2; p2.X = Canvas.GetLeft(this) + ((((double)toItemDiagramLinesNumber) / 2 + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualWidth); p2.Y = tY - this.ActualHeight; firstLineSelf = Geometry2D.GetLine2DFromPoints(p, p2); pRhombus1.X = Canvas.GetLeft(this); pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this); } else { p.X = tX + this.ActualWidth / 2; p.Y = Canvas.GetTop(this) + (((double)(toItemDiagramLinesCount - ((double)toItemDiagramLinesNumber) / 2)) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); p2.X = tX + this.ActualWidth; p2.Y = Canvas.GetTop(this) + (((double)(toItemDiagramLinesCount - ((double)toItemDiagramLinesNumber) / 2)) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight); firstLineSelf = Geometry2D.GetLine2DFromPoints(p, p2); pRhombus1.X = Canvas.GetLeft(this) + this.ActualWidth; pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this) + this.ActualHeight; } secondLine = Geometry2D.GetLine2DFromPoints(pRhombus1, pRhombus2); return(Geometry2D.FindLineCross(firstLineSelf, secondLine)); } Point pFrom = new Point(); pFrom.X = tX; if (testY <= 0) { pFrom.Y = Canvas.GetTop(this) + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight / 2); } else { pFrom.Y = tY + (((double)toItemDiagramLinesNumber + 1) / ((double)toItemDiagramLinesCount + 1) * this.ActualHeight / 2); } Line2D firstLine = Geometry2D.GetLine2DFromPoints(pTo, pFrom); // we have two lines: // - from pTo to pFrom (firstLine) // - from pRhombus1 to pRhombus2 (secondLine - depending on the rhombus side) if (testY <= 0 && testX <= 0) { pRhombus1.X = Canvas.GetLeft(this); pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this); } if (testY <= 0 && testX >= 0) { pRhombus1.X = Canvas.GetLeft(this) + this.ActualWidth; pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this); } if (testY >= 0 && testX >= 0) { pRhombus1.X = Canvas.GetLeft(this) + this.ActualWidth; pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this) + this.ActualHeight; } if (testY >= 0 && testX <= 0) { pRhombus1.X = Canvas.GetLeft(this); pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this) + this.ActualHeight; } secondLine = Geometry2D.GetLine2DFromPoints(pRhombus1, pRhombus2); return(Geometry2D.FindLineCross(firstLine, secondLine)); } else { if (toItem == this) { if (isSelfStart) { p.X = tX; p.Y = tY - this.ActualHeight / 2; return(p); } else { p.X = tX + this.ActualWidth / 2; p.Y = tY; return(p); } } Point pFrom = new Point(); pFrom.X = tX; pFrom.Y = tY; Line2D firstLine = Geometry2D.GetLine2DFromPoints(pTo, pFrom); pRhombus1 = new Point(); pRhombus2 = new Point(); // we have two lines: // - from pTo to pFrom (firstLine) // - from pRhombus1 to pRhombus2 (secondLine - depending on the rhombus side) if (testY <= 0 && testX <= 0) { pRhombus1.X = Canvas.GetLeft(this); pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this); } if (testY <= 0 && testX >= 0) { pRhombus1.X = Canvas.GetLeft(this) + this.ActualWidth; pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this); } if (testY >= 0 && testX >= 0) { pRhombus1.X = Canvas.GetLeft(this) + this.ActualWidth; pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this) + this.ActualHeight; } if (testY >= 0 && testX <= 0) { pRhombus1.X = Canvas.GetLeft(this); pRhombus1.Y = tY; pRhombus2.X = tX; pRhombus2.Y = Canvas.GetTop(this) + this.ActualHeight; } secondLine = Geometry2D.GetLine2DFromPoints(pRhombus1, pRhombus2); return(Geometry2D.FindLineCross(firstLine, secondLine)); } return(p); }