Skip to content

Commit 1b51b31

Browse files
committed
Tween remove extra shape curves
1 parent fb7843d commit 1b51b31

File tree

3 files changed

+66
-28
lines changed

3 files changed

+66
-28
lines changed

build/Geometrize.js

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
* Geometrize
33
* computational geometry and rendering library for JavaScript
44
*
5-
* @version 0.9.6 (2022-12-14 18:40:23)
5+
* @version 0.9.6 (2022-12-14 19:17:17)
66
* https://github.com/foo123/Geometrize
77
*
88
**//**
99
* Geometrize
1010
* computational geometry and rendering library for JavaScript
1111
*
12-
* @version 0.9.6 (2022-12-14 18:40:23)
12+
* @version 0.9.6 (2022-12-14 19:17:17)
1313
* https://github.com/foo123/Geometrize
1414
*
1515
**/
@@ -4431,26 +4431,36 @@ function prepare_tween(tween, fps)
44314431
}).sort(function(a, b) {
44324432
return a.frame - b.frame
44334433
});
4434-
var maxCurves = 0;
4435-
var match_shapes = function match_shapes(kf1, kf2, index, dir) {
4436-
var s1 = kf1.shape[index], s2 = kf2.shape[index+dir],
4434+
//var maxCurves = 0;
4435+
var match_shapes = function match_shapes(kf1, kf2, index1, index2) {
4436+
var s1 = kf1.shape[index1], s2 = kf2.shape[index2],
44374437
l1 = s1.length, l2 = s2.length,
44384438
m = stdMath.max(l1, l2),
44394439
i, i1, i2, p, b1, b2;
44404440
for (i1=0,i2=0,i=0; i<m; ++i)
44414441
{
4442-
if (i1 >= l1)
4442+
if (i1 >= l1 && i2 >= l2)
44434443
{
44444444
p = 0 < l1 ? s1[l1-1][3] : {x:0, y:0};
44454445
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}]);
44464446
++l1; ++i1;
4447+
p = 0 < l2 ? s2[l2-1][3] : {x:0, y:0};
4448+
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}]);
4449+
++l2; ++i2;
4450+
continue;
4451+
}
4452+
else if (i1 >= l1)
4453+
{
4454+
p = 0 < l1 ? s1[l1-1][3] : {x:0, y:0};
4455+
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}]);
4456+
++l1; ++i1; ++i2;
44474457
continue;
44484458
}
4449-
if (i2 >= l2)
4459+
else if (i2 >= l2)
44504460
{
44514461
p = 0 < l2 ? s2[l2-1][3] : {x:0, y:0};
44524462
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}]);
4453-
++l2; ++i2;
4463+
++l2; ++i2; ++i1;
44544464
continue;
44554465
}
44564466
b1 = s1[i1];
@@ -4474,22 +4484,31 @@ function prepare_tween(tween, fps)
44744484
++i2;
44754485
}
44764486
}
4487+
//s1.length must equal s2.length after matching
44774488
};
4478-
var add_curves = function add_curves(shape, numCurves) {
4489+
/*var add_curves = function add_curves(shape, numCurves) {
44794490
var p = shape.length ? shape[shape.length - 1][3] : {x:0, y:0};
44804491
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}]);
4481-
};
4492+
};*/
44824493
t.keyframes.forEach(function(_, i) {
44834494
if (i+1 < t.keyframes.length)
44844495
{
44854496
match_shapes(t.keyframes[i], t.keyframes[i+1], 0, 1);
44864497
}
4487-
maxCurves = stdMath.max(maxCurves, t.keyframes[i].shape[0].length);
4498+
if (0 === i)
4499+
{
4500+
t.keyframes[i].shape[1] = t.keyframes[i].shape[0].slice();
4501+
}
4502+
if (i+1 === t.keyframes.length)
4503+
{
4504+
t.keyframes[i].shape[0] = t.keyframes[i].shape[1].slice();
4505+
}
4506+
//maxCurves = stdMath.max(maxCurves, t.keyframes[i].shape[0].length);
44884507
});
4489-
t.keyframes.forEach(function(kf, i) {
4508+
/*t.keyframes.forEach(function(kf, i) {
44904509
add_curves(kf.shape[0], maxCurves);
44914510
add_curves(kf.shape[1], maxCurves);
4492-
});
4511+
});*/
44934512
return t;
44944513
}
44954514
function first_frame(tween)
@@ -4602,7 +4621,7 @@ function next_frame(tween)
46024621
as = a.shape[tween.reverse ? 1 : 0],
46034622
bs = b.shape[tween.reverse ? 0 : 1],
46044623
ai, bi, aij, bij,
4605-
i, j, n = as.length, x, y,
4624+
i, j, n = stdMath.min(as.length, bs.length), x, y,
46064625
s, cs = new Array(n)
46074626
;
46084627
if (!is_almost_equal(angle, 0))

build/Geometrize.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Tween.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,26 +218,36 @@ function prepare_tween(tween, fps)
218218
}).sort(function(a, b) {
219219
return a.frame - b.frame
220220
});
221-
var maxCurves = 0;
222-
var match_shapes = function match_shapes(kf1, kf2, index, dir) {
223-
var s1 = kf1.shape[index], s2 = kf2.shape[index+dir],
221+
//var maxCurves = 0;
222+
var match_shapes = function match_shapes(kf1, kf2, index1, index2) {
223+
var s1 = kf1.shape[index1], s2 = kf2.shape[index2],
224224
l1 = s1.length, l2 = s2.length,
225225
m = stdMath.max(l1, l2),
226226
i, i1, i2, p, b1, b2;
227227
for (i1=0,i2=0,i=0; i<m; ++i)
228228
{
229-
if (i1 >= l1)
229+
if (i1 >= l1 && i2 >= l2)
230230
{
231231
p = 0 < l1 ? s1[l1-1][3] : {x:0, y:0};
232232
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}]);
233233
++l1; ++i1;
234+
p = 0 < l2 ? s2[l2-1][3] : {x:0, y:0};
235+
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}]);
236+
++l2; ++i2;
237+
continue;
238+
}
239+
else if (i1 >= l1)
240+
{
241+
p = 0 < l1 ? s1[l1-1][3] : {x:0, y:0};
242+
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}]);
243+
++l1; ++i1; ++i2;
234244
continue;
235245
}
236-
if (i2 >= l2)
246+
else if (i2 >= l2)
237247
{
238248
p = 0 < l2 ? s2[l2-1][3] : {x:0, y:0};
239249
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}]);
240-
++l2; ++i2;
250+
++l2; ++i2; ++i1;
241251
continue;
242252
}
243253
b1 = s1[i1];
@@ -261,22 +271,31 @@ function prepare_tween(tween, fps)
261271
++i2;
262272
}
263273
}
274+
//s1.length must equal s2.length after matching
264275
};
265-
var add_curves = function add_curves(shape, numCurves) {
276+
/*var add_curves = function add_curves(shape, numCurves) {
266277
var p = shape.length ? shape[shape.length - 1][3] : {x:0, y:0};
267278
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}]);
268-
};
279+
};*/
269280
t.keyframes.forEach(function(_, i) {
270281
if (i+1 < t.keyframes.length)
271282
{
272283
match_shapes(t.keyframes[i], t.keyframes[i+1], 0, 1);
273284
}
274-
maxCurves = stdMath.max(maxCurves, t.keyframes[i].shape[0].length);
285+
if (0 === i)
286+
{
287+
t.keyframes[i].shape[1] = t.keyframes[i].shape[0].slice();
288+
}
289+
if (i+1 === t.keyframes.length)
290+
{
291+
t.keyframes[i].shape[0] = t.keyframes[i].shape[1].slice();
292+
}
293+
//maxCurves = stdMath.max(maxCurves, t.keyframes[i].shape[0].length);
275294
});
276-
t.keyframes.forEach(function(kf, i) {
295+
/*t.keyframes.forEach(function(kf, i) {
277296
add_curves(kf.shape[0], maxCurves);
278297
add_curves(kf.shape[1], maxCurves);
279-
});
298+
});*/
280299
return t;
281300
}
282301
function first_frame(tween)
@@ -389,7 +408,7 @@ function next_frame(tween)
389408
as = a.shape[tween.reverse ? 1 : 0],
390409
bs = b.shape[tween.reverse ? 0 : 1],
391410
ai, bi, aij, bij,
392-
i, j, n = as.length, x, y,
411+
i, j, n = stdMath.min(as.length, bs.length), x, y,
393412
s, cs = new Array(n)
394413
;
395414
if (!is_almost_equal(angle, 0))

0 commit comments

Comments
 (0)