Permalink
Browse files

efla: fixed typo, minor optimizations, allowed for transparency, adde…

…d a TODO
  • Loading branch information...
1 parent 6bc1459 commit b7f6d01969437fcca282acf1d2d6021930b54be2 @skyboy committed Mar 2, 2011
Showing with 32 additions and 30 deletions.
  1. +32 −30 skyboy/utils/efla.as
View
@@ -2,57 +2,58 @@ package skyboy.utils {
import flash.display.BitmapData;
/**
- * "Extremely Fast Line Algorithm"
- * @author Po-Han Lin (original version: http://www.edepot.com/algorithm.html)
- * @author Simo Santavirta (AS3 port: http://www.simppa.fi/blog/?p=521)
- * @author Jackson Dunstan (minor formatting: http://jacksondunstan.com/articles/506)
- * @author skyboy (optimization for 10.1+)
- * @param bmd Bitmap to draw on
- * @param x X component of the start point
- * @param y Y component of the start point
- * @param x2 X component of the end point
- * @param y2 Y component of the end point
- * @param color Color of the line
- */
+ * "Extremely Fast Line Algorithm"
+ * @author Po-Han Lin (original version: http://www.edepot.com/algorithm.html)
+ * @author Simo Santavirta (AS3 port: http://www.simppa.fi/blog/?p=521)
+ * @author Jackson Dunstan (minor formatting: http://jacksondunstan.com/articles/506)
+ * @author skyboy (optimization for 10.1+)
+ * @param BitmapData: bmd Bitmap to draw on
+ * @param int: x X component of the start point
+ * @param int: y Y component of the start point
+ * @param int: x2 X component of the end point
+ * @param int: y2 Y component of the end point
+ * @param uint: color Color of the line
+ */
public function efla(bmd:BitmapData, x:int, y:int, x2:int, y2:int, color:uint):void {
- if (y2 == y) if (x2 == x) return;
var shortLen:int = y2 - y;
var longLen:int = x2 - x;
+ if (!longLen) if (!shortLen) return;
var i:int, id:int, inc:int;
var multDiff:Number;
bmd.lock();
- bmd.setPixel(x, y, color);
+ // TODO: check for this above, swap x/y/len and optimize loops to ++ and -- (operators twice as fast, still only 2 loops)
if ((shortLen ^ (shortLen >> 31)) - (shortLen >> 31) > (longLen ^ (longLen >> 31)) - (longLen >> 31)) {
if (shortLen < 0) {
inc = -1;
- id = -shortLen % 3;
+ id = -shortLen % 4;
} else {
inc = 1;
- id = shortLen % 3;
+ id = shortLen % 4;
}
- multDiff = shortLen == 0 ? longLen : longLen / shortLen;
+ multDiff = !shortLen ? longLen : longLen / shortLen;
if (id) {
+ bmd.setPixel32(x, y, color);
i += inc;
if (--id) {
- bmd.setPixel(x + i * multDiff, y + i, color);
+ bmd.setPixel32(x + i * multDiff, y + i, color);
i += inc;
if (--id) {
- bmd.setPixel(x + i * multDiff, y + i, color);
+ bmd.setPixel32(x + i * multDiff, y + i, color);
i += inc;
}
}
}
while (i != shortLen) {
- bmd.setPixel(x + i * multDiff, y + i, color);
+ bmd.setPixel32(x + i * multDiff, y + i, color);
i += inc;
- bmd.setPixel(x + i * multDiff, y + i, color);
+ bmd.setPixel32(x + i * multDiff, y + i, color);
i += inc;
- bmd.setPixel(x + i * multDiff, y + i, color);
+ bmd.setPixel32(x + i * multDiff, y + i, color);
i += inc;
- bmd.setPixel(x + i * multDiff, y + i, color);
+ bmd.setPixel32(x + i * multDiff, y + i, color);
i += inc;
}
} else {
@@ -63,27 +64,28 @@ package skyboy.utils {
inc = 1;
id = longLen % 4;
}
- multDiff = longLen == 0 ? shortLen : shortLen / longLen;
+ multDiff = !longLen ? shortLen : shortLen / longLen;
if (id) {
+ bmd.setPixel32(x, y, color);
i += inc;
if (--id) {
- bmd.setPixel(x + i, y + i * multDiff, color);
+ bmd.setPixel32(x + i, y + i * multDiff, color);
i += inc;
if (--id) {
- bmd.setPixel(x + i, y + i * multDiff, color);
+ bmd.setPixel32(x + i, y + i * multDiff, color);
i += inc;
}
}
}
while (i != longLen) {
- bmd.setPixel(x + i, y + i * multDiff, color);
+ bmd.setPixel32(x + i, y + i * multDiff, color);
i += inc;
- bmd.setPixel(x + i, y + i * multDiff, color);
+ bmd.setPixel32(x + i, y + i * multDiff, color);
i += inc;
- bmd.setPixel(x + i, y + i * multDiff, color);
+ bmd.setPixel32(x + i, y + i * multDiff, color);
i += inc;
- bmd.setPixel(x + i, y + i * multDiff, color);
+ bmd.setPixel32(x + i, y + i * multDiff, color);
i += inc;
}
}

0 comments on commit b7f6d01

Please sign in to comment.