From 1b51b31fbad68274d45c626ad7f2b97a6c517c31 Mon Sep 17 00:00:00 2001 From: Nikos M Date: Wed, 14 Dec 2022 19:18:39 +0200 Subject: [PATCH] Tween remove extra shape curves --- build/Geometrize.js | 47 +++++++++++++++++++++++++++++------------ build/Geometrize.min.js | 4 ++-- src/Tween.js | 43 ++++++++++++++++++++++++++----------- 3 files changed, 66 insertions(+), 28 deletions(-) diff --git a/build/Geometrize.js b/build/Geometrize.js index a6e4522..1a98565 100644 --- a/build/Geometrize.js +++ b/build/Geometrize.js @@ -2,14 +2,14 @@ * Geometrize * computational geometry and rendering library for JavaScript * -* @version 0.9.6 (2022-12-14 18:40:23) +* @version 0.9.6 (2022-12-14 19:17:17) * https://github.com/foo123/Geometrize * **//** * Geometrize * computational geometry and rendering library for JavaScript * -* @version 0.9.6 (2022-12-14 18:40:23) +* @version 0.9.6 (2022-12-14 19:17:17) * https://github.com/foo123/Geometrize * **/ @@ -4431,26 +4431,36 @@ function prepare_tween(tween, fps) }).sort(function(a, b) { return a.frame - b.frame }); - var maxCurves = 0; - var match_shapes = function match_shapes(kf1, kf2, index, dir) { - var s1 = kf1.shape[index], s2 = kf2.shape[index+dir], + //var maxCurves = 0; + var match_shapes = function match_shapes(kf1, kf2, index1, index2) { + var s1 = kf1.shape[index1], s2 = kf2.shape[index2], l1 = s1.length, l2 = s2.length, m = stdMath.max(l1, l2), i, i1, i2, p, b1, b2; for (i1=0,i2=0,i=0; i= l1) + if (i1 >= l1 && i2 >= l2) { p = 0 < l1 ? s1[l1-1][3] : {x:0, y:0}; s1.push([{x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}]); ++l1; ++i1; + p = 0 < l2 ? s2[l2-1][3] : {x:0, y:0}; + s2.push([{x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}]); + ++l2; ++i2; + continue; + } + else if (i1 >= l1) + { + p = 0 < l1 ? s1[l1-1][3] : {x:0, y:0}; + s1.push([{x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}]); + ++l1; ++i1; ++i2; continue; } - if (i2 >= l2) + else if (i2 >= l2) { p = 0 < l2 ? s2[l2-1][3] : {x:0, y:0}; s2.push([{x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}]); - ++l2; ++i2; + ++l2; ++i2; ++i1; continue; } b1 = s1[i1]; @@ -4474,22 +4484,31 @@ function prepare_tween(tween, fps) ++i2; } } + //s1.length must equal s2.length after matching }; - var add_curves = function add_curves(shape, numCurves) { + /*var add_curves = function add_curves(shape, numCurves) { var p = shape.length ? shape[shape.length - 1][3] : {x:0, y:0}; while (shape.length < numCurves) shape.push([{x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}]); - }; + };*/ t.keyframes.forEach(function(_, i) { if (i+1 < t.keyframes.length) { match_shapes(t.keyframes[i], t.keyframes[i+1], 0, 1); } - maxCurves = stdMath.max(maxCurves, t.keyframes[i].shape[0].length); + if (0 === i) + { + t.keyframes[i].shape[1] = t.keyframes[i].shape[0].slice(); + } + if (i+1 === t.keyframes.length) + { + t.keyframes[i].shape[0] = t.keyframes[i].shape[1].slice(); + } + //maxCurves = stdMath.max(maxCurves, t.keyframes[i].shape[0].length); }); - t.keyframes.forEach(function(kf, i) { + /*t.keyframes.forEach(function(kf, i) { add_curves(kf.shape[0], maxCurves); add_curves(kf.shape[1], maxCurves); - }); + });*/ return t; } function first_frame(tween) @@ -4602,7 +4621,7 @@ function next_frame(tween) as = a.shape[tween.reverse ? 1 : 0], bs = b.shape[tween.reverse ? 0 : 1], ai, bi, aij, bij, - i, j, n = as.length, x, y, + i, j, n = stdMath.min(as.length, bs.length), x, y, s, cs = new Array(n) ; if (!is_almost_equal(angle, 0)) diff --git a/build/Geometrize.min.js b/build/Geometrize.min.js index 872989b..58894bd 100644 --- a/build/Geometrize.min.js +++ b/build/Geometrize.min.js @@ -2,7 +2,7 @@ * Geometrize * computational geometry and rendering library for JavaScript * -* @version 0.9.6 (2022-12-14 18:40:23) +* @version 0.9.6 (2022-12-14 19:17:17) * https://github.com/foo123/Geometrize * -**/!function(t,n,e){"use strict";"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[n]=e.call(t)):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(n)?define(n,["module"],function(n){return e.moduleUri=n.uri,e.call(t)}):n in t||(t[n]=e.call(t)||1)&&"function"==typeof define&&define.amd&&define(function(){return t[n]})}("undefined"!=typeof self?self:this,"Geometrize",function(){"use strict";var v=Object.prototype.hasOwnProperty,t=Object.prototype.toString,b=Object.defineProperty,S=Math,G=S.abs,C=S.sqrt,l=S.pow,$=S.PI,w=2*$,u=1e-6,o=$/2,a=3*$/2,r=C(2),c=C(3),f=20,h=.01,_={},y=function(){},n="undefined"!=typeof global&&"[object global]"===t.call(global),x="undefined"!=typeof window&&"[object Window]"===t.call(window),i=(n?global:x&&window,{VERSION:"0.9.6",Math:{},Geometry:{}});function e(n,t,e){var r,i,o,a=v.call(t,"constructor")?t.constructor:function(){};for(r in n?(a.prototype=Object.create(n.prototype),a.prototype.$super=(i=n,o={},function(n,t){var e=":"+n;return 1===o[e]?(i.prototype.$super||y).call(this,n,t):(o[e]=1,t=("constructor"===n?i:i.prototype[n]||y).apply(this,t||[]),o[e]=0,t)})):a.prototype.$super=y,a.prototype.constructor=a,t)v.call(t,r)&&"constructor"!==r&&(a.prototype[r]=t[r]);if(e)for(r in e)v.call(e,r)&&(a[r]=e[r]);return a}var n={$changed:!1,$cb:null,dispose:function(){this.$cb=null},isChanged:function(n){return arguments.length?(this.$changed=!!n,this):this.$changed},onChange:function(n,t){var e,r=this;return!1===t&&(kt(n)||$t(n))?r.$cb&&-1!==(e=($t(n)?r.$cb.map(function(n){return dt(n.id)}):r.$cb).indexOf(n))&&r.$cb.splice(e,1):kt(n)&&(r.$cb||(r.$cb=[]),-1===(e=r.$cb.indexOf(n))&&r.$cb.push(n)),r},triggerChange:function(){var t=this;return t.$cb&&t.$cb.forEach(function(n){n(t)}),t}},k=e(null,ut(null,{constructor:function e(r){var i=this;return r instanceof e?r:i instanceof e?(r=vt(r),i.dispose=function(){r=null,e.prototype.dispose.call(i)},i.clone=function(){return new e(r)},i.val=function(n){if(arguments.length){n=n instanceof e?n.val():vt(n);var t=!ot(r,n);return r=n,t&&!i.isChanged()&&(i.isChanged(!0),i.triggerChange()),i}return r},i.valueOf=function(){return r.valueOf()},i.toString=function(){return dt(r)},void i.isChanged(!0)):new e(r)},clone:null,val:null,valueOf:null,toString:null},n)),g=e(null,{constructor:function n(t,e,r,i,o,a,s,u,l){var c=this;return t instanceof n?t:c instanceof n?(wt(t)&&9<=t.length?(c.$00=vt(t[0]),c.$01=vt(t[1]),c.$02=vt(t[2]),c.$10=vt(t[3]),c.$11=vt(t[4]),c.$12=vt(t[5])):(c.$00=t,c.$01=e,c.$02=r,c.$10=i,c.$11=o,c.$12=a),c.$20=0,c.$21=0,void(c.$22=1)):new n(t,e,r,i,o,a,s,u,l)},$00:1,$01:0,$02:0,$10:0,$11:1,$12:0,$20:0,$21:0,$22:1,clone:function(){var n=this;return new g(n.$00,n.$01,n.$02,n.$10,n.$11,n.$12,0,0,1)},eq:function(n){if(n instanceof g){var t=this;return ot(t.$00,n.$00)&&ot(t.$01,n.$01)&&ot(t.$02,n.$02)&&ot(t.$10,n.$10)&&ot(t.$11,n.$11)&&ot(t.$12,n.$12)}return!1},add:function(n){var t=this;return n instanceof g?new g(t.$00+n.$00,t.$01+n.$01,t.$02+n.$02,t.$10+n.$10,t.$11+n.$11,t.$12+n.$12,0,0,1):(n=vt(n),new g(t.$00+n,t.$01+n,t.$02+n,t.$10+n,t.$11+n,t.$12+n,0,0,1))},mul:function(n){var t=this;return n instanceof g?new g(t.$00*n.$00+t.$01*n.$10+t.$02*n.$20,t.$00*n.$01+t.$01*n.$11+t.$02*n.$21,t.$00*n.$02+t.$01*n.$12+t.$02*n.$22,t.$10*n.$00+t.$11*n.$10+t.$12*n.$20,t.$10*n.$01+t.$11*n.$11+t.$12*n.$21,t.$10*n.$02+t.$11*n.$12+t.$12*n.$22,0,0,1):(n=vt(n),new g(t.$00*n,t.$01*n,t.$02*n,t.$10*n,t.$11*n,t.$12*n,0,0,1))},det:function(){var n=this;return n.$00*(n.$11*n.$22-n.$12*n.$21)+n.$01*(n.$12*n.$20-n.$10*n.$22)+n.$02*(n.$21*n.$10-n.$11*n.$20)},inv:function(){var n,t,e,r=this,i=r.$00,o=r.$01,a=r.$02,s=r.$10,u=r.$11,l=r.$12,c=i*u-o*s;return it(c,0)?null:new g(n=u/c,t=-o/c,-n*a-t*l,e=-s/c,r=i/c,-e*a-r*l,0,0,1)},transform:function(n,t){var e=this,r=n.x,i=n.y,n=e.$00*r+e.$01*i+e.$02,e=e.$10*r+e.$11*i+e.$12;return t?(t.x=n,t.y=e):t=new M(n,e),t},getTranslation:function(){return{x:this.$02,y:this.$12}},getRotationAngle:function(){return S.atan2(this.$10,this.$00)},getScale:function(){var n=this.$00,t=-this.$01,e=this.$10,r=this.$11;return{x:rt(n)*Nn(n,e),y:rt(r)*Nn(t,r)}},toArray:function(){var n=this;return[n.$00,n.$01,n.$02,n.$10,n.$11,n.$12,n.$20,n.$21,n.$22]},toSVG:function(){var n=this;return"matrix("+dt(n.$00)+" "+dt(n.$10)+" "+dt(n.$01)+" "+dt(n.$11)+" "+dt(n.$02)+" "+dt(n.$12)+")"},toCSS:function(){var n=this;return"matrix("+dt(n.$00)+","+dt(n.$10)+","+dt(n.$01)+","+dt(n.$11)+","+dt(n.$02)+","+dt(n.$12)+")"},toCanvas:function(n){var t=this;return n.transform(t.$00,t.$10,t.$01,t.$11,t.$02,t.$12),n},toTex:function(){return g.arrayTex(this.toArray(),3,3)},toString:function(){return g.arrayString(this.toArray(),3,3)}},{eye:function(){return new g(1,0,0,0,1,0,0,0,1)},translate:function(n,t){return new g(1,0,vt(n),0,1,vt(t),0,0,1)},rotate:function(n,t,e){e=vt(e||0),t=vt(t||0),n=vt(n);var r=S.cos(n),n=S.sin(n);return new g(r,-n,t-r*t+n*e,n,r,e-r*e-n*t,0,0,1)},scale:function(n,t,e,r){return r=vt(r||0),e=vt(e||0),n=vt(n),t=vt(t),new g(n,0,-n*e+e,0,t,-t*r+r,0,0,1)},reflectX:function(){return new g(-1,0,0,0,1,0,0,0,1)},reflectY:function(){return new g(1,0,0,0,-1,0,0,0,1)},shearX:function(n){return new g(1,vt(n),0,0,1,0,0,0,1)},shearY:function(n){return new g(1,0,0,vt(n),1,0,0,0,1)},arrayTex:function(n,t,e){for(var r="\\begin{pmatrix}",i=0;it.x?n:t),(!g&&(st.y?n:t),{ymin:h.y,xmin:f.x,ymax:u.y,xmax:o.x}}),configurable:!1}),void(l.isChanged=function(n){return!0===n&&(v=d=m=null),l.$super("isChanged",arguments)})):new n(t,e,r,i,o,a,s)},name:"Arc",clone:function(){var n=this;return new Z(n.start.clone(),n.end.clone(),n.radiusX,n.radiusY,n.angle,n.largeArc,n.sweep)},transform:function(n){var t=this,e=t.radiusX,r=t.radiusY,i=t.angle,o=tt(n.getRotationAngle()),a=n.getScale();return new Z(t.start.transform(n),t.end.transform(n),e*a.x,r*a.y,i+o,t.largeArc,t.sweep)},isClosed:function(){return!1},isConvex:function(){return!1},hasMatrix:function(){return!1},f:function(n){var t=this,e=t.center,r=t.cs;return In(t.theta+n*t.dtheta,e.x,e.y,t.rX,t.rY,r[0],r[1])},d:function(){var n,t,e,r,i,o,a,s=this,a=(n=s.center.x,t=s.center.y,e=s.rY,r=s.rX,i=[s.cs[0],-s.cs[1]],o=-s.theta,a=-s.dtheta,{p0:In(o,n,t,e,r,i[0],i[1]),p1:In(o+a,n,t,e,r,i[0],i[1]),fa:G(a)>$,fs:0=w&&n.closePath()},toTex:function(){var n=this;return"\\text{Arc: }\\left("+[bt(n.start),bt(n.end),dt(n.radiusX),dt(n.radiusY),dt(n.angle)+"\\text{°}",dt(n.largeArc?1:0),dt(n.sweep?1:0)].join(",")+"\\right)"},toString:function(){var n=this;return"Arc("+[dt(n.start),dt(n.end),dt(n.radiusX),dt(n.radiusY),dt(n.angle)+"°",dt(n.largeArc),dt(n.sweep)].join(",")+")"}});i.Arc=Z;var D=e(n,{constructor:function n(t){var r,i=this,e=null,o=null,a=null;return t instanceof n?t:i instanceof n?(i.$super("constructor",[t]),b(i,"length",{get:function(){return null==e&&(e=Pn(i._lines)),e},enumerable:!0,configurable:!1}),b(i,"_bbox",{get:function(){return null==o&&(o=r(i._points)),o},enumerable:!(r=function(t){var n=An(t[0].x-2*t[1].x+t[2].x,t[1].x-t[0].x),e=!1===n?[t[1]]:n.map(function(n){return 0<=n&&n<=1?qn(n,t):t[1]}),r=An(t[0].y-2*t[1].y+t[2].y,t[1].y-t[0].y),n=!1===r?[t[1]]:r.map(function(n){return 0<=n&&n<=1?qn(n,t):t[1]}),r=S.min.apply(S,e.concat([t[0],t[2]]).map(at)),e=S.max.apply(S,e.concat([t[0],t[2]]).map(at));return{ymin:S.min.apply(S,n.concat([t[0],t[2]]).map(st)),xmin:r,ymax:S.max.apply(S,n.concat([t[0],t[2]]).map(st)),xmax:e}}),configurable:!1}),b(i,"_hull",{get:function(){var t,n,e;return null==a&&(n=Qn(e=i._points),t=g.rotate(n.R).mul(g.translate(n.Tx,n.Ty)),n=r(e.map(function(n){return t.transform(n,{x:0,y:0})})),e=t.inv(),a=[e.transform(new M(n.xmin,n.ymin)),e.transform(new M(n.xmax,n.ymin)),e.transform(new M(n.xmax,n.ymax)),e.transform(new M(n.xmin,n.ymax))]),a},enumerable:!1,configurable:!1}),void(i.isChanged=function(n){return!0===n&&(a=o=e=null),i.$super("isChanged",arguments)})):new n(t)},name:"QBezier",clone:function(){return new D(this.points.map(function(n){return n.clone()}))},transform:function(t){return new D(this.points.map(function(n){return n.transform(t)}))},hasPoint:function(n){return function(n,t){var e;if(!(e=Tn(t[0].x-2*t[1].x+t[2].x,-2*t[0].x+2*t[1].x,t[0].x-n.x)))return!1;1=n.nframes}n["ease-in"]=n["ease-in-quad"],n["ease-out"]=n["ease-out-quad"],n["ease-in-out"]=n["ease-in-out-quad"];var rn=e(Y,{constructor:function n(l){var t,e,r=this,i=!1,o=0,a=null,s=null,u=null;return l instanceof n?l:r instanceof n?(Y.call(r),r.start=function(){return i=!0,a&&(clearTimeout(a),a=null),tn(l)&&s&&s(r),a=setTimeout(e,(tn(l)&&l.delay||0)+o),r},r.stop=function(){return i=!1,a&&(clearTimeout(a),a=null),r},r.rewind=function(){return function(n){n.reverse?n.kf=n.keyframes.length-1:n.kf=0;var t,e,r,i,o,a,s=n.keyframes[n.kf],u=s.transform.translate.x,l=s.transform.translate.y,c=s.transform.scale.origin.x,f=s.transform.scale.origin.y,h=s.transform.scale.x,y=s.transform.scale.y,g=s.transform.rotate.origin.x,x=s.transform.rotate.origin.y,p=s.transform.rotate.angle,m=1,d=0,v=s.shape[n.reverse?1:0],b=v.length,C=new Array(b);for(ot(p,0)||(m=S.cos(p),d=S.sin(p)),u+=g-m*g+d*x,l+=x-m*x-d*g,e=0;e=n.keyframes[n.kf+1].frame&&n.kf+2"+dt(r)+"":"/>");return t}function ct(a,s,u,i){if(kt(a.onChange))return a;function l(t){a.$cb.forEach(function(n){n(t)})}var c=!0;i=i||ht;var f=function(n,t){for(var e=n;et.x?n:t),(!g&&(st.y?n:t),{ymin:h.y,xmin:f.x,ymax:u.y,xmax:o.x}}),configurable:!1}),void(l.isChanged=function(n){return!0===n&&(v=d=m=null),l.$super("isChanged",arguments)})):new n(t,e,r,i,o,a,s)},name:"Arc",clone:function(){var n=this;return new Z(n.start.clone(),n.end.clone(),n.radiusX,n.radiusY,n.angle,n.largeArc,n.sweep)},transform:function(n){var t=this,e=t.radiusX,r=t.radiusY,i=t.angle,o=tt(n.getRotationAngle()),a=n.getScale();return new Z(t.start.transform(n),t.end.transform(n),e*a.x,r*a.y,i+o,t.largeArc,t.sweep)},isClosed:function(){return!1},isConvex:function(){return!1},hasMatrix:function(){return!1},f:function(n){var t=this,e=t.center,r=t.cs;return In(t.theta+n*t.dtheta,e.x,e.y,t.rX,t.rY,r[0],r[1])},d:function(){var n,t,e,r,i,o,a,s=this,a=(n=s.center.x,t=s.center.y,e=s.rY,r=s.rX,i=[s.cs[0],-s.cs[1]],o=-s.theta,a=-s.dtheta,{p0:In(o,n,t,e,r,i[0],i[1]),p1:In(o+a,n,t,e,r,i[0],i[1]),fa:G(a)>$,fs:0=w&&n.closePath()},toTex:function(){var n=this;return"\\text{Arc: }\\left("+[bt(n.start),bt(n.end),dt(n.radiusX),dt(n.radiusY),dt(n.angle)+"\\text{°}",dt(n.largeArc?1:0),dt(n.sweep?1:0)].join(",")+"\\right)"},toString:function(){var n=this;return"Arc("+[dt(n.start),dt(n.end),dt(n.radiusX),dt(n.radiusY),dt(n.angle)+"°",dt(n.largeArc),dt(n.sweep)].join(",")+")"}});i.Arc=Z;var D=e(n,{constructor:function n(t){var r,i=this,e=null,o=null,a=null;return t instanceof n?t:i instanceof n?(i.$super("constructor",[t]),b(i,"length",{get:function(){return null==e&&(e=Pn(i._lines)),e},enumerable:!0,configurable:!1}),b(i,"_bbox",{get:function(){return null==o&&(o=r(i._points)),o},enumerable:!(r=function(t){var n=An(t[0].x-2*t[1].x+t[2].x,t[1].x-t[0].x),e=!1===n?[t[1]]:n.map(function(n){return 0<=n&&n<=1?qn(n,t):t[1]}),r=An(t[0].y-2*t[1].y+t[2].y,t[1].y-t[0].y),n=!1===r?[t[1]]:r.map(function(n){return 0<=n&&n<=1?qn(n,t):t[1]}),r=S.min.apply(S,e.concat([t[0],t[2]]).map(at)),e=S.max.apply(S,e.concat([t[0],t[2]]).map(at));return{ymin:S.min.apply(S,n.concat([t[0],t[2]]).map(st)),xmin:r,ymax:S.max.apply(S,n.concat([t[0],t[2]]).map(st)),xmax:e}}),configurable:!1}),b(i,"_hull",{get:function(){var t,n,e;return null==a&&(n=Qn(e=i._points),t=g.rotate(n.R).mul(g.translate(n.Tx,n.Ty)),n=r(e.map(function(n){return t.transform(n,{x:0,y:0})})),e=t.inv(),a=[e.transform(new M(n.xmin,n.ymin)),e.transform(new M(n.xmax,n.ymin)),e.transform(new M(n.xmax,n.ymax)),e.transform(new M(n.xmin,n.ymax))]),a},enumerable:!1,configurable:!1}),void(i.isChanged=function(n){return!0===n&&(a=o=e=null),i.$super("isChanged",arguments)})):new n(t)},name:"QBezier",clone:function(){return new D(this.points.map(function(n){return n.clone()}))},transform:function(t){return new D(this.points.map(function(n){return n.transform(t)}))},hasPoint:function(n){return function(n,t){var e;if(!(e=Tn(t[0].x-2*t[1].x+t[2].x,-2*t[0].x+2*t[1].x,t[0].x-n.x)))return!1;1=n.nframes}n["ease-in"]=n["ease-in-quad"],n["ease-out"]=n["ease-out-quad"],n["ease-in-out"]=n["ease-in-out-quad"];var rn=e(E,{constructor:function n(l){var t,e,r=this,i=!1,o=0,a=null,s=null,u=null;return l instanceof n?l:r instanceof n?(E.call(r),r.start=function(){return i=!0,a&&(clearTimeout(a),a=null),tn(l)&&s&&s(r),a=setTimeout(e,(tn(l)&&l.delay||0)+o),r},r.stop=function(){return i=!1,a&&(clearTimeout(a),a=null),r},r.rewind=function(){return function(n){n.reverse?n.kf=n.keyframes.length-1:n.kf=0;var t,e,r,i,o,a,s=n.keyframes[n.kf],u=s.transform.translate.x,l=s.transform.translate.y,c=s.transform.scale.origin.x,f=s.transform.scale.origin.y,h=s.transform.scale.x,y=s.transform.scale.y,g=s.transform.rotate.origin.x,x=s.transform.rotate.origin.y,p=s.transform.rotate.angle,m=1,d=0,v=s.shape[n.reverse?1:0],b=v.length,C=new Array(b);for(ot(p,0)||(m=S.cos(p),d=S.sin(p)),u+=g-m*g+d*x,l+=x-m*x-d*g,e=0;e=n.keyframes[n.kf+1].frame&&n.kf+2"+dt(r)+"":"/>");return t}function ct(a,s,u,i){if(kt(a.onChange))return a;function l(t){a.$cb.forEach(function(n){n(t)})}var c=!0;i=i||ht;var f=function(n,t){for(var e=n;e= l1) + if (i1 >= l1 && i2 >= l2) { p = 0 < l1 ? s1[l1-1][3] : {x:0, y:0}; s1.push([{x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}]); ++l1; ++i1; + p = 0 < l2 ? s2[l2-1][3] : {x:0, y:0}; + s2.push([{x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}]); + ++l2; ++i2; + continue; + } + else if (i1 >= l1) + { + p = 0 < l1 ? s1[l1-1][3] : {x:0, y:0}; + s1.push([{x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}]); + ++l1; ++i1; ++i2; continue; } - if (i2 >= l2) + else if (i2 >= l2) { p = 0 < l2 ? s2[l2-1][3] : {x:0, y:0}; s2.push([{x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}]); - ++l2; ++i2; + ++l2; ++i2; ++i1; continue; } b1 = s1[i1]; @@ -261,22 +271,31 @@ function prepare_tween(tween, fps) ++i2; } } + //s1.length must equal s2.length after matching }; - var add_curves = function add_curves(shape, numCurves) { + /*var add_curves = function add_curves(shape, numCurves) { var p = shape.length ? shape[shape.length - 1][3] : {x:0, y:0}; while (shape.length < numCurves) shape.push([{x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}, {x:p.x, y:p.y}]); - }; + };*/ t.keyframes.forEach(function(_, i) { if (i+1 < t.keyframes.length) { match_shapes(t.keyframes[i], t.keyframes[i+1], 0, 1); } - maxCurves = stdMath.max(maxCurves, t.keyframes[i].shape[0].length); + if (0 === i) + { + t.keyframes[i].shape[1] = t.keyframes[i].shape[0].slice(); + } + if (i+1 === t.keyframes.length) + { + t.keyframes[i].shape[0] = t.keyframes[i].shape[1].slice(); + } + //maxCurves = stdMath.max(maxCurves, t.keyframes[i].shape[0].length); }); - t.keyframes.forEach(function(kf, i) { + /*t.keyframes.forEach(function(kf, i) { add_curves(kf.shape[0], maxCurves); add_curves(kf.shape[1], maxCurves); - }); + });*/ return t; } function first_frame(tween) @@ -389,7 +408,7 @@ function next_frame(tween) as = a.shape[tween.reverse ? 1 : 0], bs = b.shape[tween.reverse ? 0 : 1], ai, bi, aij, bij, - i, j, n = as.length, x, y, + i, j, n = stdMath.min(as.length, bs.length), x, y, s, cs = new Array(n) ; if (!is_almost_equal(angle, 0))