浏览代码

Update 'src/app/components/line-component/models/line-model.js'

Improved indentation: inserted space to differentiate function declaration from its use.
Introduced 2 console.log to help in debug when launching error
leo 2 年之前
父节点
当前提交
1adf51c883
共有 1 个文件被更改,包括 21 次插入19 次删除
  1. 21 19
      src/app/components/line-component/models/line-model.js

+ 21 - 19
src/app/components/line-component/models/line-model.js

@@ -57,40 +57,42 @@ export class LineModel extends LineSegmentModel {
   // otherwise O2.y<>0 => y = (O2.x * B1.x + O2.y * B1.y - O2.x * x) / O2.y
   //
   // Return: .app/components/intersection-component/models/intersection-model.js
-  getIntersectionWithStraightLine(sl) {
+  getIntersectionWithStraightLine (sl) {
     try {//D //leo
       const A1 = this.pointA, A2 = this.pointB; // this = SL(A1,A2)
-      const A3 = sl.pointA, A4 = sl.pointB;    // sl   = SL(A3, A4)
-      var A1x = A1.posX, A1y = A1.posY,       // A1 -> this
-        A2x = A2.posX, A2y = A2.posY;       // A2 -> this
-      var B1x = A3.posX, B1y = A3.posY,       // B1 -> sl
-        B2x = A4.posX, B2y = A4.posY;       // B2 -> sl
-      var d1x = A2x - A1x, d1y = A2y - A1y,       // d1 = A2-A1
-        d2x = B2x - B1x, d2y = B2y - B1y,       // d2 = B2-B1
-        O1x = -d1y, O1y = d1x,           // O1 = (-d1.y,  d1.x) ortogonal a reta r=this
-        O2x = -d2y, O2y = d2x,           // O2 = (-d2.y, d2.x) ortogonal a reta s
-        x, y;                 // P=(x,y) ponto procurado
+      const A3 = sl.pointA, A4 = sl.pointB;     // sl   = SL(A3, A4)
+      var A1x = A1.posX, A1y = A1.posY,         // A1 -> this
+          A2x = A2.posX, A2y = A2.posY;         // A2 -> this
+      var B1x = A3.posX, B1y = A3.posY,         // B1 -> sl
+          B2x = A4.posX, B2y = A4.posY;         // B2 -> sl
+      var d1x = A2x - A1x, d1y = A2y - A1y,     // d1 = A2-A1
+          d2x = B2x - B1x, d2y = B2y - B1y,     // d2 = B2-B1
+          O1x = -d1y, O1y = d1x,                // O1 = (-d1.y,  d1.x) ortogonal a reta r=this
+          O2x = -d2y, O2y = d2x,                // O2 = (-d2.y, d2.x) ortogonal a reta s
+          x, y;                                 // P=(x,y) ponto procurado
 
       if (O2y * O1x - O1y * O2x == 0) { // "Reta: erro, divisao por zero"
-        console.log("/app/components/line-component/models/line-model.js: erro: divisao por zero!");
+        console.log("app/components/line-component/models/line-model.js: erro: divisao por zero!"); //D
         return null;
-      }
+        }
       x = (O2y * (O1x * A1x + O1y * A1y) - O1y * (O2x * B1x + O2y * B1y)) / (O2y * O1x - O1y * O2x);
       if (Math.abs(O1y) > Erro)
         y = (O1x * A1x + O1y * A1y - O1x * x) / O1y;
-      else
+      else {
         if (Math.abs(O2y) > Erro)
           y = (O2x * B1x + O2y * B1y - O2x * x) / O2y;
-        else
+        else {
           if (O1y != 0.0)
             y = (O1x * A1x + O1y * A1y - O1x * x) / O1y;
           else
             if (O2y != 0.0)
               y = (O2x * B1x + O2y * B1y - O2x * x) / O2y;
             else {
-              console.log("/app/components/line-component/models/line-model.js: erro: O2y=0!");
+              console.log("app/components/line-component/models/line-model.js: erro: O2y=0!"); //D
               return null;
             }
+          }
+        }
       //D console.log("line-model.js: getIntersectionWithStraightLine(sl): (" + x + "," + y + ") = " +
       //D             "inter(r(P("+A1x+","+A1y+"),P("+A2x+","+A2y+")), s(P("+B1x+","+B1y+"),P("+B2x+","+B2y+"))");
       return [new IntersectionModel(x, y, undefined, this, sl, true, 0)];
@@ -109,7 +111,7 @@ export class LineModel extends LineSegmentModel {
 
 
   // Starting point to intersection started with StraightLine
-  getIntersection(geometricObject) {
+  getIntersection (geometricObject) {
     try { //D //leo
       //D console.log("line-model.js.getIntersection: tipo=" + geometricObject.elementClass);
       switch (geometricObject.elementClass) { // ./app/core/enums/elements-class-enum.js: POINT=0; INTERSECTION_POINT=1; CIRCUMFERENCE=3; LINE=4; LINE_SEGMENT=6,...
@@ -121,7 +123,7 @@ export class LineModel extends LineSegmentModel {
           return this.getIntersectionWithCircumference(geometricObject); //TODO melhor 'with' que 'by'
         default: break;
       }
-    } catch (e) { console.log("app/components/line-component/models/line-model.js: getIntersection(.): erro!\n" + e.stack); }
+    } catch (e) { console.log("app/components/line-component/models/line-model.js: getIntersection(.): error " + e + "\n" + e.stack); }
 
   }
 
@@ -135,4 +137,4 @@ export class LineModel extends LineSegmentModel {
     return new LineModel(pointA, pointB, label, id);
   }
 
-}
+}