Explorar el Código

fix intersection point

Victor Luiz Domingues hace 4 años
padre
commit
0d09e52fa8

+ 22 - 6
src/app/components/circumference-component/models/circumference-model.js

@@ -122,10 +122,13 @@ export class CircumferenceModel extends GeometricObject {
     const q = c / a;
 
     const delta = D * D - q;
+    const PA = new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, lineSegment, this, false, 0);
+    const PB = new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, lineSegment, this, false, 1);
+
     if (delta < 0) {
       return [
-        new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, lineSegment, false, 0),
-        new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, lineSegment, false, 1)
+        PA,
+        PB
       ];
     }
 
@@ -136,17 +139,30 @@ export class CircumferenceModel extends GeometricObject {
     const y1 = pointA.posY - dy * root1;
 
     if (delta == 0) {
+      PA.bind(x1, y1, undefined, lineSegment, this, true, 0);
       return [
-        new IntersectionModel(x1, y1, undefined, this, lineSegment, true, 0),
-        new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, lineSegment, false, 1)
+        PA,
+        PB
       ];
     }
+
     const x2 = pointA.posX - dx * root2;
     const y2 = pointA.posY - dy * root2;
 
+    PA.bind(x1, y1, undefined, lineSegment, this, true, 0);
+    PB.bind(x2, y2, undefined, lineSegment, this, true, 1);
+
+    if (this.visible) {
+      if (!this.insideSegment(PA.posX, PA.posY))
+        PA.bind(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, lineSegment, this, false, 0)
+
+      if (!this.insideSegment(PB.posX, PB.posY))
+        PB.bind(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, lineSegment, this, false, 1)
+    }
+
     return [
-      new IntersectionModel(x1, y1, undefined, this, lineSegment, true, 0),
-      new IntersectionModel(x2, y2, undefined, this, lineSegment, true, 1)
+      PA,
+      PB
     ];
 
   }

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

@@ -69,6 +69,18 @@ export class IntersectionModel extends PointModel {
     return [{ id: this.r.id }, { id: this.s.id }, { id: this.index + 1 }, { id: this.posX + 5 }, { id: this.posY - 5 }, { id: this.visible ? 1 : 0 }];
   }
 
+  bind(posX, posY, label, r, s, visible, index, id) {
+    super.bind(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();
+
+  }
+
   /**
    * Create new Intersection By Line of Script .geo
    * @param {Map} map JavaScript Map

+ 33 - 7
src/app/components/line-segment-component/models/line-segment-model.js

@@ -40,7 +40,16 @@ export class LineSegmentModel extends GeometricObject {
         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;
+  }
   getIntersectionByLine(lineSegment) {
     const r = this.getStraight();
     const s = lineSegment.getStraight();
@@ -89,10 +98,14 @@ export class LineSegmentModel extends GeometricObject {
     const q = c / a;
 
     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);
+
     if (delta < 0) {
       return [
-        new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 0),
-        new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 1)
+        PA,
+        PB
       ];
     }
 
@@ -103,17 +116,30 @@ export class LineSegmentModel extends GeometricObject {
     const y1 = pointA.posY - dy * root1;
 
     if (delta == 0) {
+      PA.bind(x1, y1, undefined, this, circumference, true, 0);
       return [
-        new IntersectionModel(x1, y1, undefined, this, circumference, true, 0),
-        new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 1)
+        PA,
+        PB
       ];
     }
+
     const x2 = pointA.posX - dx * root2;
     const y2 = pointA.posY - dy * root2;
 
+    PA.bind(x1, y1, undefined, this, circumference, true, 0);
+    PB.bind(x2, y2, undefined, this, circumference, true, 1);
+
+    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)
+
+      if (!this.insideSegment(PB.posX, PB.posY))
+        PB.bind(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 1)
+    }
+
     return [
-      new IntersectionModel(x1, y1, undefined, this, circumference, true, 0),
-      new IntersectionModel(x2, y2, undefined, this, circumference, true, 1)
+      PA,
+      PB
     ];
 
   }

+ 7 - 1
src/app/components/point-component/models/point-model.js

@@ -27,7 +27,13 @@ export class PointModel extends GeometricObject {
     this.posY = konvaObject.attrs.startPosY + event.target._lastPos.y;
     this.definitions = [{ id: this.posX + 5 }, { id: -this.posY - 5 }];
   }
-
+  bind(posX, posY, label, id) {
+    super.id = id;
+    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