/// <summary> /// Extend a line the specified distance in either/both directions /// <para>This method is immutable</para> /// </summary> /// <param name="bottomLeftExtension">The amount to extend the logical bottom left length of the line</param> /// <param name="topRightExtension">The amount to extend the logical top right length of the line</param> /// <returns>A new line with the extensions added as required</returns> public Line2D <T> Extend(T bottomLeftExtension, T topRightExtension) { Point2D <T> p1 = Ends[0]; Point2D <T> p2 = Ends[1]; T adj = (dynamic)p2.X - p1.X; T opp = (dynamic)p2.Y - p1.Y; double divisor = (double)(dynamic)opp / (double)(dynamic)adj; double atan = Math.Atan(divisor); double angle = MathsUtils.ToDegrees(atan); if ((dynamic)opp == 0) { if ((dynamic)p1.X > p2.X) { angle = 180; } } if ((dynamic)adj == 0) { if ((dynamic)p1.Y > p2.Y) { angle = 270; } } if ((dynamic)topRightExtension != 0) { p2 = p2.LocatePointAtDistance(angle, topRightExtension); } if ((dynamic)bottomLeftExtension != 0) { p1 = p1.LocatePointAtDistance(angle + 180, bottomLeftExtension); } return(new Line2D <T>(p1, p2)); }