I tried dropping my line plotter into your code, and I see what you mean, it did break.
I've not used any of M's math optimisations yet, so that's why I'm not getting any negative widths ( I guess ).
I think this is me done with the line plotter, maths next.
The two new "special case" checks may seem overkill, but in the example they happen a fair bit.Code:private function quickLine(x1:int,y1:int):void{ var i:int; var cumul:int; var x0:int=x; var y0:int=y; var dxL:int= x1 - x0; var dyL:int= y1 - y0; var xinc:int = ( dxL > 0 ) ? 1 : -1; var yinc:int = ( dyL > 0 ) ? 1 : -1; dxL = (dxL ^ (dxL >> 31)) - (dxL >> 31); //Math.abs dyL = (dyL ^ (dyL >> 31)) - (dyL >> 31); var c:Number=0xDD073C89; //Test for a straight vertical line if(dxL==0){ bitmap.fillRect(new Rectangle(x0,y0,1,dyL),c) return; } else { //Horizontal line ? if(dyL==0){ bitmap.fillRect(new Rectangle(x0,y0,dxL,1),c) return; } else { //Vertical line with just one step ? if(dxL==1){ var halfHeight:int=dyL>>1; bitmap.fillRect(new Rectangle(x0,y0,1,halfHeight),c); bitmap.fillRect(new Rectangle(x1,y1-halfHeight,1,halfHeight),c); return; } else { //Horizontal line with just one step ? if(dyL==1){ var halfWidth:int=dxL>>1; bitmap.fillRect(new Rectangle(x0,y0,halfWidth,1),c); bitmap.fillRect(new Rectangle(x1-halfWidth,y1,halfWidth,1),c); return; } } } } //None of the above, so let's check which is the major axis and do our thing if ( dxL > dyL ){ i = cumul = dxL >> 1; while(--i>-1){ x0 += xinc; x1 -= xinc; cumul += dyL; if (cumul >= dxL){ cumul -= dxL; y0 += yinc; y1 -= yinc; } bitmap.setPixel32(x0,y0,c); bitmap.setPixel32(x1,y1,c); } }else{ i = cumul = dyL >> 1; while(--i>-1){ y0 += yinc; y1 -= yinc; cumul += dxL; if ( cumul >= dyL ){ cumul -= dyL; x0 += xinc ; x1 -= xinc ; } bitmap.setPixel32(x0,y0,c); bitmap.setPixel32(x1,y1,c); } } }
I think from here the only things I can think of is some tests for diagonal lines, and ordering the conditionals differently ( So the normal line plotter routines are tested first, then if it's not one of them try the special cases ).
Squize.





Reply With Quote