Recently I had to write an algorithm to draw vertical, horizontal and 45 deg lines. I wanted that algorithm just to works as fast as possible so I extended all the possible cases :
if (x0 == x1){
...
}
else if (y0 == y1)
{
...
}
else {
if (distance(x0,x1) == distance(y0,y1)){
...
}
}
and of course, this is not DRY nor clean...
What's the cleanest and better version of an algorithm like that?
Notice that if the line is not vertical, horizontal or 45deg the function should do nothing (so nothing like raster algorithm).
An example of declaration can be line(int x0, int y0, int x1, int y1);