Victor Luiz Domingues 4 年 前
コミット
6f8ca25aa9
1 ファイル変更18 行追加46 行削除
  1. 18 46
      src/app/components/line-component/drawers/line-drawer.js

+ 18 - 46
src/app/components/line-component/drawers/line-drawer.js

@@ -87,64 +87,36 @@ export class LineDrawer extends LineSegmentDrawer {
     const pos = aggregator.genericObject.getMiddlePoint();
     aggregator.konvaObject.children[0].x(pos.posX);
     aggregator.konvaObject.children[0].y(pos.posY - 20);
-    super.batchDra
-    aggregator.konvaObject.children[1].points([
-      pointA.posX,
-      pointA.posY,
-      pointB.posX,
-      pointB.posY
-    ]);
-    super.batchDraw();
-  }
-
-  // insertPoint(aggregator) {
-  //   const pointA = aggregator.genericObject.pointA;
-  //   const pointB = aggregator.genericObject.pointB;
-  //   const pointCAggregator = this.pointDrawer.drawPoint();
-  //   const pointC = pointCAggregator.genericObject;
-  //   aggregator.konvaObject.points([
-  //     pointA.posX,
-  //     pointA.posY,
-  //     pointB.posX,
-  //     pointB.posY,
-  //     pointC.posX,
-  //     pointC.posY
-  //   ]);
-  //   super.batchDraw();
-  // }
-
-  static getKonvaLine(pointA, pointB, useLabel) {
-
-    const lineSegment = new LineSegmentModel(pointA, pointB);
-
-
     const xA = pointA.posX,
       xB = pointB.posX,
       yA = pointA.posY,
       yB = pointB.posY;
 
+    const slope = (yB - yA) / (xB - xA);
+    const linearCoefficient = (yA * xB - yB * xA) / (xB - xA);
 
+    const y = linearCoefficient;
+    const x = -linearCoefficient / slope;
+    const points = [x, 0, 0, y];
 
-    // x0 - x
-    const d1 = xB - xA,
-      // y0 - y
-      d2 = yB - yA;
-
-    // const dA = d1 * xA + d2 * yA;
-    // const dB = d1 * xB + d2 * yB;
-
-
-    const a = -d1 / d2;
-    const b = (a * xA) * -1;
+    aggregator.konvaObject.children[1].points(points);
+    super.batchDraw();
+  }
 
-    // y =  ax + b;
+  static getKonvaLine(pointA, pointB, useLabel) {
 
-    const Qy = -d1 / d2 * 0 + b;
-    const Px = (0 - b) / a;
+    const xA = pointA.posX,
+      xB = pointB.posX,
+      yA = pointA.posY,
+      yB = pointB.posY;
 
+    const slope = (yB - yA) / (xB - xA);
+    const linearCoefficient = (yA * xB - yB * xA) / (xB - xA);
 
-    const points = [Px, 0, 0, Qy];
+    const y = linearCoefficient;
+    const x = -linearCoefficient / slope;
 
+    const points = [x, 0, 0, y];
 
     const line = new Konva.Line({
       points: points,