Forráskód Böngészése

Merge branch 'develop' of http://200.144.254.107/git/victordomingues/poc-igeom into develop

Victor Luiz Domingues 5 éve
szülő
commit
c26405147a

+ 26 - 4
src/app/components/circumference-component/drawers/circumference-drawer.js

@@ -78,11 +78,32 @@ export class CircumferenceDrawer extends SelectableDrawer {
     return aggregator;
   }
   drawcircumference(circumference) {
-    const circle = new Konva.Circle({
+    // const circle = new Konva.Circle({
+    //   x: circumference.center.posX,
+    //   y: circumference.center.posY,
+    //   radius: circumference.getRadius(),
+    //   fill: "transparent",
+    //   stroke: "grey",
+    //   strokeWidth: 2,
+    //   strokeScaleEnabled: false,
+    //   transformEnabled: false,
+    //   draggable: false,
+    //   selectable: false,
+    //   index: 0,
+    //   class: ELEMENTS_CLASS.CIRCUMFERENCE,
+    //   style: { stroke: "grey", fill: "grey" },
+    //   fillEnable: false,
+    //   strokeHitEnabled: true,
+    //   hitStrokeWidth: true,
+    //   strokeEnabled: true
+    // });
+    const circle = new Konva.Arc({
       x: circumference.center.posX,
       y: circumference.center.posY,
-      radius: circumference.getRadius(),
-      fill: "transparent",
+      innerRadius: circumference.getRadius(),
+      outerRadius: circumference.getRadius(),
+      angle: 360,
+      fill: "grey",
       stroke: "grey",
       strokeWidth: 2,
       strokeScaleEnabled: false,
@@ -100,7 +121,8 @@ export class CircumferenceDrawer extends SelectableDrawer {
   update(aggregator, e) {
     if (!aggregator.visible) return;
     const center = aggregator.genericObject.center;
-    aggregator.konvaObject.radius(aggregator.genericObject.getRadius());
+    aggregator.konvaObject.innerRadius(aggregator.genericObject.getRadius());
+    aggregator.konvaObject.outerRadius(aggregator.genericObject.getRadius());
     aggregator.konvaObject.x(center.posX);
     aggregator.konvaObject.y(center.posY);
     super.batchDraw();

+ 119 - 1
src/app/components/circumference-component/models/circumference-model.js

@@ -1,5 +1,10 @@
-export class CircumferenceModel {
+import { LineSegmentModel } from "../../line-segment-component/models/line-segment-model";
+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) {
+        super();
         this.center = center;
         this.radius = radius;
         this._coordinates = [];
@@ -7,6 +12,8 @@ export class CircumferenceModel {
         this._coordinates[1] = this.center.posY;
         this._coordinates[2] = this.radius.posX;
         this._coordinates[3] = this.radius.posY;
+        super.setClass(ELEMENTS_CLASS.CIRCUMFERENCE);
+
     }
     getRadius() {
         this._coordinates[0] = this.center.posX;
@@ -18,4 +25,115 @@ export class CircumferenceModel {
         const radius = Math.sqrt(Math.pow(legA, 2) + Math.pow(legB, 2));
         return radius;
     }
+
+    getStraight() {
+        const aX = this.center.posX;
+        const aY = this.center.posY;
+        const bX = this.radius.posX;
+        const bY = this.radius.posY;
+        const a = bY - aY;
+        const b = aX - bX;
+        const c = a * aX + b * aY;
+        return [a, b, c];
+    }
+
+    getDirection() {
+        const aX = this.center.posX;
+        const aY = this.center.posY;
+        const bX = this.radius.posX;
+        const bY = this.radius.posY;
+        const a = bX - aX;
+        const b = bY - aY;
+        return [a, b];
+    }
+    getIntersection(geometricObject) {
+        switch (geometricObject.elementClass) {
+            case ELEMENTS_CLASS.LINE_SEGMENT:
+                return this.getIntersectionByLine(geometricObject);
+            case ELEMENTS_CLASS.CIRCUMFERENCE:
+                return this.getIntersectionByCircumference(geometricObject);
+            default:
+                break;
+        }
+    }
+    getIntersectionByCircumference(circumference) {
+        const rM = new LineSegmentModel(this.center, this.radius);
+        const sM = new LineSegmentModel(circumference.center, circumference.radius);
+        const r = rM.getStraight();
+        const s = sM.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,
+                circumference
+            );
+        } else {
+            const x = (b2 * c1 - b1 * c2) / determinant;
+            const y = (a1 * c2 - a2 * c1) / determinant;
+            return new IntersectionModel(x, y, undefined, this, circumference);
+        }
+        return
+    }
+
+
+    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
+            );
+        } else {
+            const x = (b2 * c1 - b1 * c2) / determinant;
+            const y = (a1 * c2 - a2 * c1) / determinant;
+            return new IntersectionModel(x, y, undefined, this, lineSegment);
+        }
+    }
+
+
+    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.center.posX + dirY * this.center.posY;
+
+        if (cInterA < cRA) {
+            return false;
+        }
+
+        // comparaca cv do ponto B < cv da intersec =>  vazio
+        const cRB = dirX * this.radius.posX + dirY * this.radius.posY;
+
+        if (cInterA > cRB) {
+            this.posX = Number.MAX_SAFE_INTEGER;
+            this.posY = Number.MAX_SAFE_INTEGER;
+            return false;
+        }
+
+        return true;
+    }
+
 }

+ 8 - 1
src/app/components/intersection-component/drawers/intersection-drawer.js

@@ -78,7 +78,14 @@ export class IntersectionDrawer extends Drawer {
     this.aggregatorA.addAggregator(aggregator);
   }
   isValidObject(konvaObject) {
-    return konvaObject.attrs.class == ELEMENTS_CLASS.LINE_SEGMENT;
+    switch (konvaObject.attrs.class) {
+      case ELEMENTS_CLASS.LINE_SEGMENT:
+        return true;
+      case ELEMENTS_CLASS.CIRCUMFERENCE:
+        return true;
+      default:
+        return false;
+    }
   }
   update(aggregator, e) {
     aggregator.genericObject.update(aggregator, e);

+ 2 - 0
src/app/components/intersection-component/models/intersection-model.js

@@ -1,10 +1,12 @@
 import { PointModel } from "../../point-component/models/point-model";
+import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
 
 export class IntersectionModel extends PointModel {
   constructor(posX, posY, label, r, s) {
     super(posX, posY, label);
     this.r = r;
     this.s = s;
+    super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
   }
 
   update(aggregator, event) {

+ 39 - 1
src/app/components/line-segment-component/models/line-segment-model.js

@@ -1,11 +1,13 @@
 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) {
     super();
     this.pointA = pointA;
     this.pointB = pointB;
     this.setLabel(label);
+    super.setClass(ELEMENTS_CLASS.LINE_SEGMENT);
   }
   getStraight() {
     const aX = this.pointA.posX;
@@ -26,7 +28,18 @@ export class LineSegmentModel extends GeometricObject {
     const b = bY - aY;
     return [a, b];
   }
-  getIntersection(lineSegment) {
+  getIntersection(geometricObject) {
+    switch (geometricObject.elementClass) {
+      case ELEMENTS_CLASS.LINE_SEGMENT:
+        return this.getIntersectionByLine(geometricObject);
+      case ELEMENTS_CLASS.CIRCUMFERENCE:
+        return this.getIntersectionByCircumference(geometricObject);
+      default:
+        break;
+    }
+  }
+
+  getIntersectionByLine(lineSegment) {
     const r = this.getStraight();
     const s = lineSegment.getStraight();
     const a1 = r[0];
@@ -51,6 +64,31 @@ export class LineSegmentModel extends GeometricObject {
     }
   }
 
+  getIntersectionByCircumference(circumference) {
+    const r = this.getStraight();
+    const s = circumference.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,
+        circumference
+      );
+    } else {
+      const x = (b2 * c1 - b1 * c2) / determinant;
+      const y = (a1 * c2 - a2 * c1) / determinant;
+      return new IntersectionModel(x, y, undefined, this, circumference);
+    }
+  }
+
   insideSegment(intersecX, intersecY) {
     const valuesR = this.getDirection();
     const dirX = valuesR[0];

+ 2 - 3
src/app/components/point-component/drawers/point-drawer.js

@@ -53,7 +53,7 @@ export class PointDrawer extends SelectableDrawer {
   }
 
   update(aggregator, event) {
-    aggregator.konvaObject.children.forEach(function(element) {
+    aggregator.konvaObject.children.forEach(function (element) {
       if (element.attrs.class == ELEMENTS_CLASS.POINT) {
         aggregator.genericObject.update(element, event);
       }
@@ -131,8 +131,7 @@ export class PointDrawer extends SelectableDrawer {
       draggable: false,
       resizeEnabled: false,
       transformEnabled: false,
-      selectable: false,
-      fontStyle: "bold"
+      selectable: false
     });
   }
 }

+ 2 - 0
src/app/components/point-component/models/point-model.js

@@ -1,10 +1,12 @@
 import { GeometricObject } from "../../../core/models/objects/geometric-object";
+import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
 export class PointModel extends GeometricObject {
   constructor(posX, posY, label) {
     super();
     this.posX = posX;
     this.posY = posY;
     this.setLabel(label);
+    super.setClass(ELEMENTS_CLASS.POINT);
   }
   update(konvaObject, event) {
     this.posX = konvaObject.attrs.startPosX + event.target._lastPos.x;

+ 1 - 1
src/app/core/application/objects.js

@@ -1,7 +1,7 @@
 import { stageManager as StageManager } from "./stage-manager";
 
 class Objects {
-  constructor() {}
+  constructor() { }
   add(aggregator) {
     StageManager.getCurrentLayer().addAggregator(aggregator);
   }

+ 5 - 5
src/app/core/drawers/selectable-drawer.js

@@ -5,7 +5,7 @@ import { ELEMENTS_CLASS } from "../enums/elements-class-enum";
 import { app as App } from "../../app";
 const HOVER_STYLE = {
   fill: "#33BCFF",
-  strokeWidth: 4,
+  strokeWidth: 6,
   stroke: "#33BCFF"
 };
 const STYLE_STROKE = {
@@ -25,7 +25,7 @@ export class SelectableDrawer extends Drawer {
     super();
   }
   static setSelectableIfToolChanged(konvaObject) {
-    konvaObject.on("mouseover", function() {
+    konvaObject.on("mouseover", function () {
       const selectedTool = App.getSelectedTool();
       if (
         selectedTool != undefined &&
@@ -37,7 +37,7 @@ export class SelectableDrawer extends Drawer {
         StageManager.getCurrentKonvaStage().draw();
       }
     });
-    konvaObject.on("mouseout", function() {
+    konvaObject.on("mouseout", function () {
       if (konvaObject == undefined) return;
       this.strokeWidth(STYLE_STROKE.strokeWidth);
       this.stroke(konvaObject.attrs.style.stroke);
@@ -46,12 +46,12 @@ export class SelectableDrawer extends Drawer {
     return konvaObject;
   }
   static setSelectable(konvaObject) {
-    konvaObject.on("mouseover", function() {
+    konvaObject.on("mouseover", function () {
       this.strokeWidth(HOVER_STYLE.strokeWidth);
       this.stroke(HOVER_STYLE.stroke);
       StageManager.getCurrentKonvaStage().draw();
     });
-    konvaObject.on("mouseout", function() {
+    konvaObject.on("mouseout", function () {
       this.strokeWidth(STYLE_POINT.strokeWidth);
       this.stroke(konvaObject.attrs.style.stroke);
       StageManager.getCurrentKonvaStage().draw();

+ 4 - 0
src/app/core/models/objects/dynamic-object.js

@@ -5,6 +5,7 @@ export class DynamicObject extends GenericObject {
     super();
     this.label;
     this.dependencies = [];
+    this.elementClass;
   }
   setLabel(label) {
     if (label != undefined) {
@@ -14,4 +15,7 @@ export class DynamicObject extends GenericObject {
   addDependency(dynamicObject) {
     this.dependencies.push(dynamicObject);
   }
+  setClass(elementClass) {
+    this.elementClass = elementClass;
+  }
 }