Hi,
My question is regarding a modification I was considering making to the Cohen-Sutherland algorithm to remove the need for a loop, specifically I want to know if the performance benefits of such a modification would outweigh the downside of the extra calculations. The modification I am making is this:
In the original algorithm, lines are clipped first against the vertical and then against the horizontal edges, so in worst case a line may need to be clipped 4 times, twice on each end. I modified the algorithm to use two slopes -- the slope of the line itself, and the line between the outer endpoint and the corner of the clipping region, to determine whether to clip the line against the vertical or the horizontal boundary. The code (in Java) looks like this:
...

double x = p1.getX();
double y = p1.getY();
double cornerSlope = (y - ymax)/(x - xmax);
double lineSlope = (y - p2.getY()) / (x - p2.getX());
if(cornerSlope < lineSlope) {
// chop against top edge
double yClipped = ymax;
double xClipped = (y - ymax) / lineSlope;
return new Point2D.Double(xClipped, yClipped);
} else {
// chop against left edge
....
}
...
Above is just a snippet of a function that is part of the algorithm, it is called after trivial accept/reject cases have been handled and returns the intersect point given p1 as the outer point and p2 as either the inner or the outer point (outer/inner with respect to the clipping region). It's called twice with parameters flipped if the line sticks out on both ends.

So I was wondering whether it is better to clip twice on each end as in original algorithm or use this modification, calculate the slopes, and clip only once on each end? Also, is this something that maybe is well-known/has been done/documented/has a name/etc.? Please forgive /correct any mistakes as I'm a bit new to this and I just coded this tonight/this morning. Thanks for any replies.