private Point2D ClipLineSegment(Point2D p0, Point2D p1, Rectangle2D e)
{
Point2D point = new Point2D(p1.X, p1.Y);
if (p1.X < e.Left)
{
point = EdgeIntersection(p0, p1, e.Left, false);
}
else if (p1.X > e.Right)
{
point = EdgeIntersection(p0, p1, e.Right, false);
}
if (point.Y < e.Bottom)
{
return EdgeIntersection(p0, p1, e.Bottom, true);
}
if (point.Y > e.Top)
{
point = EdgeIntersection(p0, p1, e.Top, true);
}
return point;
}