cone-geometry.c
// Bresenham's line algorithm (from Rosetta Code)
Bresenham's line algorithm (from Rosetta Code)
Bresenham ' s line algorithm ( from Rosetta Code )
void line(int x0, int y0, int x1, int y1, line_callback cb, void *ptr) {
    int dx = abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
    int dy = abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
    int err = (dx > dy ? dx : -dy) / 2, e2;
    while (1) {
        cb(x0, y0, ptr);
        if (x0 == x1 && y0 == y1) break;
        e2 = err;
        if (e2 > -dx) {
            err -= dy;
            x0 += sx;
        }
        if (e2 < dy) {
            err += dx;
            y0 += sy;
        }
    }
}
void line ( int x0 , int y0 , int x1 , int y1 , line_callback cb , void * ptr ) { int dx = abs ( x1 - x0 ) , sx = x0 < x1 ? 1 : -1 ; int dy = abs ( y1 - y0 ) , sy = y0 < y1 ? 1 : -1 ; int err = ( dx > dy ? dx : - dy ) / 2 , e2 ; while ( 1 ) { cb ( x0 , y0 , ptr ) ; if ( x0 == x1 && y0 == y1 ) break ; e2 = err ; if ( e2 > - dx ) { err -= dy ; x0 += sx ; } if ( e2 < dy ) { err += dx ; y0 += sy ; } } }
Bresenham's line algorithm (from Rosetta Code)
Bresenham ' s line algorithm ( from Rosetta Code )