I want to render a line segment onto a virtual integer space in minimum average time for any segment orientation/length. The segment is defined by two points with real number values (doubles).
I have already come up with several ideas that would probably work, but they strike me as horrific, heuristic hacks. (I.e. There is a clear “better direction” to begin from depending on orientation of the segment).
Surely there is a better way than the brute force method (find the “long” direction (x- or y-axis) between the end points then step along each integer value along that axis and round the value in the orthogonal axis to determine exactly one pixel (integer point) location at every integer value along the “long” axis.)
What you say regarding the “better direction” reminds me of the Bresenham line algorithm, is this maybe what you want?
http://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresenh.html
[edit]
The difference with non-integer endpoints wasn’t obvious to me but there’s an illustration here.
As you’re drawing one pixel per integer span on the long axis I’m assuming your drawing points with equal intensity (no antialiasing).
So you can just implement bresenham without the integer optimisation (what you did already) and round points at the end.
Or use fixed point math through integer bresenham (i.e. multiply your coordinates by 65536 and round, run bresenham with a longer step on the long axis, and divide or shift the output points back down to the required values before drawing).
But depending whether you are drawing fonts, or tesellated curves, or wireframe rectangles it might look better with straight bresenhams or with an antialiasing algorithm.