|
1 | | -import {copyPoint, length, reverse, shift, insertCount, distance, mod} from "../util"; |
| 1 | +import {copyPoint, length, reverse, shift, insertCount, distance, mod, angleOf} from "../util"; |
2 | 2 | import {Point, Shape} from "../types"; |
3 | 3 |
|
4 | 4 | const optimizeOrder = (a: Shape, b: Shape): Shape => { |
@@ -52,16 +52,18 @@ export const divideShape = (count: number, points: Shape): Shape => { |
52 | 52 | return out; |
53 | 53 | }; |
54 | 54 |
|
55 | | -const fixAngles = (a: Shape, b: Shape): Shape => { |
56 | | - // TODO fix in first shape too |
| 55 | +const fixAngles = (shape: Shape): Shape => { |
57 | 56 | 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]); |
60 | 62 | if (point.handleIn.length === 0) { |
61 | | - point.handleIn.angle = a[i].handleIn.angle; |
| 63 | + point.handleIn.angle = angle + Math.PI; |
62 | 64 | } |
63 | 65 | if (point.handleOut.length === 0) { |
64 | | - point.handleOut.angle = a[i].handleOut.angle; |
| 66 | + point.handleOut.angle = angle; |
65 | 67 | } |
66 | 68 | out.push(point); |
67 | 69 | } |
@@ -95,6 +97,5 @@ export const prepShapes = (a: Shape, b: Shape): [Shape, Shape] => { |
95 | 97 | const aNorm = divideShape(points, a); |
96 | 98 | const bNorm = divideShape(points, b); |
97 | 99 | const bOpt = optimizeOrder(aNorm, bNorm); |
98 | | - const bFix = fixAngles(aNorm, bOpt); |
99 | | - return [aNorm, bFix]; |
| 100 | + return [fixAngles(aNorm), fixAngles(bOpt)]; |
100 | 101 | }; |
0 commit comments