pea
developer
Hi all,
Though it is a relatively simple task, to save me coding it from scratch, does anybody have a function that crops a line segment to fit a bounding area? Pref. floating point (I will convert it to fixed point).
Example.
I have the line p1 = -50,-50; p2 = 400,300;
This line obviously is longer than the screen, and starts and ends out of the screen.
The slow way would be to simply calculate each pixel, then test whether it is on the screen, and then draw it if it is.
The faster way would be to calculate new endpoints based on a bounding rect (the screen) and then draw the line with no testing to see if it is on the screen.
There is the overhead of recalculating the end points, but this will hopefully be faster than calculating the position of all the pixels that aren't actually drawn, and the checking of each and every pixel to be within the bounds.
I already have a half-pie implementation which I wrote that draws antialised lines based on the wu principle (very fast antialiasing), but it currently only crops the x axis. I am sure someone has come up with a fast crop routine in the past.
Though it is a relatively simple task, to save me coding it from scratch, does anybody have a function that crops a line segment to fit a bounding area? Pref. floating point (I will convert it to fixed point).
Example.
I have the line p1 = -50,-50; p2 = 400,300;
This line obviously is longer than the screen, and starts and ends out of the screen.
The slow way would be to simply calculate each pixel, then test whether it is on the screen, and then draw it if it is.
The faster way would be to calculate new endpoints based on a bounding rect (the screen) and then draw the line with no testing to see if it is on the screen.
There is the overhead of recalculating the end points, but this will hopefully be faster than calculating the position of all the pixels that aren't actually drawn, and the checking of each and every pixel to be within the bounds.
I already have a half-pie implementation which I wrote that draws antialised lines based on the wu principle (very fast antialiasing), but it currently only crops the x axis. I am sure someone has come up with a fast crop routine in the past.