13 Коміти 9bde13e3f4 ... 7c505924f1

Автор SHA1 Опис Дата
  Victor Luiz Domingues 7c505924f1 Merge branch 'develop' of http://200.144.254.107/git/victordomingues/poc-igeom 3 роки тому
  leo 6c12982295 Update 'src/app/core/enums/elements-class-enum.js' 4 роки тому
  leo 4dd2c396a3 Add 'src/app/components/line-component/drawers/line-drawer.js' 4 роки тому
  leo 6053c06976 Add 'src/app/components/line-component/models/line-model.js' 4 роки тому
  leo 98bbb864d2 Delete 'src/app/components/models/line-model.js' 4 роки тому
  leo 0c37901b58 New 'src/app/components/line-component/models/line-model.js' 4 роки тому
  leo ad1e8a1690 Update 'src/app/components/line-segment-component/drawers/line-segment-drawer.js' 4 роки тому
  leo 74f51745ff Update 'src/app/components/line-segment-component/models/line-segment-model.js' 4 роки тому
  leo 9420a02d69 Update 'src/app/components/point-component/models/point-model.js' 4 роки тому
  leo 39300b5260 Update 'src/app/components/circumference-component/models/circumference-model.js' 4 роки тому
  leo 2d5a147a61 Update 'src/app/components/intersection-component/drawers/intersection-drawer.js' 4 роки тому
  leo da4ae2cf9f Update 'src/app/components/intersection-component/services/intersection-service.js' 4 роки тому
  leo 90d169bd76 Update 'src/app/components/intersection-component/models/intersection-model.js' 4 роки тому

+ 50 - 28
src/app/components/circumference-component/models/circumference-model.js

@@ -1,7 +1,18 @@
+/*
+ * iGeom by LInE
+ * Geometric Object: Circumference
+ * Model to Circumference
+ * www.matematica.br/igeom
+ * ./app/components/line-component/models/circumference-model.js
+ * @version 2020/11/02: Implemented Line instersection
+ */
+
 import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
 import { GeometricObject } from "../../../core/models/objects/geometric-object";
 import { IntersectionModel } from "../../intersection-component/models/intersection-model";
+
 export class CircumferenceModel extends GeometricObject {
+
   constructor(center, radius, id) {
     super(id);
     this.center = center;
@@ -16,14 +27,35 @@ export class CircumferenceModel extends GeometricObject {
     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));
+    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+")");
+    const dx = Ax - Cx;
+    const dy = Ay - Cy;
+    const radius = Math.sqrt(dx * dx + dy * dy);
     return radius;
   }
 
@@ -43,12 +75,15 @@ export class CircumferenceModel extends GeometricObject {
     const b = bY - aY;
     return [a, b];
   }
