move util
This commit is contained in:
parent
d8888d484a
commit
85a244d13e
|
|
@ -1,6 +1,6 @@
|
||||||
import { getBoxToBoxArrow } from 'perfect-arrows';
|
import { getBoxToBoxArrow } from 'perfect-arrows';
|
||||||
import { AbstractArrow } from './abstract-arrow.ts';
|
import { AbstractArrow } from './abstract-arrow.ts';
|
||||||
import { pointsOnBezierCurves } from './utils.ts';
|
import { getSvgPathFromStroke, pointsOnBezierCurves } from './utils.ts';
|
||||||
import { getStroke, StrokeOptions } from 'perfect-freehand';
|
import { getStroke, StrokeOptions } from 'perfect-freehand';
|
||||||
|
|
||||||
export type Arrow = [
|
export type Arrow = [
|
||||||
|
|
@ -80,24 +80,3 @@ export class FolkConnection extends AbstractArrow {
|
||||||
this.style.backgroundColor = 'black';
|
this.style.backgroundColor = 'black';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSvgPathFromStroke(stroke: number[][]): string {
|
|
||||||
if (stroke.length === 0) return '';
|
|
||||||
|
|
||||||
for (const point of stroke) {
|
|
||||||
point[0] = Math.round(point[0] * 100) / 100;
|
|
||||||
point[1] = Math.round(point[1] * 100) / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
const d = stroke.reduce(
|
|
||||||
(acc, [x0, y0], i, arr) => {
|
|
||||||
const [x1, y1] = arr[(i + 1) % arr.length];
|
|
||||||
acc.push(x0, y0, (x0 + x1) / 2, (y0 + y1) / 2);
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
['M', ...stroke[0], 'Q']
|
|
||||||
);
|
|
||||||
|
|
||||||
d.push('Z');
|
|
||||||
return d.join(' ');
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,18 @@ function getPointsOnBezierCurveWithSplitting(
|
||||||
|
|
||||||
const red = lerp(r1, r2, t);
|
const red = lerp(r1, r2, t);
|
||||||
|
|
||||||
getPointsOnBezierCurveWithSplitting([p1, q1, r1, red], 0, tolerance, outPoints);
|
getPointsOnBezierCurveWithSplitting(
|
||||||
getPointsOnBezierCurveWithSplitting([red, r2, q3, p4], 0, tolerance, outPoints);
|
[p1, q1, r1, red],
|
||||||
|
0,
|
||||||
|
tolerance,
|
||||||
|
outPoints
|
||||||
|
);
|
||||||
|
getPointsOnBezierCurveWithSplitting(
|
||||||
|
[red, r2, q3, p4],
|
||||||
|
0,
|
||||||
|
tolerance,
|
||||||
|
outPoints
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return outPoints;
|
return outPoints;
|
||||||
}
|
}
|
||||||
|
|
@ -153,3 +163,24 @@ export function pointsOnBezierCurves(
|
||||||
}
|
}
|
||||||
return newPoints;
|
return newPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getSvgPathFromStroke(stroke: number[][]): string {
|
||||||
|
if (stroke.length === 0) return '';
|
||||||
|
|
||||||
|
for (const point of stroke) {
|
||||||
|
point[0] = Math.round(point[0] * 100) / 100;
|
||||||
|
point[1] = Math.round(point[1] * 100) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
const d = stroke.reduce(
|
||||||
|
(acc, [x0, y0], i, arr) => {
|
||||||
|
const [x1, y1] = arr[(i + 1) % arr.length];
|
||||||
|
acc.push(x0, y0, (x0 + x1) / 2, (y0 + y1) / 2);
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
['M', ...stroke[0], 'Q']
|
||||||
|
);
|
||||||
|
|
||||||
|
d.push('Z');
|
||||||
|
return d.join(' ');
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue