tmpvar/vec2.js — pull request #3 by dominictarr (2013-04-07 12:03:43+00:00)
Title: Injectable clean()

Doing a string op twice for every call of set is quite slow,
this patch uses a different approach - instead multiply, round, and then divide

https://github.com/dominictarr/vec2.js/pull/new/tmpvar:master...dominictarr:injectable-clean#L0R353

Benchmark output:
```
----------------------------------
running benchmark against: master
Sun 7 Apr 2013 13:01:44 IST
----------------------------------
--- create-many.js -------------

master
random sets. ops/s 139664.80446927375
TEST
random sets. ops/s 1190476.1904761903

--- observer.js -------------

master
observer ops/s 154440.15444015444
TEST
observer ops/s 1209189.8428053204

--- random-sets-int.js -------------

master
random sets. ops/s 790513.8339920948
TEST
random sets. ops/s 3546099.290780142

--- random-sets.js -------------

master
random sets. ops/s 296033.1557134399
TEST
random sets. ops/s 3067484.662576687
```

Nearly 10 times faster!
Although, this does break 3 tests:

```
․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․

✖ 3 of 71 tests failed:

1) Vec2 math #rotate accepts a scalar angle in radians:
expected false to equal true

2) Vec2 math #normalize properly normalizes a vector:
expected 0.37139068 to equal 0.37139067

3) Vec2 math #normalize should return a new vector when returnNew is truthy:
expected 0.37139068 to equal 0.37139067

```
Those seem like rounding errors, possibly the tests are incorrect?