/// <summary> /// Creates a new instance of <see cref="Line2D"/>. /// </summary> /// <param name="p1">The first point.</param> /// <param name="p2">The second point.</param> public Line2D(Point2D p1, Point2D p2) { Point1 = p1; Point2 = p2; p1.Changed += OnPointChanged; p2.Changed += OnPointChanged; }
/// <summary> /// Invoked when a point has changed. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="args">The event arguments.</param> void OnPointChanged(Point2D source, PointChangedEventArgs args) { OnChanged(); }
internal static Line2D GetParallelLine(Point p1, Point p2, Point directionPoint, double offset) { Point2D linePoint1 = new Point2D(); Point2D linePoint2 = new Point2D(); double dx = p1.X - p2.X; double dy = p1.Y - p2.Y; double leght = Math.Sqrt((dx) * (dx) + (dy) * (dy)); // Determine the direction of the offset. offset *= GetPointPosition(p1, p2, directionPoint); // This is the parallel line linePoint1.X = (p1.X - offset * (dy) / leght); linePoint2.X = (p2.X - offset * (dy) / leght); linePoint1.Y = (p1.Y + offset * (dx) / leght); linePoint2.Y = (p2.Y + offset * (dx) / leght); Line2D parallelLine = new Line2D(linePoint1, linePoint2); return parallelLine; }