Просмотр исходного кода

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

To read GEO with intersection point
New search method "static findOD_LS (vecIdObj, id)"
static do (map, list): change "pointA = list.find(x => x.id === pointAId)" and "pointB = list.find(x => x.id === pointBId)" by
index_pointA = LineSegmentModel.findOD_LS(vecIdObj, pointAId);
index_pointB = LineSegmentModel.findOD_LS(vecIdObj, pointBId);
pointA = list[index_pointA];
pointB = list[index_pointB];
leo 2 лет назад
Родитель
Сommit
39a1c14331

+ 19 - 3
src/app/components/line-segment-component/models/line-segment-model.js

@@ -196,13 +196,29 @@ export class LineSegmentModel extends GeometricObject {
     return true;
     }
 
-  static do (map, list) {
+
+  // Help: search object in more stable structure
+  static findOD_LS (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!
+    }
+
+  // In reading GEO file, need to transform a Map in GeometricObject
+  // @see app/core/parser/file-parser.js
+  // @see app/core/parser/parser-orchestrator.js
+  static do (map, vecIdObj, list) {
     const id = map.get("id");
     const pointAId = map.get("param")[0];
     const pointBId = map.get("param")[1];
+    // const pointA = list.find(x => x.id === pointAId);
+    // const pointB = list.find(x => x.id === pointBId);
+    const index_pointA = LineSegmentModel.findOD_LS(vecIdObj, pointAId); // get the index of vecIdObj[ii].id == pointAId
+    const index_pointB = LineSegmentModel.findOD_LS(vecIdObj, pointBId); // get the index of vecIdObj[ii].id == pointBId
+    const pointA = list[index_pointA]; // pointA = vecIdObj[index_pointA].obj; aux4 += "5,";
+    const pointB = list[index_pointB]; // pointB = vecIdObj[index_pointB].obj; aux4 += "6,";
 
-    const pointA = list.find(x => x.id === pointAId);
-    const pointB = list.find(x => x.id === pointBId);
     const label = map.get("label")[0];
     return new LineSegmentModel(pointA, pointB, label, id);
     }