Skip to content

Commit c79aa24

Browse files
committed
fix angles on both start and end shapes
1 parent c3f7082 commit c79aa24

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

internal/animate/prepare.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {copyPoint, length, reverse, shift, insertCount, distance, mod} from "../util";
1+
import {copyPoint, length, reverse, shift, insertCount, distance, mod, angleOf} from "../util";
22
import {Point, Shape} from "../types";
33

44
const optimizeOrder = (a: Shape, b: Shape): Shape => {
@@ -52,16 +52,18 @@ export const divideShape = (count: number, points: Shape): Shape => {
5252
return out;
5353
};
5454

55-
const fixAngles = (a: Shape, b: Shape): Shape => {
56-
// TODO fix in first shape too
55+
const fixAngles = (shape: Shape): Shape => {
5756
const out: Shape = [];
58-
for (let i = 0; i < a.length; i++) {
59-
const point = copyPoint(b[i]);
57+
for (let i = 0; i < shape.length; i++) {
58+
const before = shape[mod(i - 1, shape.length)];
59+
const after = shape[mod(i + 1, shape.length)];
60+
const angle = angleOf(before, after);
61+
const point = copyPoint(shape[i]);
6062
if (point.handleIn.length === 0) {
61-
point.handleIn.angle = a[i].handleIn.angle;
63+
point.handleIn.angle = angle + Math.PI;
6264
}
6365
if (point.handleOut.length === 0) {
64-
point.handleOut.angle = a[i].handleOut.angle;
66+
point.handleOut.angle = angle;
6567
}
6668
out.push(point);
6769
}
@@ -95,6 +97,5 @@ export const prepShapes = (a: Shape, b: Shape): [Shape, Shape] => {
9597
const aNorm = divideShape(points, a);
9698
const bNorm = divideShape(points, b);
9799
const bOpt = optimizeOrder(aNorm, bNorm);
98-
const bFix = fixAngles(aNorm, bOpt);
99-
return [aNorm, bFix];
100+
return [fixAngles(aNorm), fixAngles(bOpt)];
100101
};

0 commit comments

Comments
 (0)