Browse Source

Update 'src/app/core/models/objects/geometric-object.js'

To read GEO with intersection point
Several indentation changes
New debug help method "static printMap_go(map, version)"
New search method "static findOD (vecIdObj, id)", to be used in "static do(.)" methods in extended classes.
leo 2 years ago
parent
commit
adc302d70f
1 changed files with 46 additions and 21 deletions
  1. 46 21
      src/app/core/models/objects/geometric-object.js

+ 46 - 21
src/app/core/models/objects/geometric-object.js

@@ -1,32 +1,57 @@
 import { DynamicObject } from "./dynamic-object";
 
 export class GeometricObject extends DynamicObject {
-  /**
-   * @param {number} id Id of object
-   */
-  constructor(id) {
+
+  //DEBUG: get String from map to check associated geometric object
+  static printMap_go (map, version) {
+    var str = ""; // if I use "let [key, value] of map" => TypeError: Invalid attempt to destructure non-iterable instance.
+    //for (let {key, value} of map) { str += "[" + key + "=" + value + "] "; }
+    let entries = Object.entries(map);
+    if (version == "map") for (let [index, [key, value]] of entries.entries()) { str += "[" + key + "=" + value + "] "; }
+    if (version == "list") for (let {key, value} of entries.entries()) { str += "[" + key + "=" + value + "] "; }
+    return str;
+    }
+    // let index = 0; // https://stackoverflow.com/questions/45251605/iterate-over-javascript-object-with-index
+    // for (let value of object) {
+    //  //do something with rest
+    //  if (index >= 1) { } // do something with the third and following items
+    //  index++; }
+
+  // @param {number} id Id of object
+  constructor (id) {
     super(id);
     this.borderColor;
     this.backgroundColor;
     this.edgeThinckness;
     this.draggable = true;
-  }
-  setBorderColor(color) {
+    }
+
+  setBorderColor (color) {
     this.borderColor = color;
-  }
-  setBackgroundColor(color) {
+    }
+
+  setBackgroundColor (color) {
     this.backgroundColor = color;
-  }
-  setEdgeThinckness(edgeThinckness) {
+    }
+
+  setEdgeThinckness (edgeThinckness) {
     this.edgeThinckness = edgeThinckness;
-  }
-
-  /**
- * Update properties of this Intersection
- * @param {DrawerAggregator} aggregator Drawer Aggregator 
- * @param {event} event 
- */
-  update(konvaObject, event) {
-    throw "not implemented exception";
-  }
-}
+    }
+
+
+  // Help each geometric object in GEO construction: search object in more stable structure
+  static findOD (vecIdObj, id) {
+    var tam = vecIdObj.length, ii;
+    for (ii=0; ii<tam; ii++)
+      if (vecIdObj[ii].id === id) return ii;
+    return -1; // Error! Not found!
+    }
+
+  // Update properties of this Intersection
+  // @param {DrawerAggregator} aggregator Drawer Aggregator 
+  // @param {event} event 
+   update (konvaObject, event) {
+     throw "not implemented exception";
+     }
+
+  }