Browse Source

fix: 优化计算流程

bill 2 months ago
parent
commit
6ecaaf511d

+ 1 - 1
src/core/components/line/attach-view.ts

@@ -139,7 +139,7 @@ export const useGetExtendPolygon = installGlobalVar(() => {
     const polygon = [...lineRect];
     const linev = lineVector(linePoints);
     if (!useJoin) {
-      return polygon
+      return polygon;
     }
 
     linePoints.forEach((point, ndx) => {

+ 11 - 3
src/core/components/line/single-line.vue

@@ -111,13 +111,21 @@ const props = defineProps<{
 }>();
 
 const getExtendPolygon = useGetExtendPolygon();
+const showEditPoint = computed(
+  () => (!mode.include(Mode.readonly) && props.canEdit) || isDrawIng.value
+);
 const polygon = computed(() =>
   getExtendPolygon(props.data, props.line, !showEditPoint.value)
 );
+const dragIng = computed(
+  () =>
+    props.dragPointIds?.length &&
+    (props.dragPointIds.includes(props.line.a) ||
+      props.dragPointIds.includes(props.line.b))
+);
 const getDiffPolygons = useGetDiffPolygons();
-const diffPolygons = computed(() => getDiffPolygons(polygon.value));
-const showEditPoint = computed(
-  () => (!mode.include(Mode.readonly) && props.canEdit) || isDrawIng.value
+const diffPolygons = computed(() =>
+  !dragIng.value ? getDiffPolygons(polygon.value) : [polygon.value]
 );
 
 const emit = defineEmits<{

+ 0 - 2
src/example/platform/platform-draw.ts

@@ -234,7 +234,6 @@ const drawSceneResource = async (resource: SceneResource, draw: Draw) => {
     draw.store.addItem("line", geo);
   }
 
-  console.log(icons, texts, images)
   draw.store.addItems("icon", icons);
   draw.store.addItems("text", texts);
   draw.store.addItems("image", images);
@@ -253,7 +252,6 @@ export const drawPlatformResource = async (
   const resource = await getResource({ ...sceneData, scale: 100 });
   let bound = null as ReturnType<ReturnType<typeof genBound>["get"]>;
 
-  console.log(resource)
   await draw.history.onceTrack(async () => {
     draw.store.setConfig({ proportion: { scale: 10, unit: "mm" } });
     bound = await drawSceneResource(resource, draw);

+ 0 - 1
src/example/platform/resource-swkk.ts

@@ -405,7 +405,6 @@ export const getResource = async ({
 
   const compass = await getCompass(scene);
 
-  console.log(scale)
   const reqs: Promise<any>[] = [
     getCompass(scene),
     getCoverLine(scene, key, scale)

+ 10 - 7
src/utils/math.ts

@@ -644,16 +644,19 @@ export const getDiffPolygons = (
   targetPolygons: Pos[][]
 ) => {
   const geo1 = originPolygon.map(({ x, y }) => [x, y]);
-  geo1.push(geo1[0])
+  geo1.push(geo1[0]);
   const geo2s = targetPolygons.map((targetPolygon) => {
     const geo2 = targetPolygon.map(({ x, y }) => [x, y]);
     geo2.push(geo2[0]);
     return geo2;
   });
-
-  const subGeos = diffPolygons([geo1], geo2s);
-  return subGeos.map((mulPolygon) => {
-    const polygon = mulPolygon as number[][][];
-    return polygon[0].map((position) => ({ x: position[0], y: position[1] }));
-  }) as Pos[][];
+  try {
+    const subGeos = diffPolygons([geo1], geo2s);
+    return subGeos.map((mulPolygon) => {
+      const polygon = mulPolygon as number[][][];
+      return polygon[0].map((position) => ({ x: position[0], y: position[1] }));
+    }) as Pos[][];
+  } catch {
+    return [originPolygon];
+  }
 };