+
   getIntersection(geometricObject) {
     switch (geometricObject.elementClass) {
+      case ELEMENTS_CLASS.LINE: // StraightLine
+        return geometricObject.getIntersectionWithCircumference(this); // Delegate to StraightLine    
       case ELEMENTS_CLASS.LINE_SEGMENT:
-        return this.getIntersectionByLine(geometricObject);
+        return this.getIntersectionByLine(geometricObject); //TODO melhor 'with' que 'by'
       case ELEMENTS_CLASS.CIRCUMFERENCE:
-        return this.getIntersectionsByCircumference(geometricObject);
+        return this.getIntersectionsByCircumference(geometricObject); //TODO melhor 'with' que 'by'
       default:
         break;
     }
@@ -62,8 +97,7 @@ export class CircumferenceModel extends GeometricObject {
   }
 
   getIntersectionsByCircumference(circumference) {
-    // if (this.cente().igual(cd.C()))
-    // return null; // duas circ. com mesmo raio => devolva "null" (ambiguidade!)
+    //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 d = this.distance(circumference); // distancia entre os raios das circ.
@@ -99,16 +133,12 @@ export class CircumferenceModel extends GeometricObject {
     ];
   }
 
-  /**
-   * Get Intersection Poin By Circumference and Line Segment
-   * @param {LineSegmentModel} lineSegment 
-   */
-  getIntersectionByLine(lineSegment) {
 
-    const pointA = lineSegment.pointA;
-    const pointB = lineSegment.pointB;
-    const center = this.center;
-    const radius = this.getRadius();
+  /// Get Intersection Poin By Circumference and Line Segment
+  /// @param {LineSegmentModel  } 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 dx = pointB.posX - pointA.posX;
     const dy = pointB.posY - pointA.posY;
@@ -128,10 +158,7 @@ export class CircumferenceModel extends GeometricObject {
     const PB = new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, lineSegment, this, false, 1);
 
     if (delta < 0) {
-      return [
-        PA,
-        PB
-      ];
+      return [PA, PB];
     }
 
     const deltaSqrt = Math.sqrt(delta);
@@ -142,10 +169,7 @@ export class CircumferenceModel extends GeometricObject {
 
     if (delta == 0) {
       PA.bind(x1, y1, undefined, lineSegment, this, true, 0);
-      return [
-        PA,
-        PB
-      ];
+      return [PA, PB];
     }
 
     const x2 = pointA.posX - dx * root2;
@@ -162,13 +186,10 @@ export class CircumferenceModel extends GeometricObject {
         PB.bind(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, lineSegment, this, false, 1)
     }
 
-    return [
-      PA,
-      PB
-    ];
-
+    return [PA, PB];
   }
 
+  // Verify intersection using "level set"
   insideSegment(intersecX, intersecY) {
     const valuesR = this.getDirection();
     const dirX = valuesR[0];
@@ -205,4 +226,5 @@ export class CircumferenceModel extends GeometricObject {
     circumference.setLabel(label);
     return circumference;
   }
-}
+
+}

+ 35 - 28
src/app/components/intersection-component/drawers/intersection-drawer.js

@@ -1,3 +1,12 @@
+/*
+ * iGeom by LInE
+ * Provides intersetion point to Geometric Objects (GO)
+ * www.matematica.br/igeom
+ * ./app/components/intersection-component/drawers/intersection-drawer.js
+ * @calledby 
+ * @version 2020/11/02: Implemented Line instersection.
+ */
+
 import { PointDrawer } from "../../point-component/drawers/point-drawer";
 import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
 import { Drawer } from "../../../core/drawers/drawer";
@@ -7,25 +16,26 @@ import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
 import { intersectionService } from "../services/intersection-service";
 
 export class IntersectionDrawer extends Drawer {
+
   static FIRST_OBJECT_STATE() {
     return "FIRST_OBJECT";
   }
+
   static SECOND_OBJECT_STATE() {
     return "SECOND_OBJECTf";
   }
+
   constructor() {
     super();
     this.aggregatorA;
     this.aggregatorB;
     this.label;
-    this.states = [
-      IntersectionDrawer.FIRST_OBJECT_STATE,
-      IntersectionDrawer.SECOND_OBJECT_STATE
-    ];
+    this.states = [IntersectionDrawer.FIRST_OBJECT_STATE, IntersectionDrawer.SECOND_OBJECT_STATE];
     this.intersections = [];
     this.pointDrawer = new PointDrawer();
     super.setElementClass(ELEMENTS_CLASS.INTERSECTION_POINT);
   }
+
   draw(e) {
     if (e != undefined && e.attrs != undefined) {
       this.aggregatorA = this.getObjectAggregatorByGenericObject(e.attrs.genericObject.r);
@@ -36,18 +46,15 @@ export class IntersectionDrawer extends Drawer {
     if (e == undefined || !this.isValidObject(e.target)) return;
 
     const selectedTool = App.getSelectedTool();
-    if (
-      selectedTool != undefined &&
+    if (selectedTool != undefined &&
       selectedTool.drawer != undefined &&
       selectedTool.drawer.elementClass == ELEMENTS_CLASS.INTERSECTION_POINT
     ) {
-      if (
-        this.state == undefined ||
-        this.state == IntersectionDrawer.FIRST_OBJECT_STATE
-      ) {
+      if (this.state == undefined || this.state == IntersectionDrawer.FIRST_OBJECT_STATE) {
         this.setFirstObject(e.target);
         this.setState(IntersectionDrawer.SECOND_OBJECT_STATE);
-      } else if (this.state == IntersectionDrawer.SECOND_OBJECT_STATE) {
+      }
+      else if (this.state == IntersectionDrawer.SECOND_OBJECT_STATE) {
         this.setSecondObject(e.target);
         this.drawPoint();
         this.reset();
@@ -55,50 +62,48 @@ export class IntersectionDrawer extends Drawer {
       }
     }
   }
+
   setFirstObject(konvaObject) {
     const aggregator = this.getObjectAggregator(konvaObject);
     this.aggregatorA = aggregator;
   }
+
   setSecondObject(konvaObject) {
     const aggregator = this.getObjectAggregator(konvaObject);
     this.aggregatorB = aggregator;
   }
+
   getObjectAggregator(konvaObject) {
     return objects.getByKonvaObject(konvaObject)[0];
   }
+
   getObjectAggregatorByGenericObject(genericObject) {
     return objects.getByGenericObject(genericObject)[0];
   }
+
   drawPoint() {
-    const intersectionPoints = intersectionService.addIntersections(this.aggregatorA.genericObject.getIntersection(
-      this.aggregatorB.genericObject
-    ));
+    const intersectionPoints = intersectionService.addIntersections(
+      this.aggregatorA.genericObject.getIntersection(this.aggregatorB.genericObject));
     this.drawByIntersectionPoints(intersectionPoints);
   }
+
   drawByIntersectionPoints(intersectionPoints) {
     for (let index = 0; index < intersectionPoints.length; index++) {
       const intersectionPoint = intersectionPoints[index];
       intersectionPoint.update();
       // if (!intersectionPoint.visible) return;
-      const point = PointDrawer.drawPoint(
-        intersectionPoint,
-        true,
-        false,
-        true
-      );
-      const aggregator = new DrawerAggregator(
-        this,
-        intersectionPoint,
-        point.konvaObject,
-        ELEMENTS_CLASS.INTERSECTION_POINT
-      );
+      const point = PointDrawer.drawPoint(intersectionPoint, true, false, true);
+      const aggregator = new DrawerAggregator(this, intersectionPoint, point.konvaObject, ELEMENTS_CLASS.INTERSECTION_POINT);
       super.addAggregator(aggregator);
       this.aggregatorB.addAggregator(aggregator);
       this.aggregatorA.addAggregator(aggregator);
     }
   }
+
   isValidObject(konvaObject) {
     switch (konvaObject.attrs.class) {
+      case ELEMENTS_CLASS.LINE:
+        return true;
       case ELEMENTS_CLASS.LINE_SEGMENT:
         return true;
       case ELEMENTS_CLASS.CIRCUMFERENCE:
@@ -107,8 +112,8 @@ export class IntersectionDrawer extends Drawer {
         return false;
     }
   }
-  update(aggregator, e) {
 
+  update(aggregator, e) {
     aggregator.genericObject.update(aggregator, e);
 
     if (!aggregator.genericObject.visible || aggregator.genericObject.posX == Number.MAX_SAFE_INTEGER) {
@@ -142,9 +147,11 @@ export class IntersectionDrawer extends Drawer {
     }
     this.batchDraw();
   }
+
   reset() {
     this.aggregatorA = undefined;
     this.aggregatorB = undefined;
     this.setState(undefined);
   }
-}
+
+}

+ 99 - 85
src/app/components/intersection-component/models/intersection-model.js

@@ -1,3 +1,12 @@
+/*
+ * iGeom by LInE
+ * Provides intersetion point to Geometric Objects (GO)
+ * www.matematica.br/igeom
+ * ./app/components/intersection-component/models/intersection-model.js
+ * @calledby ./app/components/<go>-component/models/<go>-model.js
+ * @version 2020/11/02: Implemented Line instersection; changed "this.r" and "this.s" to "this.og1" and "this.og2"
+ */
+
 import { PointModel } from "../../point-component/models/point-model";
 import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
 import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
@@ -5,107 +14,112 @@ import { GeometricObject } from "../../../core/models/objects/geometric-object";
 import { setWith } from "lodash";
 
 export class IntersectionModel extends PointModel {
-  /**
-   * 
-   * @param {GeometricObject} r Geometric Object 
-   * @param {GeometricObject} s Geometric Object
-   * @param {boolean} visible Visiblity of Object 
-   * @param {number} index Index position of Object ex (1)
-   * @param {id} id indentity of intersection ex: 0
-   */
-  constructor(posX, posY, label, r, s, visible, index, id) {
-    super(posX, posY, label, id);
-    this.r = r;
-    this.s = s;
-    super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
-    this.visible = visible;
-    this.index = index;
-    this.color = -65536;
-    this.definitions = this.getDefinitions();
+
+  // @param {GeometricObject} og1 Geometric Object 
+  // @param {GeometricObject} og2 Geometric Object
+  // @param {boolean} visible Visiblity of Object 
+  // @param {number} index Index position of Object ex (1)
+  // @param {id} id indentity of intersection ex: 0
+  constructor(posX, posY, label, og1, og2, visible, index, id) {
+    try { //D //leo
+      super(posX, posY, label, id);
+      this.og1 = og1;
+      this.og2 = og2;
+      super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
+      this.visible = visible;
+      this.index = index;
+      this.color = -65536;
+      this.definitions = this.getDefinitions();
+    } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: constructor(.): erro!\n" + e.stack); }
   }
 
-  /**
-   * Update properties of this Intersection
-   * @param {DrawerAggregator} aggregator Drawer Aggregator 
-   * @param {event} event 
-  */
+  // Update properties of this Intersection
+  // @param {DrawerAggregator} aggregator Drawer Aggregator 
+  // @param {event} event
   update(aggregator, event) {
-    const intersections = this.r.getIntersection(this.s);
-    if (intersections.length == 1) {
-      this.visible = true;
-      const intersection = intersections[0];
-      this.posX = parseFloat(intersection.posX.toFixed(2));
-      this.posY = parseFloat(intersection.posY.toFixed(2));
-      // this.visible = intersection.visible;
-      if (!this.r.insideSegment(this.posX, this.posY)) {
-        this.posX = Number.MAX_SAFE_INTEGER;
-        this.posY = Number.MAX_SAFE_INTEGER;
-        this.visible = false;
-        this.definitions = this.getDefinitions();
-        return;
-      }
-      if (!this.s.insideSegment(this.posX, this.posY)) {
-        this.posX = Number.MAX_SAFE_INTEGER;
-        this.posY = Number.MAX_SAFE_INTEGER;
-        this.visible = false;
-        this.definitions = this.getDefinitions();
+    try { //D //leo
+      const intersections = this.og1.getIntersection(this.og2);
+      if (intersections.length == 1) {
+        this.visible = true;
+        const intersection = intersections[0];
+        this.posX = parseFloat(intersection.posX.toFixed(2));
+        this.posY = parseFloat(intersection.posY.toFixed(2));
+        // this.visible = intersection.visible;
+        if (!this.og1.insideSegment(this.posX, this.posY)) {
+          this.posX = Number.MAX_SAFE_INTEGER;
+          this.posY = Number.MAX_SAFE_INTEGER;
+          this.visible = false;
+          this.definitions = this.getDefinitions();
+          return;
+        }
+        if (!this.og2.insideSegment(this.posX, this.posY)) {
+          this.posX = Number.MAX_SAFE_INTEGER;
+          this.posY = Number.MAX_SAFE_INTEGER;
+          this.visible = false;
+          this.definitions = this.getDefinitions();
+          return;
+        }
         return;
       }
-      return;
-    }
-    if (intersections.length > 1) {
-      for (let index = 0; index < intersections.length; index++) {
-        const intersection = intersections[index];
-        if (this.index == index) {
-          this.posX = parseFloat(intersection.posX.toFixed(2));
-          this.posY = parseFloat(intersection.posY.toFixed(2));
-          this.visible = intersection.visible;
+      if (intersections.length > 1) {
+        for (let index = 0; index < intersections.length; index++) {
+          const intersection = intersections[index];
+          if (this.index == index) {
+            this.posX = parseFloat(intersection.posX.toFixed(2));
+            this.posY = parseFloat(intersection.posY.toFixed(2));
+            this.visible = intersection.visible;
+          }
         }
       }
-    }
-    this.definitions = this.getDefinitions();
+      this.definitions = this.getDefinitions();
+    } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: update(aggregator, event): erro!"); }
   }
 
   getDefinitions() {
-    return [{ id: this.r.id }, { id: this.s.id }, { id: this.index + 1 }, { id: this.visible ? 1 : 0 }];
+    try { //D //leo
+      return [{ id: this.og1.id }, { id: this.og2.id }, { id: this.index + 1 }, { id: this.visible ? 1 : 0 }];
+    } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: getDefinitions(): erro!"); }
   }
 
-  bind(posX, posY, label, r, s, visible, index) {
-    super.bind(posX, posY, label);
-    this.r = r;
-    this.s = s;
-    this.visible = visible;
-    this.index = index;
-    this.color = -65536;
-    this.definitions = this.getDefinitions();
-    super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
+  bind(posX, posY, label, og1, og2, visible, index) {
+    try { //D //leo
+      super.bind(posX, posY, label);
+      this.og1 = og1;
+      this.og2 = og2;
+      this.visible = visible;
+      this.index = index;
+      this.color = -65536;
+      this.definitions = this.getDefinitions();
+      super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
+    } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: bind(.): erro!\n" + e.stack); }
   }
 
-  /**
-   * Create new Intersection By Line of Script .geo
-   * @param {Map} map JavaScript Map
-   * @param {[]} list List of Generic Objects
-   */
+  // Create new Intersection By Line of Script .geo
+  // @param {Map} map JavaScript Map
+  // @param {[]} list List of Generic Objects
   static do(map, list) {
-    const id = map.get("id");
-    const rId = map.get("param")[0];
-    const sId = map.get("param")[1];
-    const index = map.get("param")[2] - 1;
-    const visible = map.get("param")[5] == 1;
-    const label = map.get("label")[0];
-    const r = list.find(x => x.id == rId);
-    const s = list.find(x => x.id == sId);
+    try { //D //leo
+      const id = map.get("id");
+      const og1_Id = map.get("param")[0];
+      const og2_Id = map.get("param")[1];
+      const index = map.get("param")[2] - 1;
+      const visible = map.get("param")[5] == 1;
+      const label = map.get("label")[0];
+      const og1 = list.find(x => x.id == og1_Id);
+      const og2 = list.find(x => x.id == og2_Id);
 
-    const intersections = r.getIntersection(s);
-    if (intersections.length == 1) {
-      const i = intersections[0];
-      i.bind(i.posX, i.posY, label, r, s, true, index);
-      return i;
-    } else {
-      const i = intersections.find(x => x.index == index);
-      i.bind(i.posX, i.posY, label, r, s, true, index);
-      return i;
-    }
+      const intersections = og1.getIntersection(og2); // intersection providade by the first geometric object
+
+      if (intersections.length == 1) {
+        const i = intersections[0];
+        i.bind(i.posX, i.posY, label, og1, og2, true, index);
+        return i;
+      } else {
+        const i = intersections.find(x => x.index == index);
+        i.bind(i.posX, i.posY, label, og1, og2, true, index);
+        return i;
+      }
+    } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: do(.): erro!"); }
   }
 
 }

+ 31 - 18
src/app/components/intersection-component/services/intersection-service.js

@@ -1,23 +1,36 @@
+/*
+ * iGeom by LInE
+ * Provides service to construct intersetion point of Geometric Objects (GO)
+ * www.matematica.br/igeom
+ * ./app/components/intersection-component/services/intersection-service.js
+ * @calledby ./app/components/<go>-component/models/<go>-model.js
+ * @version 2020/11/02: Implemented Line instersection
+ */
+
+// Provides service to (any) intersections
 class IntersectionService {
-    constructor() {
-        this.intersectionsMap = new Map()
+
+  constructor () { // load under iGeom initialization
+    this.intersectionsMap = new Map()
     }
 
-    /**
-     * 
-     * @param {[]} intersections 
-     */
-    addIntersections(intersections) {
-        const key = intersections.map((intersection) => {
-            return `r_${intersection.r.id}_s_${intersection.s.id}`;
-        });
-        if (this.intersectionsMap.has(key)) {
-            this.intersectionsMap.get(key).forEach((x, i) => intersections[i] = x.id);
-            delete this.intersectionsMap.get(key);
-            this.intersectionsMap.delete(key);
-        }
-        this.intersectionsMap.set(key, intersections);
-        return intersections;
+  // @param {[]} intersections
+  // @calledby ./app/components/intersection-component/drawers/intersection-drawer.js
+  addIntersections (intersections) { try { //D //leo
+    //D console.log("intersection-service.js: addIntersections(" + intersections + ")");
+    const key = intersections.map((intersection) => {
+      return `og1_${intersection.og1.id}_og2_${intersection.og2.id}`;
+      });
+    if (this.intersectionsMap.has(key)) {
+      this.intersectionsMap.get(key).forEach((x, i) => intersections[i] = x.id);
+      delete this.intersectionsMap.get(key);
+      this.intersectionsMap.delete(key);
+      }
+    this.intersectionsMap.set(key, intersections);
+    return intersections;
+    } catch (e) { console.log("app/components/intersection-component/services/intersection-service.js: addIntersections(.): erro!\n" + e.stack); }
     }
-}
+
+  }
+
 export const intersectionService = new IntersectionService();

+ 7 - 4
src/app/components/line-component/drawers/line-drawer.js

@@ -2,6 +2,8 @@
  * iGeom by LInE
  * Geometric Object: Straight Line
  * www.matematica.br/igeom
+ * ./app/components/line-component/drawers/line-drawer.js
+ * Draw the Straight Line
  */
 
 import { stageManager } from "../../../core/application/stage-manager"; // to get Canvas size 'stageManager.getSize();'
@@ -16,6 +18,7 @@ import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
 import { LineSegmentModel } from "../../line-segment-component/models/line-segment-model";
 
 export class LineDrawer extends LineSegmentDrawer {
+
   constructor() {
     super();
     this.setElementClass(ELEMENTS_CLASS.LINE);
@@ -126,8 +129,8 @@ export class LineDrawer extends LineSegmentDrawer {
     const size = stageManager.getSize(); // From: ../../../core/application/stage-manager
     const W = size.w; // canvas width
     const H = size.h; // canvas height
-    let Ix, Iy, Ex, Ey; // Point I will be left-bottom one and E will be the top-right one
-    let Lg, Rg, Ug, Dg;
+    var Ix, Iy, Ex, Ey; // Point I will be left-bottom one and E will be the top-right one
+    var Lg, Rg, Ug, Dg;
     // Line perpendicular to axis "x" (dx = 0)
     if (dx === 0) {
       // Calculates parameters Ug, Dg:
@@ -149,7 +152,7 @@ export class LineDrawer extends LineSegmentDrawer {
       Ug = -Ay / dy;    // -A.y / d.y
       Dg = (H - Ay) / dy; // (H-A.y) / d.y
       // Find the situation (1), (2), (3) or (4) calculating "ming" the smallest "g" and "maxg" the greatest "g"
-      let ming, maxg; // calculate extreme points (intercepted with the Canvas frame)
+      var ming, maxg; // calculate extreme points (intercepted with the Canvas frame)
       if (dx > 0) { // (1)
         if (Lg < Dg) ming = Dg;
         else ming = Lg;
@@ -221,4 +224,4 @@ export class LineDrawer extends LineSegmentDrawer {
     return line;
   }
 
-}
+}

+ 120 - 4
src/app/components/line-component/models/line-model.js

@@ -1,11 +1,128 @@
+/*
+ * iGeom by LInE
+ * Geometric Object: Straight Line
+ * www.matematica.br/igeom
+ * ./app/components/line-component/models/line-model.js
+ * Model to Straight Line
+ */
 
 import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
 import { LineSegmentModel } from "../../line-segment-component/models/line-segment-model";
+import { IntersectionModel } from "../../intersection-component/models/intersection-model";
+
+const Erro = 0.00001; //TODO a definir...
+
 export class LineModel extends LineSegmentModel {
+
   constructor(pointA, pointB, label, id) {
     super(pointA, pointB, label, id);
     this.setClass(ELEMENTS_CLASS.LINE);
-    this.color = -16776961;
+  }
+
+  // Overload the Segment 'insideSegment' method (otherwise point intersection could be hiden)
+  insideSegment(intersecX, intersecY) { //TODO Sempre verificar se esta dentro, nao parece bom...
+    return true;
+  }
+
+  // Intersection with circunference
+  getIntersectionWithCircumference(circ) { // circ = circunference(C,radius)
+    // Delegate to super class Segment
+    return super.getIntersectionByCircumference(circ);
+  }
+
+  // Intersection between Straigh Lines (SL): with sl
+  // r := this=SL(A1,A2) e s := SL(B1,B2)
+  //                     \  /
+  //                       o P=(x,y)
+  //                      / \
+  //                     o   \   o O2 (orthogonal to B2-B1)
+  // O1 ort. to    o    / A2  oB1
+  // A2-A1        O1\  /       \
+  //                  o         oB2
+  //                 / A1        \
+  //            this=r            s
+  // d1:=(A2.x-A1.x, A2.y-A1.y) => o1:=(-d1.y, d1.x) : ortogonais as retas r e s
+  // d2:=(B2.x-B1.x, B2.y-B1.y) => o2:=(-d2.y, d2.x) :
+  // Find P=(x,y) such that (inner product)
+  //           O1' P = O1' A1 (1)
+  //           O2' P = O2' B1 (2)
+  // (1) => O1.x * x + O1.y * y = O1.x * A1.x + O1.y * A1.y => O2.y * (O1.x * x + O1.y * y) = O2.y * (O1.x * A1.x + O1.y * A1.y) (3)
+  // (2) => O2.x * x + O2.y * y = O2.x * B1.x + O2.y * B1.y => O1.y * (O2.x * x + O2.y * y) = O1.y * (O2.x * B1.x + O2.y * B1.y) (4)
+  //
+  // (3)-(4) = O2.y * O1.x * x - O1.y * O2.x * x = O2.y * (O1.x * A1.x + O1.y * A1.y) - O1.y * (O2.x * B1.x + O2.y * B1.y)
+  //         = x * (O2.y * O1.x - O1.y * O2.x) = O2.y * (O1.x * A1.x + O1.y * A1.y) - O1.y * (O2.x * B1.x + O2.y * B1.y)
+  //         => x = ( O2.y * (O1.x * A1.x + O1.y * A1.y) - O1.y * (O2.x * B1.x + O2.y * B1.y) ) / (O2.y * O1.x - O1.y * O2.x)
+  //
+  // If        O1.y<>0 => y = (O1.x * A1.x + O1.y * A1.y - O1.x * x) / O1.y
+  // 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) {
+    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
+
+      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!");
+        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
+        if (Math.abs(O2y) > Erro)
+          y = (O2x * B1x + O2y * B1y - O2x * x) / O2y;
+        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!");
+              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)];
+    } catch (e) { console.log("app/components/line-component/models/line-model.js: getIntersectionWithStraightLine(.): erro!\n" + e.stack); }
+  } // getIntersectionWithStraightLine(sl)
+
+
+  // Intersection between Straigh Line (SL) and Segment (S)
+  // P in S(C,D)  <=> P = a C+(1-a)D, a em [0,1] then | Px = Ax+b(Bx-Ax) = a*Cx + (1-a)Dx and Py = Ay+b(By-Ay) = a*Cy + (1-a)Dy and
+  // P in SL(A,B) <=> P = A + b(B-A)             ---> | b = (a*Cx + (1-a)Dx - Ax)/(Bx-Ax)
+  getIntersectionWithSegment(segm) {
+    //const pointA = segm.pointA;
+    //const pointB = segm.pointB;
+    return segm.getIntersectionByLine(this); //TODO nome em './app/components/line-segment-component/models/line-segment-model.js ! getIntersectionByLine(.)' deveria ser 'getIntersectionWithSegment'
+  }
+
+
+  // Starting point to intersection started with StraightLine
+  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,...
+        case ELEMENTS_CLASS.LINE:
+          return this.getIntersectionWithStraightLine(geometricObject); //TODO melhor 'with' que 'by'
+        case ELEMENTS_CLASS.LINE_SEGMENT:
+          return this.getIntersectionWithStraightLine(geometricObject); //TODO melhor 'with' que 'by'
+        case ELEMENTS_CLASS.CIRCUMFERENCE:
+          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); }
+
   }
 
   static do(map, list) {
@@ -15,8 +132,7 @@ export class LineModel extends LineSegmentModel {
     const pointA = list.find(x => x.id === pointAId);
     const pointB = list.find(x => x.id === pointBId);
     const label = map.get("label")[0];
-    const line = new LineModel(pointA, pointB, label, id);
-    return line;
+    return new LineModel(pointA, pointB, label, id);
   }
-}
 
+}

+ 43 - 49
src/app/components/line-segment-component/drawers/line-segment-drawer.js

@@ -1,3 +1,12 @@
+/*
+ * iGeom by LInE
+ * Geometric Object: Segment
+ * Drawer to Segment
+ * www.matematica.br/igeom
+ * ./app/components/line-segment-component/drawers/line-segment-drawer.js
+ * @version 2020/11/02: indentation
+ */
+
 import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
 import { label as Label } from "../../../component-registry/label";
 import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
@@ -6,13 +15,17 @@ import { LineSegmentModel } from "../models/line-segment-model";
 import { PointDrawer } from "../../point-component/drawers/point-drawer";
 import { objects as Objects } from "../../../core/application/objects";
 import { SelectableDrawer } from "../../../core/drawers/selectable-drawer";
+
 export class LineSegmentDrawer extends SelectableDrawer {
+
   static FIRST_POINT_STATE() {
     return "FIRST_POINT";
   }
+
   static SECOND_POINT_STATE() {
     return "SECOND_POINT";
   }
+
   constructor() {
     super();
     this.pointA;
@@ -20,14 +33,12 @@ export class LineSegmentDrawer extends SelectableDrawer {
     this.aggregatorA;
     this.aggregatorB;
     this.label;
-    this.states = [
-      LineSegmentDrawer.FIRST_POINT_STATE,
-      LineSegmentDrawer.SECOND_POINT_STATE
-    ];
+    this.states = [LineSegmentDrawer.FIRST_POINT_STATE, LineSegmentDrawer.SECOND_POINT_STATE];
     this.lineSegment;
     this.pointDrawer = new PointDrawer();
     super.setElementClass(ELEMENTS_CLASS.LINE_SEGMENT);
   }
+
   setPointA(point) {
     this.pointA = point;
   }
@@ -45,15 +56,12 @@ export class LineSegmentDrawer extends SelectableDrawer {
 
   draw(e) {
     if (e != undefined) {
-      if (
-        e.target != undefined &&
-        e.target.attrs.class != undefined &&
-        (e.target.attrs.class == ELEMENTS_CLASS.POINT ||
-          e.target.attrs.class == ELEMENTS_CLASS.INTERSECTION_POINT)
-      ) {
+      if (e.target != undefined && e.target.attrs.class != undefined &&
+        (e.target.attrs.class == ELEMENTS_CLASS.POINT || e.target.attrs.class == ELEMENTS_CLASS.INTERSECTION_POINT)) {
         this.drawByStates(e.target);
         return;
-      } else if (e.attrs != undefined && e.attrs.genericObject != undefined) {
+      }
+      else if (e.attrs != undefined && e.attrs.genericObject != undefined) {
         this.drawByLineSegment(e.attrs.genericObject)
         return;
       }
@@ -74,19 +82,16 @@ export class LineSegmentDrawer extends SelectableDrawer {
     }
     if (this.state == undefined) {
       super.setState(LineSegmentDrawer.FIRST_POINT_STATE);
-    } else if (this.state == LineSegmentDrawer.FIRST_POINT_STATE) {
-      aggregator =
-        aggregator != undefined ? aggregator : this.pointDrawer.drawPoint();
+    }
+    else if (this.state == LineSegmentDrawer.FIRST_POINT_STATE) {
+      aggregator = aggregator != undefined ? aggregator : this.pointDrawer.drawPoint();
       this.setAggregatorA(aggregator);
       super.setState(LineSegmentDrawer.SECOND_POINT_STATE);
-    } else if (this.state == LineSegmentDrawer.SECOND_POINT_STATE) {
-      aggregator =
-        aggregator != undefined ? aggregator : this.pointDrawer.drawPoint();
+    }
+    else if (this.state == LineSegmentDrawer.SECOND_POINT_STATE) {
+      aggregator = aggregator != undefined ? aggregator : this.pointDrawer.drawPoint();
       this.setAggregatorB(aggregator);
-      this.drawByPoints(
-        [this.pointA, this.pointB],
-        [this.aggregatorA, this.aggregatorB]
-      );
+      this.drawByPoints([this.pointA, this.pointB], [this.aggregatorA, this.aggregatorB]);
       super.setState(LineSegmentDrawer.FIRST_POINT_STATE);
     }
   }
@@ -97,11 +102,7 @@ export class LineSegmentDrawer extends SelectableDrawer {
     this.setPointB(points[1]);
     aggregators = this.resolveAggregators(points, aggregators, true);
     this.label = Label.draw(true);
-    this.lineSegment = new LineSegmentModel(
-      this.pointA,
-      this.pointB,
-      this.label
-    );
+    this.lineSegment = new LineSegmentModel(this.pointA, this.pointB, this.label);
     this.drawByLineSegment(this.lineSegment);
     this.reset();
   }
@@ -111,31 +112,29 @@ export class LineSegmentDrawer extends SelectableDrawer {
     const group = SelectableDrawer.getKonvaGroup(false);
     const text = LineSegmentDrawer.getKonvaText(lineSegment, lineSegment.label);
     group.add(text);
-    const konvaObject = LineSegmentDrawer.getKonvaLine(
-      lineSegment.pointA,
-      lineSegment.pointB
-    );
+    const konvaObject = LineSegmentDrawer.getKonvaLine(lineSegment.pointA, lineSegment.pointB);
     group.add(konvaObject);
     super.setKonvaObject(group);
     const aggregator = new DrawerAggregator(
-      this,
-      this.lineSegment,
-      group,
-      ELEMENTS_CLASS.LINE_SEGMENT
+      this, this.lineSegment,
+      group, ELEMENTS_CLASS.LINE_SEGMENT
     );
     super.addAggregator(aggregator);
     const aggregators = this.resolveAggregators([this.lineSegment.pointA, this.lineSegment.pointB], undefined);
     aggregators[1].addAggregator(aggregator);
     aggregators[0].addAggregator(aggregator);
-    SelectableDrawer.drawObject(this.konvaObject);
+
+    //D console.log("./app/components/line-segment-component/drawers/line-segment-drawer.js: drawByLineSegment"); //leo
+    SelectableDrawer.drawObject(this.konvaObject); //
+
     this.konvaObject.zIndex(1);
-    super.batchDraw();
+
+    super.batchDraw(); // ../../../core/drawers/drawer-aggregator.js
     SelectableDrawer.setMaxIndex(aggregators[0].konvaObject);
     SelectableDrawer.setMaxIndex(aggregators[1].konvaObject);
   }
 
   resolveAggregators(points, aggregators, selected) {
-
     this.pointA = points[0];
     this.pointB = points[1];
 
@@ -157,12 +156,9 @@ export class LineSegmentDrawer extends SelectableDrawer {
     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
+      pointA.posX, pointA.posY,
+      pointB.posX, pointB.posY
     ]);
     super.batchDraw();
   }
@@ -173,12 +169,9 @@ export class LineSegmentDrawer extends SelectableDrawer {
     const pointCAggregator = this.pointDrawer.drawPoint();
     const pointC = pointCAggregator.genericObject;
     aggregator.konvaObject.points([
-      pointA.posX,
-      pointA.posY,
-      pointB.posX,
-      pointB.posY,
-      pointC.posX,
-      pointC.posY
+      pointA.posX, pointA.posY,
+      pointB.posX, pointB.posY,
+      pointC.posX, pointC.posY
     ]);
     super.batchDraw();
   }
@@ -225,4 +218,5 @@ export class LineSegmentDrawer extends SelectableDrawer {
     const line = LineSegmentDrawer.getKonvaLine(pointA, pointB);
     return line;
   }
-}
+
+}

+ 170 - 157
src/app/components/line-segment-component/models/line-segment-model.js

@@ -1,187 +1,200 @@
+/*
+ * iGeom by LInE
+ * Geometric Object: Segment
+ * Manage intersection of Segment with: Sements, Circumference
+ * www.matematica.br/igeom
+ * .app/components/line-segment-component/models/line-segment-model.js
+ * @version 2020/11/02: Implemented Line instersection
+ */
+
 import { GeometricObject } from "../../../core/models/objects/geometric-object";
 import { IntersectionModel } from "../../intersection-component/models/intersection-model";
 import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
+
 export class LineSegmentModel extends GeometricObject {
-    constructor(pointA, pointB, label, id) {
-        super(id);
-        this.pointA = pointA;
-        this.pointB = pointB;
-        this.setLabel(label);
-        super.setClass(ELEMENTS_CLASS.LINE_SEGMENT);
-        this.definitions.push(this.pointA);
-        this.definitions.push(this.pointB);
-    }
-    getStraight() {
-        const aX = this.pointA.posX;
-        const aY = this.pointA.posY;
-        const bX = this.pointB.posX;
-        const bY = this.pointB.posY;
-        const a = bY - aY;
-        const b = aX - bX;
-        const c = a * aX + b * aY;
-        return [a, b, c];
-    }
-    getDirection() {
-        const aX = this.pointA.posX;
-        const aY = this.pointA.posY;
-        const bX = this.pointB.posX;
-        const bY = this.pointB.posY;
-        const a = bX - aX;
-        const b = bY - aY;
-        return [a, b];
-    }
-    getMiddlePoint() {
-        const x = (this.pointA.posX + this.pointB.posX) / 2;
-        const y = (this.pointA.posY + this.pointB.posY) / 2;
-        return { posX: x, posY: y };
-    }
-    getIntersection(geometricObject) {
-        switch (geometricObject.elementClass) {
-            case ELEMENTS_CLASS.LINE_SEGMENT:
-                return this.getIntersectionByLine(geometricObject);
-            case ELEMENTS_CLASS.CIRCUMFERENCE:
-                return this.getIntersectionByCircumference(geometricObject);
-            default:
-                break;
-        }
+
+  constructor(pointA, pointB, label, id) {
+    super(id);
+    this.pointA = pointA;
+    this.pointB = pointB;
+    this.setLabel(label);
+    super.setClass(ELEMENTS_CLASS.LINE_SEGMENT);
+    this.definitions.push(this.pointA);
+    this.definitions.push(this.pointB);
+  }
+
+  getStraight() {
+    const aX = this.pointA.posX;
+    const aY = this.pointA.posY;
+    const bX = this.pointB.posX;
+    const bY = this.pointB.posY;
+    const a = bY - aY;
+    const b = aX - bX;
+    const c = a * aX + b * aY;
+    return [a, b, c];
+  }
+
+  // Return [(Bx-Ax, By-Ay)]
+  getDirection() {
+    const aX = this.pointA.posX;
+    const aY = this.pointA.posY;
+    const bX = this.pointB.posX;
+    const bY = this.pointB.posY;
+    const a = bX - aX;
+    const b = bY - aY;
+    return [a, b];
+  }
+
+
+  getMiddlePoint() {
+    const x = (this.pointA.posX + this.pointB.posX) / 2;
+    const y = (this.pointA.posY + this.pointB.posY) / 2;
+    return { posX: x, posY: y };
+  }
+
+  getIntersection(geometricObject) {
+    switch (geometricObject.elementClass) {
+      case ELEMENTS_CLASS.LINE: // StraightLine
+        return geometricObject.getIntersectionWithStraightLine(this); // Delegate to StraightLine
+      case ELEMENTS_CLASS.LINE_SEGMENT:
+        return this.getIntersectionByLine(geometricObject); //TODO nome deveria especificar SEGMENTO: this.getIntersectionWithSegment
+      case ELEMENTS_CLASS.CIRCUMFERENCE:
+        return this.getIntersectionByCircumference(geometricObject);
+      default:
+        break;
     }
-    getDeterminantByLine(lineSegment) {
-        const r = this.getStraight();
-        const s = lineSegment.getStraight();
-        const a1 = r[0];
-        const b1 = r[1];
-        const a2 = s[0];
-        const b2 = s[1];
-        const determinant = a1 * b2 - a2 * b1;
-        return determinant;
+  }
+
+  getDeterminantByLine(lineSegment) {
+    const og1 = this.getStraight();
+    const og2 = lineSegment.getStraight();
+    const a1 = og1[0];
+    const b1 = og1[1];
+    const a2 = og2[0];
+    const b2 = og2[1];
+    const determinant = a1 * b2 - a2 * b1;
+    return determinant;
+  }
+
+  getIntersectionByLine(lineSegment) { //TODO nome deveria especificar SEGMENTO: getIntersectionWithSegment
+    const og1 = this.getStraight(); //r
+    const og2 = lineSegment.getStraight(); //s
+    const a1 = og1[0];
+    const b1 = og1[1];
+    const c1 = og1[2];
+    const a2 = og2[0];
+    const b2 = og2[1];
+    const c2 = og2[2];
+    const determinant = a1 * b2 - a2 * b1;
+    if (determinant == 0) {
+      return [new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, lineSegment, true, 0)];
     }
-    getIntersectionByLine(lineSegment) {
-        const r = this.getStraight();
-        const s = lineSegment.getStraight();
-        const a1 = r[0];
-        const b1 = r[1];
-        const c1 = r[2];
-        const a2 = s[0];
-        const b2 = s[1];
-        const c2 = s[2];
-        const determinant = a1 * b2 - a2 * b1;
-        if (determinant == 0) {
-            return [
-                new IntersectionModel(
-                    Number.MAX_SAFE_INTEGER,
-                    Number.MAX_SAFE_INTEGER,
-                    undefined,
-                    this,
-                    lineSegment,
-                    true,
-                    0
-                )
-            ];
-        } else {
-            const x = (b2 * c1 - b1 * c2) / determinant;
-            const y = (a1 * c2 - a2 * c1) / determinant;
-            return [new IntersectionModel(x, y, undefined, this, lineSegment, true, 0)];
-        }
+    else {
+      const x = (b2 * c1 - b1 * c2) / determinant;
+      const y = (a1 * c2 - a2 * c1) / determinant;
+      return [new IntersectionModel(x, y, undefined, this, lineSegment, true, 0)];
     }
+  }
 
-    getIntersectionByCircumference(circumference) {
-
-        const pointA = this.pointA;
-        const pointB = this.pointB;
-        const center = circumference.center;
-        const radius = circumference.getRadius();
+  // Intersection with circunference
+  getIntersectionByCircumference(circumference) { //TODO Nome? Melhor 'getIntersectionWithCircumference'
+    const pointA = this.pointA;
+    const pointB = this.pointB;
+    const center = circumference.center;
+    const radius = circumference.getRadius();
 
-        const dx = pointB.posX - pointA.posX;
-        const dy = pointB.posY - pointA.posY;
+    const dx = pointB.posX - pointA.posX;
+    const dy = pointB.posY - pointA.posY;
 
-        const cx = center.posX - pointA.posX;
-        const cy = center.posY - pointA.posY;
+    const cx = center.posX - pointA.posX;
+    const cy = center.posY - pointA.posY;
 
-        const a = dx * dx + dy * dy;
-        const b = dx * cx + dy * cy;
-        const c = cx * cx + cy * cy - radius * radius;
+    const a = dx * dx + dy * dy; // ||B-A||^2 = (B-A)'(B-A)
+    const b = dx * cx + dy * cy; // (B-A)'(C-A)
+    const c = cx * cx + cy * cy - radius * radius; // ||C-A||^2 - r^2
 
-        const D = b / a;
-        const q = c / a;
+    const D = b / a; // (B-A)'(C-A) / (B-A)'(B-A)
+    const q = c / a; // (||C-A||^2 - r^2) / (B-A)'(B-A)
 
-        const delta = D * D - q;
+    const delta = D * D - q;
 
-        const PA = new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 0);
-        const PB = new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 1);
+    const PA = new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 0);
+    const PB = new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 1);
 
-        if (delta < 0) {
-            return [
-                PA,
-                PB
-            ];
-        }
+    if (delta < 0) { //TODO Verificar? No intersection points
+      //D console.log("line-segment-model.js: getIntersectionByCircumference(.): delta<0: " + Number.MAX_SAFE_INTEGER);
+      return [PA, PB];
+    }
 
-        const deltaSqrt = Math.sqrt(delta);
-        const root1 = -D + deltaSqrt;
-        const root2 = -D - deltaSqrt;
-        const x1 = pointA.posX - dx * root1
-        const y1 = pointA.posY - dy * root1;
+    const deltaSqrt = Math.sqrt(delta);
+    const root1 = -D + deltaSqrt;
+    const root2 = -D - deltaSqrt;
+    const x1 = pointA.posX - dx * root1
+    const y1 = pointA.posY - dy * root1;
 
-        if (delta == 0) {
-            PA.bind(x1, y1, undefined, this, circumference, true, 0);
-            return [
-                PA,
-                PB
-            ];
-        }
+    if (delta == 0) { //TODO Verificar? Only one point (actually, both with the same coordinates)
+      //D console.log("line-segment-model.js: getIntersectionByCircumference(.): delta==0");
+      PA.bind(x1, y1, undefined, this, circumference, true, 0);
+      return [PA, PB];
+    }
 
-        const x2 = pointA.posX - dx * root2;
-        const y2 = pointA.posY - dy * root2;
+    if (delta == 0) {
+      PA.bind(x1, y1, undefined, this, circumference, true, 0);
+      return [
+        PA,
+        PB
+      ];
+    }
 
-        PA.bind(x1, y1, undefined, this, circumference, true, 0);
-        PB.bind(x2, y2, undefined, this, circumference, true, 1);
+    const x2 = pointA.posX - dx * root2;
+    const y2 = pointA.posY - dy * root2;
 
-        if (this.visible) {
-            if (!this.insideSegment(PA.posX, PA.posY))
-                PA.bind(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 0)
+    PA.bind(x1, y1, undefined, this, circumference, true, 0);
+    PB.bind(x2, y2, undefined, this, circumference, true, 1);
 
-            if (!this.insideSegment(PB.posX, PB.posY))
-                PB.bind(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 1);
-        }
-        return [
-            PA,
-            PB
-        ];
+    if (!this.insideSegment(PB.posX, PB.posY))
+      PB.bind(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 1);
 
-    }
+    return [PA, PB];
+  } // getIntersectionByCircumference(circumference)
 
-    insideSegment(intersecX, intersecY) {
-        const valuesR = this.getDirection();
-        const dirX = valuesR[0];
-        const dirY = valuesR[1];
-        const cInterA = dirX * intersecX + dirY * intersecY;
 
-        // comparaca cv do ponto A > cv da intersec =>  vazio
-        const cRA = dirX * this.pointA.posX + dirY * this.pointA.posY;
+  // Considering de "level set" defined by direction d=B-A and intersection P,
+  // if d'P<d'A or d'P>d'B, then intersection is empty
+  insideSegment(intersecX, intersecY) {
+    //D console.log("line-segment-model.js: insideSegment(.)");
+    const valuesR = this.getDirection(); // get d=B-A
+    const dirX = valuesR[0]; // Bx-Ax
+    const dirY = valuesR[1]; // By-Ay
+    const cInterA = dirX * intersecX + dirY * intersecY;
 
-        if (cInterA < cRA) {
-            return false;
-        }
+    // comparacao cv do ponto A > cv da intersec =>  vazio
+    const cRA = dirX * this.pointA.posX + dirY * this.pointA.posY;
 
-        // comparaca cv do ponto B < cv da intersec =>  vazio
-        const cRB = dirX * this.pointB.posX + dirY * this.pointB.posY;
+    if (cInterA < cRA) { // d'P < d'A
+      return false;
+    }
 
-        if (cInterA > cRB) {
-            this.posX = Number.MAX_SAFE_INTEGER;
-            this.posY = Number.MAX_SAFE_INTEGER;
-            return false;
-        }
+    // comparacao cv do ponto B < cv da intersec =>  vazio
+    const cRB = dirX * this.pointB.posX + dirY * this.pointB.posY;
 
-        return true;
-    }
-    static do(map, list) {
-        const id = map.get("id");
-        const pointAId = map.get("param")[0];
-        const pointBId = map.get("param")[1];
-        const pointA = list.find(x => x.id === pointAId);
-        const pointB = list.find(x => x.id === pointBId);
-        const label = map.get("label")[0];
-        return new LineSegmentModel(pointA, pointB, label, id);
+    if (cInterA > cRB) { // d'P > d'B
+      this.posX = Number.MAX_SAFE_INTEGER;
+      this.posY = Number.MAX_SAFE_INTEGER;
+      return false;
     }
-}
 
+    return true;
+  }
+
+  static do(map, list) {
+    const id = map.get("id");
+    const pointAId = map.get("param")[0];
+    const pointBId = map.get("param")[1];
+    const pointA = list.find(x => x.id === pointAId);
+    const pointB = list.find(x => x.id === pointBId);
+    const label = map.get("label")[0];
+    return new LineSegmentModel(pointA, pointB, label, id);
+  }
+
+}

+ 36 - 30
src/app/components/point-component/models/point-model.js

@@ -1,48 +1,54 @@
-import { GeometricObject } from "../../../core/models/objects/geometric-object";
-import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
+/*
+ * iGeom by LInE
+ * Geometric Object: Point
+ * Model to Point
+ * www.matematica.br/igeom
+ * ./app/components/point-component/models/point-model.js
+ * @version 2020/11/02: Implemented Line instersection
+ */
+
+import { GeometricObject   } from "../../../core/models/objects/geometric-object";
+import { ELEMENTS_CLASS   } from "../../../core/enums/elements-class-enum";
+
 export class PointModel extends GeometricObject {
-  /**
-   * 
-   * @param {number} posX X Position ex: (38.5) float precision
-   * @param {number} posY Y Position  ex: (-38.5) float precision
-   * @param {string} label  Label ex: (P)
-   */
-  constructor(posX, posY, label, id) {
+
+  // @param {number  } posX X Position ex: (38.5) float precision
+  // @param {number  } posY Y Position  ex: (-38.5) float precision
+  // @param {string  } label  Label ex: (P)
+  constructor (posX, posY, label, id) {
     super(id);
     this.posX = posX;
     this.posY = posY;
     this.setLabel(label);
     super.setClass(ELEMENTS_CLASS.POINT);
-    this.definitions = [{ id: this.posX + 5 }, { id: -this.posY - 5 }];
+    this.definitions = [{ id: this.posX + 5   }, { id: -this.posY - 5   }];
     this.color = -16711936;
-  }
+    }
 
-  /**
-   * 
-   * @param {konvaObject} Object of Konva Library
-   * @param {*} event 
-   */
-  update(konvaObject, event) {
+  // @param {konvaObject  } Object of Konva Library
+  // @param {*  } event 
+  update (konvaObject, event) {
     this.posX = konvaObject.attrs.startPosX + event.target._lastPos.x;
     this.posY = konvaObject.attrs.startPosY + event.target._lastPos.y;
-    this.definitions = [{ id: this.posX + 5 }, { id: -this.posY - 5 }];
-  }
-  bind(posX, posY, label) {
+    this.definitions = [{ id: this.posX + 5   }, { id: -this.posY - 5   }];
+    }
+
+  bind (posX, posY, label) {
     this.posX = posX;
     this.posY = posY;
     this.setLabel(label);
-    this.definitions = [{ id: this.posX + 5 }, { id: -this.posY - 5 }];
-  }
-  /**
- * Create new Intersection By Line of Script .geo
- * @param {Map} map JavaScript Map
- * @param {List} list List of Generic Objects
- */
-  static do(map, list) {
+    this.definitions = [{ id: this.posX + 5   }, { id: -this.posY - 5   }];
+    }
+
+  // Create new Intersection By Line of Script .geo
+  // @param {Map  } map JavaScript Map
+  // @param {List  } list List of Generic Objects
+  static do (map, list) {
     const id = map.get("id");
     const x = map.get("param")[0] - 5;
     const y = -map.get("param")[1] + 5;
     const label = map.get("label")[0];
     return new PointModel(x, y, label, id);
-  }
-}
+    }
+
+  }

+ 13 - 7
src/app/core/enums/elements-class-enum.js

@@ -1,3 +1,11 @@
+/*
+ * iGeom by LInE
+ * Definitions of ID to Geometric Objects
+ * www.matematica.br/igeom
+ * ./app/core/enums/elements-class-enum.js
+ * @version 2020/11/02: Implemented Line instersection
+ */
+
 export const ELEMENTS_CLASS = {
   NONE: -1,
   POINT: 0,
@@ -25,12 +33,9 @@ export const ELEMENTS_CLASS = {
   // TO: LOCUS                      =  17;
   // TO: MED_TEXTO                  =  20;  // para textos
   // TO: CIRCUNFERENCIA_INT         =  21; // [11/01/2006] estava 56, mas este num. e de rotacao
-};
+  };
 
-/**
- *
- * @param {number} code
- */
+// @param {number} code
 export function fromCodeToClass(code) {
   switch (code) {
     case 0:
@@ -46,5 +51,6 @@ export function fromCodeToClass(code) {
     default:
       console.error("Tipo não suportado" + "\"" + code + "\"", code)
       return ELEMENTS_CLASS.POINT;
-  }
-}
+    }
+
+  }