xushiting преди 2 години
родител
ревизия
bfc9e3bc8d
променени са 1 файла, в които са добавени 16 реда и са изтрити 12 реда
  1. 16 12
      src/graphic/Util/MathUtil.js

+ 16 - 12
src/graphic/Util/MathUtil.js

@@ -1252,7 +1252,7 @@ export default class MathUtil {
   }
 
   getHitInfoForThreeBezier(position, curve, rang = 3) {
-    const { x: offsetX, y: offsetY } = position
+    const { x: offsetX, y: offsetY } = position;
     // 用 x 求出对应的 t,用 t 求相应位置的 y,再比较得出的 y 与 offsetY 之间的差值
     const tsx = mathUtil.getThreeBezierT(
       curve.start.x,
@@ -1273,8 +1273,8 @@ export default class MathUtil {
         if (Math.abs(point.y - offsetY) < rang) {
           return {
             position: point,
-            distance: mathUtil.getDistance(point, position)
-          }
+            distance: mathUtil.getDistance(point, position),
+          };
         }
       }
     }
@@ -1298,8 +1298,8 @@ export default class MathUtil {
         if (Math.abs(point.x - offsetX) < rang) {
           return {
             position: point,
-            distance: mathUtil.getDistance(point, position)
-          }
+            distance: mathUtil.getDistance(point, position),
+          };
         }
       }
     }
@@ -1310,8 +1310,8 @@ export default class MathUtil {
     let bezierData = [];
     bezierData.push(curve.start.x);
     bezierData.push(curve.start.y);
-    bezierData.push(curve.control.x);
-    bezierData.push(curve.control.y);
+    bezierData.push(curve.controls[0].x);
+    bezierData.push(curve.controls[0].y);
     bezierData.push(curve.end.x);
     bezierData.push(curve.end.y);
     const { isHit, getInfo } = bezierUtil.measureBezier(...bezierData);
@@ -1321,18 +1321,22 @@ export default class MathUtil {
       distance: mathUtil.getDistance(position, {
         x: point[0],
         y: point[1],
-      })
+      }),
     };
   }
 
   getHitInfoForCurves(pos, curves) {
     let joinInfo;
     for (const curve of curves) {
-      const tempJoinInfo = curve.controls.length === 2
-        ? mathUtil.getHitInfoForThreeBezier(pos, curve, 8)
-        : mathUtil.getHitInfoForTwoBezier(pos.x, curve)
+      const tempJoinInfo =
+        curve.controls.length === 2
+          ? mathUtil.getHitInfoForThreeBezier(pos, curve, 8)
+          : mathUtil.getHitInfoForTwoBezier(pos.x, curve);
 
-      if (!joinInfo || (tempJoinInfo && tempJoinInfo.distance < joinInfo.distance)) {
+      if (
+        !joinInfo ||
+        (tempJoinInfo && tempJoinInfo.distance < joinInfo.distance)
+      ) {
         joinInfo = tempJoinInfo;
       }
     }