utils修改
This commit is contained in:
parent
3a87487697
commit
3cb91d10ad
@ -695,33 +695,30 @@ export function splitLineEvenly(
|
||||
});
|
||||
}
|
||||
|
||||
/** 计算折线的平行线 */
|
||||
export function getParallelOfPolyline(
|
||||
/** 计算直线的平行线 */
|
||||
export function getParallelOfLine(
|
||||
points: IPointData[],
|
||||
direction: 'L' | 'R',
|
||||
offset: number
|
||||
) {
|
||||
if (points.length < 2) throw Error('折线点不能少于2个');
|
||||
if (points.length !== 2) throw Error('直线点的个数需为2');
|
||||
const normalVecs = points.map((p, i) => {
|
||||
if (points[i - 1] && points[i + 1]) {
|
||||
let point;
|
||||
if (points[i + 1]) {
|
||||
point = new Vector2([
|
||||
points[i + 1].x - p.x,
|
||||
points[i + 1].y - p.y,
|
||||
]).normalize();
|
||||
} else {
|
||||
let point;
|
||||
if (points[i + 1]) {
|
||||
point = new Vector2([
|
||||
points[i + 1].x - p.x,
|
||||
points[i + 1].y - p.y,
|
||||
]).normalize();
|
||||
} else {
|
||||
point = new Vector2([
|
||||
p.x - points[i - 1].x,
|
||||
p.y - points[i - 1].y,
|
||||
]).normalize();
|
||||
}
|
||||
const rotate = new Matrix().rotate(
|
||||
(direction === 'L' ? Math.PI : -Math.PI) / 2
|
||||
);
|
||||
return rotate.apply(point);
|
||||
point = new Vector2([
|
||||
p.x - points[i - 1].x,
|
||||
p.y - points[i - 1].y,
|
||||
]).normalize();
|
||||
}
|
||||
const rotate = new Matrix().rotate(
|
||||
(direction === 'L' ? Math.PI : -Math.PI) / 2
|
||||
);
|
||||
return rotate.apply(point);
|
||||
});
|
||||
return points.map((p, i) => ({
|
||||
x: p.x + offset * normalVecs[i]?.x,
|
||||
|
Loading…
Reference in New Issue
Block a user