johnmccutchan/vector_math — pull request #63 by Fox32 (2014-03-16 19:15:05+00:00)
Title: Feature/cleanup

*This pull-requets is work in progress. I need to finish the cleanup for the matrix classes. There are also some open pointsmarked with TODO comments. I will work on it in the next days, I created this pull request to catch initial reactions*

I started this pull request with the goal to remove call chaining (#59) but I also took a look at "some" other things:

* Remove call chaining (breaking change, but the Dart Editor gives very good guidance here!)
* Rename some parts to match the Dart Style guide (constants, constructors, ...) (I only deprecated them)
* Removed some methods that didn't provide a real benefit (e.g. Sphere.copyOriginDirection)
* Formatting
* Analyser warnings
* Remove duplicate code (e.g. the plus operator of a vector can share the same code as VectorN.add)
* Add more documentation comments (especially for the collision detection objects)
* Improve code in a way that dart2js can generate better code. I took [these](https://code.google.com/p/dart/issues/detail?id=17434#c2) suggestions as a start. Here is a example of dart2js code that changed, the old code:
```
dot$1: [function(other) {
var t1, t2, t3, t4, t5, t6, t7;
t1 = this.storage;
t2 = t1[0];
t3 = other.get$storage();
t4 = t3.length;
if (0 >= t4)
return H.ioore(t3, 0);
t5 = t3[0];
t6 = t1[1];
if (1 >= t4)
return H.ioore(t3, 1);
t7 = t3[1];
t1 = t1[2];
if (2 >= t4)
return H.ioore(t3, 2);
return t2 * t5 + t6 * t7 + t1 * t3[2];
}, "call$1", "get$dot", 2, 0, null, 109, []],
```
and the new code:
```
dot$1: [function(other) {
var otherStorage, t1;
otherStorage = other.get$_storage();
t1 = this._storage;
return t1[0] * otherStorage[0] + t1[1] * otherStorage[1] + t1[2] * otherStorage[2];
}, "call$1", "get$dot", 2, 0, null, 109, []],
```
In this case range checks could be removed, in other cases less calls to getters are made. It also has a small influence on code size, but I don't think that these are significant. For the future it would be nice to have a test bench to compare the performance of changes in both the DartVM and Dart2Js. Not sure what to choose as a benchmark here, maybe some sort of simulation?