|
@@ -20,6 +20,10 @@ import { computed, nextTick, reactive, Ref, watch } from "vue";
|
|
|
import { getLineIconEndpoints } from "../../../line-icon";
|
|
import { getLineIconEndpoints } from "../../../line-icon";
|
|
|
import { useDrawIngData } from "@/core/hook/use-draw";
|
|
import { useDrawIngData } from "@/core/hook/use-draw";
|
|
|
import { polygonDifference, polygonDifferenceOnly } from "@/utils/math-clip";
|
|
import { polygonDifference, polygonDifferenceOnly } from "@/utils/math-clip";
|
|
|
|
|
+import {
|
|
|
|
|
+ useViewerInvertTransform,
|
|
|
|
|
+ useViewerInvertTransformConfig,
|
|
|
|
|
+} from "@/core/hook/use-viewer";
|
|
|
|
|
|
|
|
export const useGetExtendPolygon = (lineData: Ref<LineData | undefined>) => {
|
|
export const useGetExtendPolygon = (lineData: Ref<LineData | undefined>) => {
|
|
|
const minAngle = MathUtils.degToRad(0.1);
|
|
const minAngle = MathUtils.degToRad(0.1);
|
|
@@ -28,8 +32,13 @@ export const useGetExtendPolygon = (lineData: Ref<LineData | undefined>) => {
|
|
|
type JInfo = { lej: LEJInfo | undefined; diffPolygons?: Pos[][] };
|
|
type JInfo = { lej: LEJInfo | undefined; diffPolygons?: Pos[][] };
|
|
|
const joinInfos = reactive({}) as Record<string, Record<string, JInfo>>;
|
|
const joinInfos = reactive({}) as Record<string, Record<string, JInfo>>;
|
|
|
|
|
|
|
|
|
|
+ const inv = useViewerInvertTransformConfig();
|
|
|
|
|
+ const getWidth = (width: number, fixed: boolean) =>
|
|
|
|
|
+ fixed ? width * inv.value.scaleX : width;
|
|
|
|
|
+
|
|
|
const getInfoKey = (line: LEJLine) =>
|
|
const getInfoKey = (line: LEJLine) =>
|
|
|
- line.points.reduce((t, p) => round(p.x, 3) + round(p.y, 3) + t, "") + line.width;
|
|
|
|
|
|
|
+ line.points.reduce((t, p) => round(p.x, 3) + round(p.y, 3) + t, "") +
|
|
|
|
|
+ line.width;
|
|
|
|
|
|
|
|
const setLEJInfo = (
|
|
const setLEJInfo = (
|
|
|
data: LineData,
|
|
data: LineData,
|
|
@@ -38,11 +47,11 @@ export const useGetExtendPolygon = (lineData: Ref<LineData | undefined>) => {
|
|
|
) => {
|
|
) => {
|
|
|
const origin = {
|
|
const origin = {
|
|
|
points: getLinePoints(data, originLine),
|
|
points: getLinePoints(data, originLine),
|
|
|
- width: originLine.strokeWidth,
|
|
|
|
|
|
|
+ width: getWidth(originLine.strokeWidth, originLine.fixed)
|
|
|
};
|
|
};
|
|
|
const target = {
|
|
const target = {
|
|
|
points: getLinePoints(data, targetLine),
|
|
points: getLinePoints(data, targetLine),
|
|
|
- width: targetLine.strokeWidth,
|
|
|
|
|
|
|
+ width: getWidth(targetLine.strokeWidth, targetLine.fixed)
|
|
|
};
|
|
};
|
|
|
const { originNdx } = getLEJJoinNdxs(origin.points, target.points);
|
|
const { originNdx } = getLEJJoinNdxs(origin.points, target.points);
|
|
|
const lej = getLineEdgeJoinInfo(origin, target, minAngle, palAngle);
|
|
const lej = getLineEdgeJoinInfo(origin, target, minAngle, palAngle);
|
|
@@ -60,7 +69,7 @@ export const useGetExtendPolygon = (lineData: Ref<LineData | undefined>) => {
|
|
|
const getLEJPolygon = (data: LineData, originLine: LineDataLine) => {
|
|
const getLEJPolygon = (data: LineData, originLine: LineDataLine) => {
|
|
|
const origin = {
|
|
const origin = {
|
|
|
points: getLinePoints(data, originLine),
|
|
points: getLinePoints(data, originLine),
|
|
|
- width: originLine.strokeWidth,
|
|
|
|
|
|
|
+ width: getWidth(originLine.strokeWidth, originLine.fixed)
|
|
|
};
|
|
};
|
|
|
if (!origin.points[0] || !origin.points[1]) return [];
|
|
if (!origin.points[0] || !origin.points[1]) return [];
|
|
|
const key = getInfoKey(origin);
|
|
const key = getInfoKey(origin);
|
|
@@ -118,8 +127,8 @@ export const useGetExtendPolygon = (lineData: Ref<LineData | undefined>) => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
let diffPolygons: Pos[][] = [];
|
|
let diffPolygons: Pos[][] = [];
|
|
|
- const pointIds = lines.flatMap(l => [l.a, l.b])
|
|
|
|
|
- const lineCount = lines.length
|
|
|
|
|
|
|
+ const pointIds = lines.flatMap((l) => [l.a, l.b]);
|
|
|
|
|
+ const lineCount = lines.length;
|
|
|
while (lines.length) {
|
|
while (lines.length) {
|
|
|
if (lines.length > 1) {
|
|
if (lines.length > 1) {
|
|
|
const select = selectLEJLines(lines)!;
|
|
const select = selectLEJLines(lines)!;
|
|
@@ -129,8 +138,8 @@ export const useGetExtendPolygon = (lineData: Ref<LineData | undefined>) => {
|
|
|
lines = lines.filter(
|
|
lines = lines.filter(
|
|
|
(line) => line !== select.origin && line !== select.target
|
|
(line) => line !== select.origin && line !== select.target
|
|
|
);
|
|
);
|
|
|
- origin.diffPolygons = diffPolygons
|
|
|
|
|
- target.diffPolygons = diffPolygons
|
|
|
|
|
|
|
+ origin.diffPolygons = diffPolygons;
|
|
|
|
|
+ target.diffPolygons = diffPolygons;
|
|
|
|
|
|
|
|
diffPolygons = [
|
|
diffPolygons = [
|
|
|
...diffPolygons,
|
|
...diffPolygons,
|
|
@@ -140,13 +149,13 @@ export const useGetExtendPolygon = (lineData: Ref<LineData | undefined>) => {
|
|
|
} else {
|
|
} else {
|
|
|
const key = getInfoKey({
|
|
const key = getInfoKey({
|
|
|
points: getLinePoints(data, lines[0]),
|
|
points: getLinePoints(data, lines[0]),
|
|
|
- width: lines[0].strokeWidth,
|
|
|
|
|
|
|
+ width: getWidth(lines[0].strokeWidth, lines[0].fixed)
|
|
|
});
|
|
});
|
|
|
if (!(key in joinInfos)) {
|
|
if (!(key in joinInfos)) {
|
|
|
joinInfos[key] = {};
|
|
joinInfos[key] = {};
|
|
|
}
|
|
}
|
|
|
const ndx = [lines[0].a, lines[0].b].findIndex(
|
|
const ndx = [lines[0].a, lines[0].b].findIndex(
|
|
|
- (id) => pointIds.filter(pid => id === pid).length === lineCount
|
|
|
|
|
|
|
+ (id) => pointIds.filter((pid) => id === pid).length === lineCount
|
|
|
);
|
|
);
|
|
|
joinInfos[key][ndx] = { lej: undefined, diffPolygons };
|
|
joinInfos[key][ndx] = { lej: undefined, diffPolygons };
|
|
|
lines = [];
|
|
lines = [];
|
|
@@ -156,7 +165,7 @@ export const useGetExtendPolygon = (lineData: Ref<LineData | undefined>) => {
|
|
|
|
|
|
|
|
const genLEJLine = (lineData: LineData, line: LineDataLine) => ({
|
|
const genLEJLine = (lineData: LineData, line: LineDataLine) => ({
|
|
|
points: getLinePoints(lineData, line),
|
|
points: getLinePoints(lineData, line),
|
|
|
- width: line.strokeWidth,
|
|
|
|
|
|
|
+ width: getWidth(line.strokeWidth, line.fixed)
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const init = (data: LineData) => {
|
|
const init = (data: LineData) => {
|
|
@@ -208,7 +217,7 @@ export const useGetExtendPolygon = (lineData: Ref<LineData | undefined>) => {
|
|
|
delete joinInfos[key];
|
|
delete joinInfos[key];
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
- { immediate: true, flush: 'post' }
|
|
|
|
|
|
|
+ { immediate: true, flush: "post" }
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -254,7 +263,7 @@ export const useGetExtendPolygon = (lineData: Ref<LineData | undefined>) => {
|
|
|
return (line: LineDataLine) => {
|
|
return (line: LineDataLine) => {
|
|
|
// console.error(lineLen(...getLinePoints(lineData.value!, line!)))
|
|
// console.error(lineLen(...getLinePoints(lineData.value!, line!)))
|
|
|
const polygon = lineData.value ? getLEJPolygon(lineData.value, line) : [];
|
|
const polygon = lineData.value ? getLEJPolygon(lineData.value, line) : [];
|
|
|
- return polygon
|
|
|
|
|
|
|
+ return polygon;
|
|
|
};
|
|
};
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -354,10 +363,12 @@ export const useGetDiffLineIconPolygons = (
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ const inv = useViewerInvertTransformConfig()
|
|
|
|
|
+ const getWidth = (line: LineDataLine) => line.fixed ? line.strokeWidth * inv.value.scaleX : line.strokeWidth
|
|
|
const interPolygons = computed(() => {
|
|
const interPolygons = computed(() => {
|
|
|
return interLines.value.map((il) => {
|
|
return interLines.value.map((il) => {
|
|
|
const interLine = il.points;
|
|
const interLine = il.points;
|
|
|
- const topOffset = linevv.value.clone().multiplyScalar(line.strokeWidth);
|
|
|
|
|
|
|
+ const topOffset = linevv.value.clone().multiplyScalar(getWidth(line));
|
|
|
const botOffset = topOffset.clone().multiplyScalar(-1);
|
|
const botOffset = topOffset.clone().multiplyScalar(-1);
|
|
|
return [
|
|
return [
|
|
|
topOffset.clone().add(interLine[0]),
|
|
topOffset.clone().add(interLine[0]),
|
|
@@ -370,6 +381,9 @@ export const useGetDiffLineIconPolygons = (
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
diff: (polygon: Pos[]) => {
|
|
diff: (polygon: Pos[]) => {
|
|
|
|
|
+ if (interPolygons.value.length) {
|
|
|
|
|
+ console.log(polygonDifference(polygon, interPolygons.value))
|
|
|
|
|
+ }
|
|
|
const result = interPolygons.value.length
|
|
const result = interPolygons.value.length
|
|
|
? polygonDifference(polygon, interPolygons.value)
|
|
? polygonDifference(polygon, interPolygons.value)
|
|
|
: [polygon];
|
|
: [polygon];
|