UNPKG

bodymovin

Version:

After Effects plugin for exporting animations to SVG + JavaScript or canvas + JavaScript

64 lines (59 loc) 1.63 kB
function ShapePath(){ this.c = false; this._length = 0; this._maxLength = 8; this.v = Array.apply(null,{length:this._maxLength}); this.o = Array.apply(null,{length:this._maxLength}); this.i = Array.apply(null,{length:this._maxLength}); }; ShapePath.prototype.setPathData = function(closed, len) { this.c = closed; this.setLength(len); var i = 0; while(i < len){ this.v[i] = point_pool.newPoint(); this.o[i] = point_pool.newPoint(); this.i[i] = point_pool.newPoint(); i += 1; } }; ShapePath.prototype.setLength = function(len) { while(this._maxLength < len) { this.doubleArrayLength(); } this._length = len; } ShapePath.prototype.doubleArrayLength = function() { this.v = this.v.concat(Array.apply(null,{length:this._maxLength})) this.i = this.i.concat(Array.apply(null,{length:this._maxLength})) this.o = this.o.concat(Array.apply(null,{length:this._maxLength})) this._maxLength *= 2; }; ShapePath.prototype.setXYAt = function(x, y, type, pos, replace) { var arr; this._length = Math.max(this._length, pos + 1); if(this._length >= this._maxLength) { this.doubleArrayLength(); } switch(type){ case 'v': arr = this.v; break; case 'i': arr = this.i; break; case 'o': arr = this.o; break; } if(!arr[pos] || (arr[pos] && !replace)){ arr[pos] = point_pool.newPoint(); } arr[pos][0] = x; arr[pos][1] = y; }; ShapePath.prototype.setTripleAt = function(vX,vY,oX,oY,iX,iY,pos, replace) { this.setXYAt(vX,vY,'v',pos, replace); this.setXYAt(oX,oY,'o',pos, replace); this.setXYAt(iX,iY,'i',pos, replace); };