private static Point2D EdgeIntersection(Point2D p0, Point2D p1, double val, bool horizontal)
{
Point2D point = new Point2D(p1.X - p0.X, p1.Y - p0.Y);
if (horizontal)
{
return new Point2D(p0.X + ((point.X / point.Y) * (val - p0.Y)), val);
}
return new Point2D(val, p0.Y + ((point.Y / point.X) * (val - p0.X)));
}
}