Precalculate side points again for better performance.

This commit is contained in:
Jürg Lehni 2014-03-12 10:40:07 +01:00
parent fb005ee63a
commit 76c0f7dd12

View file

@ -16,6 +16,7 @@
this.numSegment = Math.floor(r / 3 + 2); this.numSegment = Math.floor(r / 3 + 2);
this.boundOffset = []; this.boundOffset = [];
this.boundOffsetBuff = []; this.boundOffsetBuff = [];
this.sidePoints = [];
this.path = new Path({ this.path = new Path({
fillColor: { fillColor: {
hue: Math.random() * 360, hue: Math.random() * 360,
@ -29,6 +30,10 @@
this.boundOffset.push(this.radius); this.boundOffset.push(this.radius);
this.boundOffsetBuff.push(this.radius); this.boundOffsetBuff.push(this.radius);
this.path.add(new Point()); this.path.add(new Point());
this.sidePoints.push(new Point({
angle: 360 / this.numSegment * i,
length: 1
}));
} }
} }
@ -103,10 +108,7 @@
} }
Ball.prototype.getSidePoint = function(index) { Ball.prototype.getSidePoint = function(index) {
return this.point + { return this.point + this.sidePoints[index] * this.boundOffset[index];
angle: 360 / this.numSegment * index,
length: this.boundOffset[index]
};
} }
Ball.prototype.updateBounds = function() { Ball.prototype.updateBounds = function() {