drawLineXOR method

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

Implementation

void drawLineXOR( int x1, int y1, int x2, int y2 ){
	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;
		}
		putXOR( x1, y1 );
		s = dx ~/ 2;
		while( ++x1 <= x2 ){
			if( (s -= dy) < 0 ){
				s += dx;
				y1 += step;
			}
			putXOR( 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;
		}
		putXOR( x1, y1 );
		s = dy ~/ 2;
		while( ++y1 <= y2 ){
			if( (s -= dx) < 0 ){
				s += dy;
				x1 += step;
			}
			putXOR( x1, y1 );
		}
	}
}