kangax/fabric.js — pull request #285 by EricLesch (2012-10-15 17:53:58+00:00)
Title: Fixing todo for method _getAngleValueForStraighten

While I was looking at the angle stuff I saw a todo that looked doable.

I changed this ->

_getAngleValueForStraighten: function() {
var angle = this.get('angle');

// TODO (kangax): can this be simplified?

if (angle > -225 && angle <= -135) { return -180; }
else if (angle > -135 && angle <= -45) { return -90; }
else if (angle > -45 && angle <= 45) { return 0; }
else if (angle > 45 && angle <= 135) { return 90; }
else if (angle > 135 && angle <= 225 ) { return 180; }
else if (angle > 225 && angle <= 315) { return 270; }
else if (angle > 315) { return 360; }

return 0;
},

to this ->

_getAngleValueForStraighten: function() {
return (Math.ceil((this.get('angle') - 45) / 90)) * 90;
},

Tested with every value from -225 to 406 here:

http://jsfiddle.net/EricLesch/szxRd/2/

If it is out of range(i.e. <= 225 or > 405) it will return different values than the old function (not defaulting to 0 or 360) but I figure that this is probably the behavior that you want.

Best,
Eric