|
@@ -1,4 +1,5 @@
|
|
|
import {
|
|
|
+ eqPoint,
|
|
|
getDiffPolygons,
|
|
|
getVectorLine,
|
|
|
isPolygonPointInner,
|
|
@@ -18,12 +19,12 @@ import { MathUtils } from "three";
|
|
|
import { diffArrayChange, rangMod } from "@/utils/shared";
|
|
|
import { globalWatch, installGlobalVar } from "@/core/hook/use-global-vars";
|
|
|
import { useStore } from "@/core/store";
|
|
|
-import { computed, reactive, watchEffect } from "vue";
|
|
|
+import { computed, reactive, Ref, toRaw, watchEffect } from "vue";
|
|
|
import { Transform } from "konva/lib/Util";
|
|
|
import { sortFn } from "@/core/store/store";
|
|
|
import { getLineIconEndpoints, getSnapLine } from "../line-icon";
|
|
|
-import { useTestPoints } from "@/core/hook/use-debugger";
|
|
|
import { useDrawIngData } from "@/core/hook/use-draw";
|
|
|
+import { useTestPoints } from "@/core/hook/use-debugger";
|
|
|
|
|
|
const minAngle = MathUtils.degToRad(0.1);
|
|
|
const palAngle = MathUtils.degToRad(20);
|
|
@@ -212,71 +213,121 @@ export const useGetDiffIconPolygons = installGlobalVar(() => {
|
|
|
});
|
|
|
|
|
|
// 计算与icon相差的多边形
|
|
|
-export const useGetDiffLineIconPolygons = (line: LineData["lines"][0]) => {
|
|
|
+export const useGetDiffLineIconPolygons = (line: LineData["lines"][0], linePoints: Ref<Pos[]>) => {
|
|
|
const store = useStore();
|
|
|
- const drawStore = useDrawIngData()
|
|
|
- const linePoints = computed(() => getSnapLine(store, { lineId: line.id }));
|
|
|
+ const drawStore = useDrawIngData();
|
|
|
const linevv = computed(() => verticalVector(lineVector(linePoints.value!)));
|
|
|
const icons = computed(() => {
|
|
|
- if (drawStore.lineIcon) {
|
|
|
- return drawStore.lineIcon.concat(store.getTypeItems("lineIcon"))
|
|
|
- } else {
|
|
|
- return store.getTypeItems("lineIcon")
|
|
|
- }
|
|
|
+ const icons = store
|
|
|
+ .getTypeItems("lineIcon")
|
|
|
+ .concat(drawStore.lineIcon || []);
|
|
|
+ return icons.filter((item) => !item.hide);
|
|
|
});
|
|
|
const lineIcons = computed(() =>
|
|
|
icons.value.filter((icon) => icon.lineId === line.id)
|
|
|
);
|
|
|
- const interPolygons = computed(() => {
|
|
|
+
|
|
|
+ const interSteps = computed(() => {
|
|
|
const lineSteps = lineIcons.value
|
|
|
- .map((icon) =>
|
|
|
- icon.endLen > icon.startLen
|
|
|
- ? [icon.startLen, icon.endLen]
|
|
|
- : [icon.endLen, icon.startLen]
|
|
|
- )
|
|
|
- .sort((line1, line2) => line1[0] - line2[0]);
|
|
|
+ .map((icon) => {
|
|
|
+ const openSide = icon.openSide;
|
|
|
+ const endLen = icon.endLen || 0.001;
|
|
|
+ const startLen = icon.startLen || 0.001;
|
|
|
+ const inv = endLen < startLen;
|
|
|
+ return {
|
|
|
+ lens: inv ? [endLen, startLen] : [startLen, endLen],
|
|
|
+ openSide: inv ? (openSide === "LEFT" ? "RIGHT" : "LEFT") : openSide,
|
|
|
+ };
|
|
|
+ })
|
|
|
+ .sort((line1, line2) => line1.lens[0] - line2.lens[0]);
|
|
|
if (!lineSteps.length) return [];
|
|
|
|
|
|
- const interSteps: number[][] = [];
|
|
|
+ const interSteps: { lens: number[]; openSide: "LEFT" | "RIGHT" }[] = [];
|
|
|
let i = 0;
|
|
|
do {
|
|
|
- const startStep = lineSteps[i][0];
|
|
|
- let endStep = lineSteps[i][1];
|
|
|
+ const startStep = lineSteps[i].lens[0];
|
|
|
+ const openSide = lineSteps[i].openSide;
|
|
|
+ let endStep = lineSteps[i].lens[1];
|
|
|
for (i++; i < lineSteps.length; i++) {
|
|
|
- if (lineSteps[i][0] <= endStep) {
|
|
|
- if (lineSteps[i][1] > endStep) {
|
|
|
- endStep = lineSteps[i][1];
|
|
|
+ if (lineSteps[i].lens[0] <= endStep) {
|
|
|
+ if (lineSteps[i].lens[1] > endStep) {
|
|
|
+ endStep = lineSteps[i].lens[1];
|
|
|
}
|
|
|
} else {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- interSteps.push([startStep, endStep]);
|
|
|
+ interSteps.push({
|
|
|
+ lens: [startStep, endStep],
|
|
|
+ openSide,
|
|
|
+ });
|
|
|
} while (i < lineSteps.length);
|
|
|
|
|
|
- const interLines = interSteps.map((steps) =>
|
|
|
- getLineIconEndpoints(linePoints.value!, {
|
|
|
- startLen: steps[0],
|
|
|
- endLen: steps[1],
|
|
|
- })
|
|
|
- );
|
|
|
+ return interSteps;
|
|
|
+ });
|
|
|
+
|
|
|
+ const interLines = computed(() =>
|
|
|
+ interSteps.value.map((steps) => ({
|
|
|
+ openSide: steps.openSide,
|
|
|
+ points: getLineIconEndpoints(linePoints.value!, {
|
|
|
+ startLen: steps.lens[0],
|
|
|
+ endLen: steps.lens[1],
|
|
|
+ }),
|
|
|
+ }))
|
|
|
+ );
|
|
|
|
|
|
- return interLines.map(interLine => {
|
|
|
- const topOffset = linevv.value.clone().multiplyScalar(line.strokeWidth)
|
|
|
- const botOffset = topOffset.clone().multiplyScalar(-1)
|
|
|
+ const stepLines = computed(() => {
|
|
|
+ if (!linePoints.value?.length || !interLines.value.length) return [];
|
|
|
+
|
|
|
+ const steps: Pos[][] = [];
|
|
|
+ if (!eqPoint(linePoints.value[0], interLines.value[0].points[0])) {
|
|
|
+ steps.push([linePoints.value[0], interLines.value[0].points[0]]);
|
|
|
+ }
|
|
|
+ let start = interLines.value[0].points[1];
|
|
|
+
|
|
|
+ let i = 1;
|
|
|
+ for (; i < interLines.value.length; i++) {
|
|
|
+ const iLine = interLines.value[i];
|
|
|
+ steps.push([start, iLine.points[0]]);
|
|
|
+ start = iLine.points[1];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!eqPoint(start, linePoints.value[1])) {
|
|
|
+ steps.push([start, linePoints.value[1]]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return steps;
|
|
|
+ });
|
|
|
+
|
|
|
+ const subStepsLines = computed(() => {
|
|
|
+ return interLines.value.map((il) => {
|
|
|
+ return il.openSide === "RIGHT" ? il.points : [...il.points].reverse();
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ const interPolygons = computed(() => {
|
|
|
+ return interLines.value.map((il) => {
|
|
|
+ const interLine = il.points;
|
|
|
+ const topOffset = linevv.value.clone().multiplyScalar(line.strokeWidth);
|
|
|
+ const botOffset = topOffset.clone().multiplyScalar(-1);
|
|
|
return [
|
|
|
topOffset.clone().add(interLine[0]),
|
|
|
topOffset.clone().add(interLine[1]),
|
|
|
botOffset.clone().add(interLine[1]),
|
|
|
botOffset.clone().add(interLine[0]),
|
|
|
- ]
|
|
|
- })
|
|
|
+ ];
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- return (polygon: Pos[]) => {
|
|
|
- if (!interPolygons.value.length) {
|
|
|
- return [polygon];
|
|
|
- }
|
|
|
- return getDiffPolygons(polygon, interPolygons.value)
|
|
|
+ return {
|
|
|
+ diff: (polygon: Pos[]) => {
|
|
|
+ const result = interPolygons.value.length
|
|
|
+ ? getDiffPolygons(polygon, interPolygons.value)
|
|
|
+ : [polygon];
|
|
|
+
|
|
|
+ return result;
|
|
|
+ },
|
|
|
+ subSteps: subStepsLines,
|
|
|
+ steps: stepLines,
|
|
|
};
|
|
|
};
|