public float Distance(PointF p) { if (LineEquation.IsBetween(line.GetNormalAt(A), p, line.GetNormalAt(B))) { return(line.Distance(p)); } return(Math.Min(Distance(A, p), Distance(B, p))); }
public PointF?IntersectAtDistance(LineSegment segmentToCut, float width) { // always assuming other.A is the farthest end var distance = width * (line.IsAboveOrRightOf(segmentToCut.A) ? 1 : -1); var parallelLine = line.GetParallelLine(distance); var p = parallelLine.Intersect(segmentToCut.line); if (p.HasValue) { if (LineEquation.IsBetween(line.GetNormalAt(A), p.Value, line.GetNormalAt(B)) && segmentToCut.bindingRectangle.Contains(p.Value)) { return(p); } } List <PointF> points = new List <PointF>(); points.AddRange(segmentToCut.line.Intersect(new CircleEquation(width, A))); points.AddRange(segmentToCut.line.Intersect(new CircleEquation(width, B))); return(GetNearestPoint(segmentToCut.A, points)); }