多边形线段细分备用--分割多段
This commit is contained in:
parent
9be2d014bc
commit
f4b9ba2b37
@ -19,6 +19,7 @@ import {
|
||||
distance2,
|
||||
linePoint,
|
||||
pointPolygon,
|
||||
calculateLineSegmentingPoint,
|
||||
} from '../utils';
|
||||
import { GraphicTransformEvent, ShiftData } from './GraphicTransformPlugin';
|
||||
|
||||
@ -57,6 +58,9 @@ export abstract class GraphicEditPlugin<
|
||||
export const addWaypointConfig: MenuItemOptions = {
|
||||
name: '添加路径点',
|
||||
};
|
||||
export const addWaySegmentingConfig: MenuItemOptions = {
|
||||
name: '细分',
|
||||
};
|
||||
export const removeWaypointConfig: MenuItemOptions = {
|
||||
name: '移除路径点',
|
||||
};
|
||||
@ -251,6 +255,21 @@ export function addLineWayPoint(
|
||||
graphic.linePoints = points;
|
||||
}
|
||||
|
||||
export function addPolygonSegmentingPoint(
|
||||
graphic: ILineGraphic,
|
||||
start: number,
|
||||
end: number,
|
||||
knife = 2
|
||||
) {
|
||||
const linePoints = graphic.linePoints;
|
||||
const points = linePoints.slice(0, start + 1);
|
||||
points.push(
|
||||
...calculateLineSegmentingPoint(linePoints[start], linePoints[end], knife)
|
||||
);
|
||||
points.push(...linePoints.slice(end));
|
||||
graphic.linePoints = points;
|
||||
}
|
||||
|
||||
function assertBezierWayPoint(i: number) {
|
||||
const c = i % 3;
|
||||
if (c !== 0) {
|
||||
|
@ -287,6 +287,31 @@ export function calculateLineMidpoint(p1: IPointData, p2: IPointData): Point {
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算线段细分坐标--线段分成几份
|
||||
* @param p1
|
||||
* @param p2
|
||||
* @param knife
|
||||
* @returns
|
||||
*/
|
||||
export function calculateLineSegmentingPoint(
|
||||
p1: IPointData,
|
||||
p2: IPointData,
|
||||
knife: number
|
||||
): IPointData[] {
|
||||
const segmentingPoints: IPointData[] = [];
|
||||
const x = p1.x < p2.x ? p1.x : p2.x;
|
||||
const y = p1.y < p2.y ? p1.y : p2.y;
|
||||
const w = Math.abs(p1.x - p2.x);
|
||||
const h = Math.abs(p1.y - p2.y);
|
||||
for (let i = 0; i < knife - 1; i++) {
|
||||
const pointX = x + (w * (i + 1)) / knife;
|
||||
const pointy = y + (h * (i + 1)) / knife;
|
||||
segmentingPoints.push(new Point(pointX, pointy));
|
||||
}
|
||||
return segmentingPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算点到直线距离
|
||||
* @param p1
|
||||
|
Loading…
Reference in New Issue
Block a user