|
@@ -1,14 +1,14 @@
|
|
|
-import { MathUtils, Vector2 } from "three";
|
|
|
+// import { MathUtils, Vector2 } from "three";
|
|
|
import { DEV } from "../../../env";
|
|
|
import {
|
|
|
getLineIntersection,
|
|
|
getLineDist,
|
|
|
getLineNearPointDist,
|
|
|
- getDire2Angle,
|
|
|
- getLineDire,
|
|
|
- getVerticalDire,
|
|
|
- createLineByDire,
|
|
|
- getLineProjection,
|
|
|
+ // getDire2Angle,
|
|
|
+ // getLineDire,
|
|
|
+ // getVerticalDire,
|
|
|
+ // createLineByDire,
|
|
|
+ // getLineProjection,
|
|
|
RelationshipEnum,
|
|
|
round,
|
|
|
} from "../../../shared/math";
|
|
@@ -20,17 +20,17 @@ import {
|
|
|
import { currentConstant } from "../../view-constant";
|
|
|
import {
|
|
|
generateWholeLineLineId,
|
|
|
- generateWholeLinePointId,
|
|
|
+ // generateWholeLinePointId,
|
|
|
generateWholeLinePoygonId,
|
|
|
getWholeLineLineRaw,
|
|
|
- getWholeLineLinesRawByPointId,
|
|
|
+ // getWholeLineLinesRawByPointId,
|
|
|
getWholeLinePoint,
|
|
|
getWholeLinePoints,
|
|
|
getWholeLinePolygonLines,
|
|
|
getWholeLinePolygonLinesByPoint,
|
|
|
wholeLineDelLineByPointIds,
|
|
|
wholeLineLineAddPoint,
|
|
|
- wholeLineLineIsolatePoint,
|
|
|
+ // wholeLineLineIsolatePoint,
|
|
|
wholeLineReplacePoint,
|
|
|
} from "./whole-line-base";
|
|
|
import { wholeLineAddPoint } from "./whole-line-mouse";
|
|
@@ -464,169 +464,169 @@ export const mergeWholeLinePointsByPoint = (
|
|
|
export const repeatMoveWholeLineLine = (
|
|
|
config: WholeLineAttrib,
|
|
|
lineAttrib: WholeLineLineAttrib,
|
|
|
- initPosition: number[][],
|
|
|
- angleRang = [10, 170]
|
|
|
+ initPosition: number[][]
|
|
|
+ // angleRang = [10, 170]
|
|
|
) => {
|
|
|
- const cache: {
|
|
|
- [key in string]: {
|
|
|
- id: string;
|
|
|
- split: boolean;
|
|
|
- refDire: number[];
|
|
|
- lineDire: number[];
|
|
|
- isFirst: boolean;
|
|
|
- };
|
|
|
- } = {};
|
|
|
- const linePointIds = lineAttrib.pointIds;
|
|
|
- const line0 = getWholeLinePoints(config, [linePointIds[0], linePointIds[1]]);
|
|
|
- const lineDire0 = getLineDire([
|
|
|
- line0[0].x,
|
|
|
- line0[0].y,
|
|
|
- line0[1].x,
|
|
|
- line0[1].y,
|
|
|
- ]);
|
|
|
- const line1 = getWholeLinePoints(config, [linePointIds[1], linePointIds[0]]);
|
|
|
- const lineDire1 = getLineDire([
|
|
|
- line1[0].x,
|
|
|
- line1[0].y,
|
|
|
- line1[1].x,
|
|
|
- line1[1].y,
|
|
|
- ]);
|
|
|
-
|
|
|
- const getPointRefInfo = (moveDire: number[], ndx: number) => {
|
|
|
- let isFirst = true;
|
|
|
- const curPointId = linePointIds[ndx];
|
|
|
- if (!cache[curPointId]) {
|
|
|
- cache[curPointId] = {} as any;
|
|
|
- } else {
|
|
|
- isFirst = false;
|
|
|
- // if (cache[curPointId].split) {
|
|
|
- return { ...cache[curPointId], isFirst };
|
|
|
- // }
|
|
|
- }
|
|
|
-
|
|
|
- const joinLines = getWholeLineLinesRawByPointId(config, curPointId).filter(
|
|
|
- (line) =>
|
|
|
- !(
|
|
|
- line.pointIds.includes(linePointIds[0]) &&
|
|
|
- line.pointIds.includes(linePointIds[1])
|
|
|
- )
|
|
|
- );
|
|
|
- const joinLineDires: number[][] = [];
|
|
|
- const lineDire = ndx === 0 ? lineDire0 : lineDire1;
|
|
|
-
|
|
|
- let invAngle = Number.MAX_VALUE;
|
|
|
- let invSelectLineId: string;
|
|
|
- let invSelectLineDire: number[] | null = null;
|
|
|
-
|
|
|
- let alongAngle = -Number.MAX_VALUE;
|
|
|
- let alongSelectLineId: string;
|
|
|
- let alongSelectLineDire: number[] | null = null;
|
|
|
-
|
|
|
- for (let { pointIds: joinPointIds, id } of joinLines) {
|
|
|
- joinPointIds = [
|
|
|
- linePointIds[ndx],
|
|
|
- ...joinPointIds.filter((id) => id !== linePointIds[ndx]),
|
|
|
- ];
|
|
|
- const joinLine = getWholeLinePoints(config, joinPointIds);
|
|
|
- const joinLineDire = getLineDire([
|
|
|
- joinLine[0].x,
|
|
|
- joinLine[0].y,
|
|
|
- joinLine[1].x,
|
|
|
- joinLine[1].y,
|
|
|
- ]);
|
|
|
- joinLineDires.push(joinLineDire);
|
|
|
- // if (["10", "14"].includes(id)) {
|
|
|
- // continue;
|
|
|
- // }
|
|
|
-
|
|
|
- const currentAngle = getDire2Angle(lineDire, joinLineDire);
|
|
|
- // 逆时针
|
|
|
- if (currentAngle > 0) {
|
|
|
- if (currentAngle < invAngle) {
|
|
|
- invAngle = currentAngle;
|
|
|
- invSelectLineId = id;
|
|
|
- invSelectLineDire = joinLineDire;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (currentAngle > alongAngle) {
|
|
|
- alongAngle = currentAngle;
|
|
|
- alongSelectLineId = id;
|
|
|
- alongSelectLineDire = joinLineDire;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- let pointJointLineDire: number[] | null = null;
|
|
|
- let angle: number | null = null;
|
|
|
- let selectLineId: string | null = null;
|
|
|
-
|
|
|
- if (!invSelectLineDire || !alongSelectLineDire) {
|
|
|
- pointJointLineDire = invSelectLineDire || alongSelectLineDire;
|
|
|
- selectLineId = invSelectLineDire ? invSelectLineId : alongSelectLineId;
|
|
|
- angle = invSelectLineDire ? invAngle : alongAngle;
|
|
|
- } else if (
|
|
|
- Math.abs(getDire2Angle(moveDire, invSelectLineDire)) <
|
|
|
- Math.abs(getDire2Angle(moveDire, alongSelectLineDire))
|
|
|
- ) {
|
|
|
- pointJointLineDire = invSelectLineDire;
|
|
|
- selectLineId = invSelectLineId;
|
|
|
- angle = invAngle;
|
|
|
- } else {
|
|
|
- pointJointLineDire = alongSelectLineDire;
|
|
|
- selectLineId = alongSelectLineId;
|
|
|
- angle = alongAngle;
|
|
|
- }
|
|
|
-
|
|
|
- let isSplitPoint = false;
|
|
|
- // 需要判定,如果参考线与当前线段夹角超过多少则不适合作为参考线
|
|
|
- let refLineAngle = Math.abs(MathUtils.radToDeg(angle));
|
|
|
- if (
|
|
|
- (pointJointLineDire !== null && refLineAngle > angleRang[1]) ||
|
|
|
- refLineAngle < angleRang[0]
|
|
|
- ) {
|
|
|
- console.log(
|
|
|
- "夹角不在范围,分割",
|
|
|
- selectLineId,
|
|
|
- ndx === 0 ? line0 : line1,
|
|
|
- refLineAngle
|
|
|
- );
|
|
|
- selectLineId = null;
|
|
|
- pointJointLineDire = getVerticalDire(pointJointLineDire);
|
|
|
- isSplitPoint = true;
|
|
|
-
|
|
|
- // 如果有多条线段,判断是否方向一致,不一致则要分割
|
|
|
- } else if (joinLines.length > 1) {
|
|
|
- const temp = pointJointLineDire;
|
|
|
- for (let i = 0; i < joinLines.length; i++) {
|
|
|
- if (temp === joinLineDires[i]) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- const angle =
|
|
|
- (getDire2Angle(temp, joinLineDires[i]) + Math.PI) % Math.PI;
|
|
|
-
|
|
|
- if (round(angle, 3) > 0) {
|
|
|
- console.log("方向不同,分割");
|
|
|
- isSplitPoint = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- cache[curPointId].refDire = pointJointLineDire;
|
|
|
- cache[curPointId].lineDire = lineDire;
|
|
|
- cache[curPointId].id = selectLineId;
|
|
|
- cache[curPointId].split = isSplitPoint;
|
|
|
- cache[curPointId].isFirst = isFirst;
|
|
|
-
|
|
|
- return cache[curPointId];
|
|
|
- };
|
|
|
+ // const cache: {
|
|
|
+ // [key in string]: {
|
|
|
+ // id: string;
|
|
|
+ // split: boolean;
|
|
|
+ // refDire: number[];
|
|
|
+ // lineDire: number[];
|
|
|
+ // isFirst: boolean;
|
|
|
+ // };
|
|
|
+ // } = {};
|
|
|
+ // const linePointIds = lineAttrib.pointIds;
|
|
|
+ // const line0 = getWholeLinePoints(config, [linePointIds[0], linePointIds[1]]);
|
|
|
+ // const lineDire0 = getLineDire([
|
|
|
+ // line0[0].x,
|
|
|
+ // line0[0].y,
|
|
|
+ // line0[1].x,
|
|
|
+ // line0[1].y,
|
|
|
+ // ]);
|
|
|
+ // const line1 = getWholeLinePoints(config, [linePointIds[1], linePointIds[0]]);
|
|
|
+ // const lineDire1 = getLineDire([
|
|
|
+ // line1[0].x,
|
|
|
+ // line1[0].y,
|
|
|
+ // line1[1].x,
|
|
|
+ // line1[1].y,
|
|
|
+ // ]);
|
|
|
+
|
|
|
+ // const getPointRefInfo = (moveDire: number[], ndx: number) => {
|
|
|
+ // let isFirst = true;
|
|
|
+ // const curPointId = linePointIds[ndx];
|
|
|
+ // if (!cache[curPointId]) {
|
|
|
+ // cache[curPointId] = {} as any;
|
|
|
+ // } else {
|
|
|
+ // isFirst = false;
|
|
|
+ // // if (cache[curPointId].split) {
|
|
|
+ // return { ...cache[curPointId], isFirst };
|
|
|
+ // // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // const joinLines = getWholeLineLinesRawByPointId(config, curPointId).filter(
|
|
|
+ // (line) =>
|
|
|
+ // !(
|
|
|
+ // line.pointIds.includes(linePointIds[0]) &&
|
|
|
+ // line.pointIds.includes(linePointIds[1])
|
|
|
+ // )
|
|
|
+ // );
|
|
|
+ // const joinLineDires: number[][] = [];
|
|
|
+ // const lineDire = ndx === 0 ? lineDire0 : lineDire1;
|
|
|
+
|
|
|
+ // let invAngle = Number.MAX_VALUE;
|
|
|
+ // let invSelectLineId: string;
|
|
|
+ // let invSelectLineDire: number[] | null = null;
|
|
|
+
|
|
|
+ // let alongAngle = -Number.MAX_VALUE;
|
|
|
+ // let alongSelectLineId: string;
|
|
|
+ // let alongSelectLineDire: number[] | null = null;
|
|
|
+
|
|
|
+ // for (let { pointIds: joinPointIds, id } of joinLines) {
|
|
|
+ // joinPointIds = [
|
|
|
+ // linePointIds[ndx],
|
|
|
+ // ...joinPointIds.filter((id) => id !== linePointIds[ndx]),
|
|
|
+ // ];
|
|
|
+ // const joinLine = getWholeLinePoints(config, joinPointIds);
|
|
|
+ // const joinLineDire = getLineDire([
|
|
|
+ // joinLine[0].x,
|
|
|
+ // joinLine[0].y,
|
|
|
+ // joinLine[1].x,
|
|
|
+ // joinLine[1].y,
|
|
|
+ // ]);
|
|
|
+ // joinLineDires.push(joinLineDire);
|
|
|
+ // // if (["10", "14"].includes(id)) {
|
|
|
+ // // continue;
|
|
|
+ // // }
|
|
|
+
|
|
|
+ // const currentAngle = getDire2Angle(lineDire, joinLineDire);
|
|
|
+ // // 逆时针
|
|
|
+ // if (currentAngle > 0) {
|
|
|
+ // if (currentAngle < invAngle) {
|
|
|
+ // invAngle = currentAngle;
|
|
|
+ // invSelectLineId = id;
|
|
|
+ // invSelectLineDire = joinLineDire;
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // if (currentAngle > alongAngle) {
|
|
|
+ // alongAngle = currentAngle;
|
|
|
+ // alongSelectLineId = id;
|
|
|
+ // alongSelectLineDire = joinLineDire;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // let pointJointLineDire: number[] | null = null;
|
|
|
+ // let angle: number | null = null;
|
|
|
+ // let selectLineId: string | null = null;
|
|
|
+
|
|
|
+ // if (!invSelectLineDire || !alongSelectLineDire) {
|
|
|
+ // pointJointLineDire = invSelectLineDire || alongSelectLineDire;
|
|
|
+ // selectLineId = invSelectLineDire ? invSelectLineId : alongSelectLineId;
|
|
|
+ // angle = invSelectLineDire ? invAngle : alongAngle;
|
|
|
+ // } else if (
|
|
|
+ // Math.abs(getDire2Angle(moveDire, invSelectLineDire)) <
|
|
|
+ // Math.abs(getDire2Angle(moveDire, alongSelectLineDire))
|
|
|
+ // ) {
|
|
|
+ // pointJointLineDire = invSelectLineDire;
|
|
|
+ // selectLineId = invSelectLineId;
|
|
|
+ // angle = invAngle;
|
|
|
+ // } else {
|
|
|
+ // pointJointLineDire = alongSelectLineDire;
|
|
|
+ // selectLineId = alongSelectLineId;
|
|
|
+ // angle = alongAngle;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // let isSplitPoint = false;
|
|
|
+ // // 需要判定,如果参考线与当前线段夹角超过多少则不适合作为参考线
|
|
|
+ // let refLineAngle = Math.abs(MathUtils.radToDeg(angle));
|
|
|
+ // if (
|
|
|
+ // (pointJointLineDire !== null && refLineAngle > angleRang[1]) ||
|
|
|
+ // refLineAngle < angleRang[0]
|
|
|
+ // ) {
|
|
|
+ // console.log(
|
|
|
+ // "夹角不在范围,分割",
|
|
|
+ // selectLineId,
|
|
|
+ // ndx === 0 ? line0 : line1,
|
|
|
+ // refLineAngle
|
|
|
+ // );
|
|
|
+ // selectLineId = null;
|
|
|
+ // pointJointLineDire = getVerticalDire(pointJointLineDire);
|
|
|
+ // isSplitPoint = true;
|
|
|
+
|
|
|
+ // // 如果有多条线段,判断是否方向一致,不一致则要分割
|
|
|
+ // } else if (joinLines.length > 1) {
|
|
|
+ // const temp = pointJointLineDire;
|
|
|
+ // for (let i = 0; i < joinLines.length; i++) {
|
|
|
+ // if (temp === joinLineDires[i]) {
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+ // const angle =
|
|
|
+ // (getDire2Angle(temp, joinLineDires[i]) + Math.PI) % Math.PI;
|
|
|
+
|
|
|
+ // if (round(angle, 3) > 0) {
|
|
|
+ // console.log("方向不同,分割");
|
|
|
+ // isSplitPoint = true;
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // cache[curPointId].refDire = pointJointLineDire;
|
|
|
+ // cache[curPointId].lineDire = lineDire;
|
|
|
+ // cache[curPointId].id = selectLineId;
|
|
|
+ // cache[curPointId].split = isSplitPoint;
|
|
|
+ // cache[curPointId].isFirst = isFirst;
|
|
|
+
|
|
|
+ // return cache[curPointId];
|
|
|
+ // };
|
|
|
|
|
|
return (move: number[]) => {
|
|
|
- const moveDire = new Vector2(move[0], move[1]).normalize().toArray();
|
|
|
- const pointInfos = [
|
|
|
- getPointRefInfo(moveDire, 0),
|
|
|
- getPointRefInfo(moveDire, 1),
|
|
|
- ];
|
|
|
+ // const moveDire = new Vector2(move[0], move[1]).normalize().toArray();
|
|
|
+ // const pointInfos = [
|
|
|
+ // getPointRefInfo(moveDire, 0),
|
|
|
+ // getPointRefInfo(moveDire, 1),
|
|
|
+ // ];
|
|
|
|
|
|
// console.log(pointInfos);
|
|
|
const positions = [
|
|
@@ -634,54 +634,54 @@ export const repeatMoveWholeLineLine = (
|
|
|
[initPosition[1][0] + move[0], initPosition[1][1] + move[1]],
|
|
|
];
|
|
|
const pointAttribs = getWholeLinePoints(config, lineAttrib.pointIds);
|
|
|
- if (pointInfos[0].refDire || pointInfos[1].refDire) {
|
|
|
- const currentPositions: number[][] = [];
|
|
|
- const joinDires = pointInfos.map(({ refDire }) =>
|
|
|
- refDire === null
|
|
|
- ? pointInfos[0].refDire || pointInfos[1].refDire
|
|
|
- : refDire
|
|
|
- );
|
|
|
-
|
|
|
- for (let i = 0; i < pointInfos.length; i++) {
|
|
|
- const joinDire = joinDires[i];
|
|
|
- const isSplit = pointInfos[i].split && pointInfos[i].isFirst;
|
|
|
- const joinLine = createLineByDire(joinDire, initPosition[i], 10);
|
|
|
-
|
|
|
- if (isSplit) {
|
|
|
- const addPointId = generateWholeLinePointId(config);
|
|
|
- config.points.push({
|
|
|
- ...pointAttribs[i],
|
|
|
- id: addPointId,
|
|
|
- });
|
|
|
- wholeLineLineIsolatePoint(
|
|
|
- config,
|
|
|
- line0,
|
|
|
- lineAttrib.pointIds[i],
|
|
|
- addPointId
|
|
|
- );
|
|
|
- }
|
|
|
- currentPositions[i] = getLineProjection(joinLine, positions[i]).point;
|
|
|
- }
|
|
|
- const firstMain =
|
|
|
- getLineDist(currentPositions[0], initPosition[0]) <
|
|
|
- getLineDist(currentPositions[1], initPosition[1]);
|
|
|
- const lineDire = firstMain ? lineDire0 : lineDire1;
|
|
|
- const lineStart = firstMain ? currentPositions[0] : currentPositions[1];
|
|
|
- const bitDire = firstMain ? joinDires[1] : joinDires[0];
|
|
|
- const bitStart = firstMain ? initPosition[1] : initPosition[0];
|
|
|
-
|
|
|
- const main = createLineByDire(lineDire, lineStart, 10);
|
|
|
- const bit = createLineByDire(bitDire, bitStart, 10);
|
|
|
- const lineEnd = getLineIntersection(main, bit);
|
|
|
-
|
|
|
- if (firstMain) {
|
|
|
- positions[0] = lineStart;
|
|
|
- positions[1] = lineEnd;
|
|
|
- } else {
|
|
|
- positions[1] = lineStart;
|
|
|
- positions[0] = lineEnd;
|
|
|
- }
|
|
|
- }
|
|
|
+ // if (pointInfos[0].refDire || pointInfos[1].refDire) {
|
|
|
+ // const currentPositions: number[][] = [];
|
|
|
+ // const joinDires = pointInfos.map(({ refDire }) =>
|
|
|
+ // refDire === null
|
|
|
+ // ? pointInfos[0].refDire || pointInfos[1].refDire
|
|
|
+ // : refDire
|
|
|
+ // );
|
|
|
+
|
|
|
+ // for (let i = 0; i < pointInfos.length; i++) {
|
|
|
+ // const joinDire = joinDires[i];
|
|
|
+ // const isSplit = pointInfos[i].split && pointInfos[i].isFirst;
|
|
|
+ // const joinLine = createLineByDire(joinDire, initPosition[i], 10);
|
|
|
+
|
|
|
+ // if (isSplit) {
|
|
|
+ // const addPointId = generateWholeLinePointId(config);
|
|
|
+ // config.points.push({
|
|
|
+ // ...pointAttribs[i],
|
|
|
+ // id: addPointId,
|
|
|
+ // });
|
|
|
+ // wholeLineLineIsolatePoint(
|
|
|
+ // config,
|
|
|
+ // line0,
|
|
|
+ // lineAttrib.pointIds[i],
|
|
|
+ // addPointId
|
|
|
+ // );
|
|
|
+ // }
|
|
|
+ // currentPositions[i] = getLineProjection(joinLine, positions[i]).point;
|
|
|
+ // }
|
|
|
+ // const firstMain =
|
|
|
+ // getLineDist(currentPositions[0], initPosition[0]) <
|
|
|
+ // getLineDist(currentPositions[1], initPosition[1]);
|
|
|
+ // const lineDire = firstMain ? lineDire0 : lineDire1;
|
|
|
+ // const lineStart = firstMain ? currentPositions[0] : currentPositions[1];
|
|
|
+ // const bitDire = firstMain ? joinDires[1] : joinDires[0];
|
|
|
+ // const bitStart = firstMain ? initPosition[1] : initPosition[0];
|
|
|
+
|
|
|
+ // const main = createLineByDire(lineDire, lineStart, 10);
|
|
|
+ // const bit = createLineByDire(bitDire, bitStart, 10);
|
|
|
+ // const lineEnd = getLineIntersection(main, bit);
|
|
|
+
|
|
|
+ // if (firstMain) {
|
|
|
+ // positions[0] = lineStart;
|
|
|
+ // positions[1] = lineEnd;
|
|
|
+ // } else {
|
|
|
+ // positions[1] = lineStart;
|
|
|
+ // positions[0] = lineEnd;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
pointAttribs[0].x = positions[0][0];
|
|
|
pointAttribs[0].y = positions[0][1];
|