浏览代码

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

To read GEO with intersection point
Changed "static do (map, list)" to "static do (id, map, vecIdObj, list)" with several changes,
including 2 "list.find(.)" to "GeometricObject.findOD(.)"
leo 2 年之前
父节点
当前提交
c7d8a78503
共有 1 个文件被更改,包括 48 次插入27 次删除
  1. 48 27
      src/app/components/intersection-component/models/intersection-model.js

+ 48 - 27
src/app/components/intersection-component/models/intersection-model.js

@@ -31,8 +31,9 @@ export class IntersectionModel extends PointModel {
       this.color = -65536; // rgba(255,0,0,1)
       this.definitions = this.getDefinitions();
       this.backgroundColor = "#aa0000"; // setBackgroundColor(color)
-      console.log("intersection-model.js: og1=" + og1.label +", og2=" + og2.label + ", this.color=" + this.color); // console.trace(); //leo //D
-    } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: constructor(.): erro!\n" + e.stack); }
+      console.log("intersection-model.js!constructor: id=" + id + ",  this.id=" + this.id + ", og1=" + og1.label +", og2=" + og2.label + ", this.color=" + this.color); //
+      //D if (this.id==3) console.trace(); //leo //D
+    } catch (e) { console.log("intersection-model.js!constructor(.): erro!\n" + e.stack); }
     }
 
   // Update properties of this Intersection
@@ -74,14 +75,18 @@ export class IntersectionModel extends PointModel {
           }
         }
       this.definitions = this.getDefinitions();
-    } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: update(aggregator, event): erro!"); }
-    }
+    } catch (e) { console.log("intersection-model.js!update(aggregator, event): erro!"); }
+    } // update(aggregator, event)
 
   // To be used in GEO file DEFINITION, see app/core/models/application/actions/action.js
   getDefinitions () {
-    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("intersection-model.js: getDefinitions(): erro!"); }
+    try {
+      // DEFINITION=2 to IntersectionPoint must be 3 values, the ID of the first and second GeometricObject (GO), e.g.
+      //  A:=Point(x1,y1); B:=Point(x2,y2); C:=Point(x3,y3); c:=Circumference(A,B); r:=Line(A,C); I1:=IntersectionPoint(c,r,1); I2:=IntersectionPoint(c,r,2);
+      // so, I1 is the "north" intesection, while I2 is "south"
+      // return [{ id: this.og1.id }, { id: this.og2.id }, { id: this.index + 1 }, { id: this.visible ? 1 : 0 }];
+      return [{ id: this.og1.id }, { id: this.og2.id }, { id: this.index + 1 } ];
+    } catch (e) { console.log("intersection-model.js!getDefinitions(): erro!"); }
     }
 
   bind (posX, posY, label, og1, og2, visible, index) {
@@ -94,35 +99,51 @@ export class IntersectionModel extends PointModel {
       this.color = -65536; // rgba(255,0,0,1)
       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); }
+    } catch (e) { console.log("intersection-model.js!bind(.): erro!\n" + e.stack); }
     }
 
+
   // Create new Intersection of lines (by script ".geo")
   // @param {Map} map JavaScript Map
   // @param {[]} list List of Generic Objects
-  static do (map, list) {
+  static do (id, map, vecIdObj, list) {
+    var aux = "", index_og1, index_og2;
+    console.log("intersection-model.js!do(.): enter, id=" + id);
     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 id = map.get("id");
+      const og1_Id = map.get("param")[0];              aux += "og1_Id=" + og1_Id;
+      const og2_Id = map.get("param")[1];              aux += ", og2_Id=" + og2_Id;
+      const index = map.get("param")[2] - 1;           aux += ", index=" + index;
+      // const visible = map.get("param")[5] == 1; // this parameter must not be used in DEFINITION=2, must be ""2:5 3 1" not "2:5 3 1 1"
+      const label = map.get("label")[0];               aux += ", label=" + label;
+      //const og1 = list.find(x => x.id == og1_Id);
+      //const og2 = list.find(x => x.id == og2_Id);
+      index_og1 = GeometricObject.findOD(vecIdObj, og1_Id); aux += ", index_og1=" + index_og1; // get the index of vecIdObj[ii].id == og1_Id
+      index_og2 = GeometricObject.findOD(vecIdObj, og2_Id); aux += ", index_og2=" + index_og2; // get the index of vecIdObj[ii].id == og2_Id
+      const og1 = list[index_og1];                     aux += ", og1.id=" + (og1&&og1.id?og1.id:"<>"); // og1 Point
+      const og2 = list[index_og2];                     aux += ", og2.id=" + (og2&&og2.id?og2.id:"<>"); // Point defining circumference og2
 
-      const intersections = og1.getIntersection(og2); // intersection providaded by the first geometric object
+      const intersections = og1.getIntersection(og2); // intersection provided by the first geometric object
+      aux += ", #intersections=" + (intersections && intersections.length ? intersections.length : "<>");
 
       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;
+        const inters_p = intersections[0];
+        inters_p.bind(inters_p.posX, inters_p.posY, label, og1, og2, true, index);
+console.log("intersection-model.js!do(.): 1, id=" + id + ", inters_p=" + inters_p + "; " + aux);
+        return inters_p;
+      } else { // if has 2 intersections, get only "north"=1 or "south"=2
+        const inters_p = intersections.find(x => x.index == index);
+        inters_p.bind(inters_p.posX, inters_p.posY, label, og1, og2, true, index);
+inters_p.id = id;
+console.log("intersection-model.js!do(.): 2, id=" + id + ", inters_p.id=" + inters_p.id + ", index=" + index + "; " + aux);
+        return inters_p;
        }
-    } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: do(.): erro!"); }
-    }
+    } catch (e) {
+      var aux2 = "";
+      if (index_og1) aux2 += ", list[" + index_og1 + "]=" + (list && list.length>0  ? JSON.stringify(list[index_og1]) : "<>");
+      if (index_og2) aux2 += ", list[" + index_og2 + "]=" + (list && list.length>0  ? JSON.stringify(list[index_og2]) : "<>");
+      console.log("intersection-model.js: do(.): erro!" + "\n* " + aux + aux2);
+      }
+    } // static do(map, vecIdObj, list)
 
   } // export class IntersectionModel extends PointModel