UNPKG

604 BPlain TextView Raw
1import type { CurveArray } from '../types';
2
3// reverse CURVE based pathArray segments only
4export function reverseCurve(pathArray: CurveArray): CurveArray {
5 const rotatedCurve = pathArray
6 .slice(1)
7 .map((x, i, curveOnly) =>
8 // @ts-ignore
9 !i ? pathArray[0].slice(1).concat(x.slice(1)) : curveOnly[i - 1].slice(-2).concat(x.slice(1)),
10 )
11 // @ts-ignore
12 .map((x) => x.map((y, i) => x[x.length - i - 2 * (1 - (i % 2))]))
13 .reverse();
14
15 return [['M'].concat(rotatedCurve[0].slice(0, 2))].concat(
16 rotatedCurve.map((x) => ['C'].concat(x.slice(2))),
17 ) as CurveArray;
18}