Kaynağa Gözat

Update 'src/app/components/intersection-component/drawers/intersection-drawer.js'

Improved indentation: inserted space to differentiate function declaration from its use.
Introduced code to avoid redefinition of intersection point between line/segment with line/segment/circumference
E.g. let r:=line(A,B) and c0:=circ(C,A), then when defining D:=inter(r,c0) one intersection point is A (do not create a new one!)
+ alreadyHasIntersection (og1, og2, str_a1, str_a2): new function/method
+ drawPoint(): changed, now use 'alreadyHasIntersection(.)' to avoid the line/segment case only (circumference elsewhere)
leo 2 yıl önce
ebeveyn
işleme
d5f2cb98d1

+ 34 - 5
src/app/components/intersection-component/drawers/intersection-drawer.js

@@ -82,10 +82,11 @@ export class IntersectionDrawer extends Drawer {
   // Avoid to create intersection between lines/segments when some defining point is the intersection
   // Return true <=> need a new point
   alreadyHasIntersection (og1, og2, str_a1, str_a2) {
+    // app/core/enums/elements-class-enum.js : ELEMENTS_CLASS.LINE, ELEMENTS_CLASS.LINE_SEGMENT, ELEMENTS_CLASS.CIRCUMFERENCE
+    // Avoid duplicate intersection between line/segment with line/segment
     if ((og1.elementClass==ELEMENTS_CLASS.LINE || og1.elementClass==ELEMENTS_CLASS.LINE_SEGMENT) &&
         (og2.elementClass==ELEMENTS_CLASS.LINE || og2.elementClass==ELEMENTS_CLASS.LINE_SEGMENT)) {
       // Try to avoid redundant point
-      //D var aux = " ELEMENTS_CLASS.LINE=" + ELEMENTS_CLASS.LINE + ", ";
       if (og1.pointA==og2.pointA || og1.pointA==og2.pointB || og1.pointB==og2.pointA || og1.pointB==og2.pointB) {
         var aux2 = " "+og1.pointA+","+og1.pointB+";"+og2.pointA+","+og2.pointB+" ";
         console.log("intersection-drawer.js!alreadyHasIntersection(): existing intersection, nothing to be done: " + str_a1 + " , " + str_a2 + ", " + aux2);
@@ -93,6 +94,22 @@ export class IntersectionDrawer extends Drawer {
         return true;
         }
       }
+    // Avoid duplicate intersection between line/segment with circumference
+    var ogLine = null, ogCirc = null;
+    if (og1.elementClass==ELEMENTS_CLASS.LINE || og1.elementClass==ELEMENTS_CLASS.LINE_SEGMENT) ogLine = og1;
+    else if (og1.elementClass==ELEMENTS_CLASS.CIRCUMFERENCE || og1.elementClass==ELEMENTS_CLASS.CIRCUMFERENCE) ogCirc = og1;
+    if (og2.elementClass==ELEMENTS_CLASS.LINE || og2.elementClass==ELEMENTS_CLASS.LINE_SEGMENT) ogLine = og2;
+    else if (og2.elementClass==ELEMENTS_CLASS.CIRCUMFERENCE || og2.elementClass==ELEMENTS_CLASS.CIRCUMFERENCE) ogCirc = og2;
+    if (ogLine!=null && ogCirc!=null) { // is Line/Segment and Circumference
+      // Try to avoid redundant point
+      if (ogLine.pointA==ogCirc.radius || ogLine.pointB==ogCirc.radius) {
+        var aux2 = " Line/Segment with (A,B)=("+ogLine.pointA + "," + ogLine.pointB + "); Circ.=" + ogCirc.radius + " ";
+        console.log("intersection-drawer.js!alreadyHasIntersection(): existing intersection, nothing to be done: " + str_a1 + " , " + str_a2 + ", " + aux2);
+        //TODO need to become visible? "ogLine.visible = true;" or "ogCirc.visible = true;"
+        return false; // let "app/components/line-segment-component/models/line-segment-model.js!getIntersectionWithCircumference(.)" treat this case!
+        // return true;
+        }
+      }
     return false;
     }
 
@@ -103,16 +120,28 @@ export class IntersectionDrawer extends Drawer {
     const og1 = this.aggregatorA.genericObject, og2 = this.aggregatorB.genericObject;
     const str_a1 = "og1=(" + og1.elementClass + ",id=" + og1.id + ")"; //D genericObject
     const str_a2 = "og2=(" + og2.elementClass + ",id=" + og2.id + ")"; //D
-    if (this.alreadyHasIntersection(og1,og2,str_a1,str_a2)) return;
-    console.log("intersection-drawer.js!drawPoint(): create intersection between " + str_a1 + " , " + str_a2);
-    const intersectionOg1Og2 = og1.getIntersection(og2);
-    const intersectionPoints = intersectionService.addIntersections(intersectionOg1Og2);
+    if (this.alreadyHasIntersection(og1,og2,str_a1,str_a2))
+      return; // intersection already defined by line/segment.pointA or pointB
+    console.log("intersection-drawer.js!drawPoint(): create intersection between " + str_a1 + " , " + str_a2); //D //leo
+
+    // Really create the intersection: line-segment-model.js!getIntersectionByLine(.); getIntersectionWithCircumference(.)
+    // app/components/: line-component/models/line-model.js; line-segment-component/models/line-segment-model.js; circumference-component/models/circumference-model.js
+    const intersectionOg1Og2 = og1.getIntersection(og2); // get [ṔA, PB], but perhaps PA or PB is Point, NOT IntersectionPoint!
+
+    // app/components/intersection-component/services/intersection-service.js
+    const intersectionPoints = intersectionService.addIntersections(intersectionOg1Og2, og1, og2);
+
     this.drawByIntersectionPoints(intersectionPoints);
     }
 
   drawByIntersectionPoints (intersectionPoints) {
     for (let index = 0; index < intersectionPoints.length; index++) {
       const intersectionPoint = intersectionPoints[index];
+      if (intersectionPoint.og1 == undefined) {
+        //D console.log("intersection-drawer.js!drawByIntersectionPoints(.): " + index + ": intersectionPoint.id=" + intersectionPoint.id + " og1 undefined");
+        continue; // this point already exists!
+	}
+      //D else console.log("intersection-drawer.js!drawByIntersectionPoints(.): " + index + ": intersectionPoint.id=" + intersectionPoint.id + "");
       intersectionPoint.update();
       // if (!intersectionPoint.visible) return;
       const point = PointDrawer.drawPoint(intersectionPoint, true, false, true);