Pārlūkot izejas kodu

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

Improved indentation: space to differentiate function definition from its usage
Improved method name from 'getRadius()' to 'getRadiusValue()'
Dependences:
+ app/components/line-segment-component/models/line-segment-model.js    : OK
+ app/components/middle-point/models/middle-point-model.js              : getIntersectionWithCircumference (circumference): const radius = circumference.getRadiusValue();
+ app/components/circumference-component/models/circumference-model.js  : getRadius() -> getRadiusValue();
   getIntersectionsByCircumference(circumference):
    const r1=this.getRadiusValue(), r2=circumference.getRadiusValue();const rA=this.getRadiusValue(),rB=circumference.getRadiusValue();
    getIntersectionByLine(lineSegment): radius = this.getRadiusValue();
+ app/components/circumference-component/drawers/circumference-drawer.js
    drawCircumference(circumference):  innerRadius: circumference.getRadiusValue(), outerRadius: circumference.getRadiusValue(),
    update(aggregator, e): aggregator.konvaObject.innerRadius(aggregator.genericObject.getRadiusValue()); aggregator.konvaObject.outerRadius(aggregator.genericObject.getRadiusValue());
leo 2 gadi atpakaļ
vecāks
revīzija
d2d0018aa8

+ 47 - 44
src/app/components/circumference-component/models/circumference-model.js

@@ -26,47 +26,50 @@ export class CircumferenceModel extends GeometricObject {
     super.setClass(ELEMENTS_CLASS.CIRCUMFERENCE);
     this.definitions.push(this.center);
     this.definitions.push(this.radius);
-  }
+    }
 
   getCenter() {
     return this.center;
-  }
+    }
 
   getPoint() {
     return this.radius;
-  }
+    }
 
-  getRadius() {
-    /* Deixar mais intuitiva...
-    this._coordinates[0] = this.center.posX;
-    this._coordinates[1] = this.center.posY;
-    this._coordinates[2] = this.radius.posX;
-    this._coordinates[3] = this.radius.posY;
-    const legA = this._coordinates[2] - this._coordinates[0];
-    const legB = this._coordinates[3] - this._coordinates[1];
-    const radius = Math.sqrt(Math.pow(legA, 2) + Math.pow(legB, 2)); // Desnecessario!
-    return radius;
-    */
+  getRadius () {
+    return this.radius; // the point
+    }
+
+  getRadiusValue () { // return ||this.center - this.radius||
+    //_ Deixar mais intuitiva...
+    //_ this._coordinates[0] = this.center.posX;
+    //_ this._coordinates[1] = this.center.posY;
+    //_ this._coordinates[2] = this.radius.posX;
+    //_ this._coordinates[3] = this.radius.posY;
+    //_ const legA = this._coordinates[2] - this._coordinates[0];
+    //_ const legB = this._coordinates[3] - this._coordinates[1];
+    //_ const radius = Math.sqrt(Math.pow(legA, 2) + Math.pow(legB, 2)); // Desnecessario!
+    //_ return radius;
     var Cx, Cy, Ax, Ay;
     Cx = this._coordinates[0] = this.center.posX;
     Cy = this._coordinates[1] = this.center.posY;
     Ax = this._coordinates[2] = this.radius.posX;
     Ay = this._coordinates[3] = this.radius.posY;
-    //D console.log("circumference-model.js: circ((" + Cx +","+ Cy +"), ("+Ax+","+Ay+")");
+    //D console.log("circumference-model.js: circ(" + Cx + "," +  Cy  + "), (" + Ax + "," + Ay + ")");
     const dx = Ax - Cx;
     const dy = Ay - Cy;
     const radius = Math.sqrt(dx * dx + dy * dy);
     return radius;
-  }
+    }
 
-  getStraight() {
+  getStraight () {
     const dx = this.radius.posX - this.center.posX;
     const dy = this.radius.posY - this.center.posY;
     const c = Math.sqrt(dy * dy + dx * dx);
     return [dx, dy, c];
-  }
+    }
 
