drawLine method

void drawLine(
  1. int x1,
  2. int y1,
  3. int x2,
  4. int y2,
)

Implementation

void drawLine( int x1, int y1, int x2, int y2 ){
	gWorldLine( this, x1, y1, x2, y2 );
	_gWorldPut = false;

	int dx, dy;
	int step;
	int temp;
	int s;

	dx = ClipMath.abs( (x2 - x1).toDouble() ).toInt();
	dy = ClipMath.abs( (y2 - y1).toDouble() ).toInt();
	if( dx > dy ){
		if( x1 > x2 ){
			step = (y1 > y2) ? 1 : -1;
			temp = x1; x1 = x2; x2 = temp;
			y1 = y2;
		} else {
			step = (y1 < y2) ? 1 : -1;
		}
		put( x1.toInt(), y1.toInt() );
		s = dx ~/ 2;
		while( ++x1 <= x2 ){
			if( (s -= dy) < 0 ){
				s += dx;
				y1 += step;
			}
			put( x1, y1 );
		}
	} else {
		if( y1 > y2 ){
			step = (x1 > x2) ? 1 : -1;
			temp = y1; y1 = y2; y2 = temp;
			x1 = x2;
		} else {
			step = (x1 < x2) ? 1 : -1;
		}
		put( x1, y1 );
		s = dy ~/ 2;
		while( ++y1 <= y2 ){
			if( (s -= dx) < 0 ){
				s += dy;
				x1 += step;
			}
			put( x1, y1 );
		}
	}

	_gWorldPut = true;
}