-  getDirection() {
+  getDirection () {
     const aX = this.center.posX;
     const aY = this.center.posY;
     const bX = this.radius.posX;
@@ -74,32 +77,32 @@ export class CircumferenceModel extends GeometricObject {
     const a = bX - aX;
     const b = bY - aY;
     return [a, b];
-  }
+    }
 
-  getIntersection(geometricObject) {
+  getIntersection (geometricObject) {
     switch (geometricObject.elementClass) {
       case ELEMENTS_CLASS.LINE: // StraightLine
-        return geometricObject.getIntersectionWithCircumference(this); // Delegate to StraightLine    
+        return geometricObject.getIntersectionWithCircumference(this); // Delegate to StraightLine
       case ELEMENTS_CLASS.LINE_SEGMENT:
         return this.getIntersectionByLine(geometricObject); //TODO melhor 'with' que 'by'
       case ELEMENTS_CLASS.CIRCUMFERENCE:
         return this.getIntersectionsByCircumference(geometricObject); //TODO melhor 'with' que 'by'
       default:
         break;
+      }
     }
-  }
 
-  distance(center) {
+  distance (center) {
     const dx = center.posX - this.center.posX;
     const dy = center.posY - this.center.posY;
     const dist = Math.sqrt(dy * dy + dx * dx);
     return dist;
-  }
+    }
 
-  getIntersectionsByCircumference(circumference) {
+  getIntersectionsByCircumference (circumference) {
     //TODO if (this.cente().igual(cd.C())) return null; // duas circ. com mesmo raio => devolva "null" (ambiguidade!)
-    const r1 = this.getRadius(); // raio circ. atual
-    const r2 = circumference.getRadius(); // raio circ. "cd"
+    const r1 = this.getRadiusValue(); // raio circ. atual
+    const r2 = circumference.getRadiusValue(); // raio circ. "cd"
     const d = this.distance(circumference); // distancia entre os raios das circ.
     if (r1 + r2 < d || Math.abs(r1 - r2) > d) return null;
     const A = this.center; // pega o centro da circunferencia atual
@@ -113,8 +116,8 @@ export class CircumferenceModel extends GeometricObject {
     let v1 = B.posY - A.posY;
     let u = u1 * cos + v1 * sen;
     let v = -u1 * sen + v1 * cos;
-    const rA = this.getRadius();
-    const rB = circumference.getRadius();
+    const rA = this.getRadiusValue();
+    const rB = circumference.getRadiusValue();
     u = (u * u - rB * rB + rA * rA) / (2 * u);
     v = Math.sqrt(rA * rA - u * u);
     v1 = v;
@@ -131,14 +134,14 @@ export class CircumferenceModel extends GeometricObject {
       new IntersectionModel(x1, y1, undefined, this, circumference, true, 0),
       new IntersectionModel(x2, y2, undefined, this, circumference, true, 1)
     ];
-  }
+    }
 
 
   /// Get Intersection Poin By Circumference and Line Segment
   /// @param {LineSegmentModel  } lineSegment 
-  getIntersectionByLine(lineSegment) {
+  getIntersectionByLine (lineSegment) {
     const pointA = lineSegment.pointA, pointB = lineSegment.pointB; // sl = segment(A,B)
-    const center = this.center, radius = this.getRadius();          // c0 = circunference(C,A) = circ("center,radius")
+    const center = this.center, radius = this.getRadiusValue();     // c0 = circunference(C,A) = circ("center,radius")
 
     const dx = pointB.posX - pointA.posX;
     const dy = pointB.posY - pointA.posY;
@@ -159,7 +162,7 @@ export class CircumferenceModel extends GeometricObject {
 
     if (delta < 0) {
       return [PA, PB];
-    }
+      }
 
     const deltaSqrt = Math.sqrt(delta);
     const root1 = -D + deltaSqrt;
@@ -170,7 +173,7 @@ export class CircumferenceModel extends GeometricObject {
     if (delta == 0) {
       PA.bind(x1, y1, undefined, lineSegment, this, true, 0);
       return [PA, PB];
-    }
+      }
 
     const x2 = pointA.posX - dx * root2;
     const y2 = pointA.posY - dy * root2;
@@ -184,13 +187,13 @@ export class CircumferenceModel extends GeometricObject {
 
       if (!this.insideSegment(PB.posX, PB.posY))
         PB.bind(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, lineSegment, this, false, 1)
-    }
+      }
 
     return [PA, PB];
-  }
+    }
 
   // Verify intersection using "level set"
-  insideSegment(intersecX, intersecY) {
+  insideSegment (intersecX, intersecY) {
     const valuesR = this.getDirection();
     const dirX = valuesR[0];
     const dirY = valuesR[1];
@@ -201,7 +204,7 @@ export class CircumferenceModel extends GeometricObject {
 
     if (cInterA < cRA) {
       return false;
-    }
+      }
 
     // comparaca cv do ponto B < cv da intersec =>  vazio
     const cRB = dirX * this.radius.posX + dirY * this.radius.posY;
@@ -210,12 +213,12 @@ export class CircumferenceModel extends GeometricObject {
       this.posX = Number.MAX_SAFE_INTEGER;
       this.posY = Number.MAX_SAFE_INTEGER;
       return false;
-    }
+      }
 
     return true;
-  }
+    }
 
-  static do(map, list) {
+  static do (map, list) {
     const id = map.get("id");
     const centerId = map.get("param")[0];
     const radiusId = map.get("param")[1];
@@ -225,6 +228,6 @@ export class CircumferenceModel extends GeometricObject {
     const circumference = new CircumferenceModel(center, radius, id);
     circumference.setLabel(label);
     return circumference;
-  }
+    }
 
-}
+  } // export class CircumferenceModel extends GeometricObject