|
@@ -1,57 +1,64 @@
|
|
|
|
+/*
|
|
|
|
+ * iGeom by LInE
|
|
|
|
+ * Provides intersetion point to Geometric Objects (GO)
|
|
|
|
+ * www.matematica.br/igeom
|
|
|
|
+ * ./app/components/intersection-component/models/intersection-model.js
|
|
|
|
+ * @calledby ./app/components/<go>-component/models/<go>-model.js
|
|
|
|
+ * @version 2020/11/02: Implemented Line instersection; changed "this.r" and "this.s" to "this.og1" and "this.og2"
|
|
|
|
+ */
|
|
|
|
+
|
|
import { PointModel } from "../../point-component/models/point-model";
|
|
import { PointModel } from "../../point-component/models/point-model";
|
|
import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
|
|
import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
|
|
import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
|
|
import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
|
|
import { GeometricObject } from "../../../core/models/objects/geometric-object";
|
|
import { GeometricObject } from "../../../core/models/objects/geometric-object";
|
|
|
|
+import { setWith } from "lodash";
|
|
|
|
|
|
export class IntersectionModel extends PointModel {
|
|
export class IntersectionModel extends PointModel {
|
|
- /**
|
|
|
|
- *
|
|
|
|
- * @param {GeometricObject} r Geometric Object
|
|
|
|
- * @param {GeometricObject} s Geometric Object
|
|
|
|
- * @param {boolean} visible Visiblity of Object
|
|
|
|
- * @param {number} index Index position of Object ex (1)
|
|
|
|
|
|
|
|
- */
|
|
|
|
- constructor(posX, posY, label, r, s, visible, index, id) {
|
|
|
|
|
|
+ // @param {GeometricObject} og1 Geometric Object
|
|
|
|
+ // @param {GeometricObject} og2 Geometric Object
|
|
|
|
+ // @param {boolean} visible Visiblity of Object
|
|
|
|
+ // @param {number} index Index position of Object ex (1)
|
|
|
|
+ // @param {id} id indentity of intersection ex: 0
|
|
|
|
+ constructor (posX, posY, label, og1, og2, visible, index, id) { try{ //D //leo
|
|
super(posX, posY, label, id);
|
|
super(posX, posY, label, id);
|
|
- this.r = r;
|
|
|
|
- this.s = s;
|
|
|
|
|
|
+ this.og1 = og1;
|
|
|
|
+ this.og2 = og2;
|
|
super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
|
|
super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
|
|
this.visible = visible;
|
|
this.visible = visible;
|
|
this.index = index;
|
|
this.index = index;
|
|
this.color = -65536;
|
|
this.color = -65536;
|
|
this.definitions = this.getDefinitions();
|
|
this.definitions = this.getDefinitions();
|
|
- }
|
|
|
|
|
|
+ } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: constructor(.): erro!\n" + e.stack); }
|
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
|
- * Update properties of this Intersection
|
|
|
|
- * @param {DrawerAggregator} aggregator Drawer Aggregator
|
|
|
|
- * @param {event} event
|
|
|
|
- */
|
|
|
|
- update(aggregator, event) {
|
|
|
|
- const intersections = this.r.getIntersection(this.s);
|
|
|
|
|
|
+ // Update properties of this Intersection
|
|
|
|
+ // @param {DrawerAggregator} aggregator Drawer Aggregator
|
|
|
|
+ // @param {event} event
|
|
|
|
+ update (aggregator, event) { try { //D //leo
|
|
|
|
+ const intersections = this.og1.getIntersection(this.og2);
|
|
if (intersections.length == 1) {
|
|
if (intersections.length == 1) {
|
|
this.visible = true;
|
|
this.visible = true;
|
|
const intersection = intersections[0];
|
|
const intersection = intersections[0];
|
|
this.posX = parseFloat(intersection.posX.toFixed(2));
|
|
this.posX = parseFloat(intersection.posX.toFixed(2));
|
|
this.posY = parseFloat(intersection.posY.toFixed(2));
|
|
this.posY = parseFloat(intersection.posY.toFixed(2));
|
|
// this.visible = intersection.visible;
|
|
// this.visible = intersection.visible;
|
|
- if (!this.r.insideSegment(this.posX, this.posY)) {
|
|
|
|
|
|
+ if (!this.og1.insideSegment(this.posX, this.posY)) {
|
|
this.posX = Number.MAX_SAFE_INTEGER;
|
|
this.posX = Number.MAX_SAFE_INTEGER;
|
|
this.posY = Number.MAX_SAFE_INTEGER;
|
|
this.posY = Number.MAX_SAFE_INTEGER;
|
|
this.visible = false;
|
|
this.visible = false;
|
|
this.definitions = this.getDefinitions();
|
|
this.definitions = this.getDefinitions();
|
|
return;
|
|
return;
|
|
- }
|
|
|
|
- if (!this.s.insideSegment(this.posX, this.posY)) {
|
|
|
|
|
|
+ }
|
|
|
|
+ if (!this.og2.insideSegment(this.posX, this.posY)) {
|
|
this.posX = Number.MAX_SAFE_INTEGER;
|
|
this.posX = Number.MAX_SAFE_INTEGER;
|
|
this.posY = Number.MAX_SAFE_INTEGER;
|
|
this.posY = Number.MAX_SAFE_INTEGER;
|
|
this.visible = false;
|
|
this.visible = false;
|
|
this.definitions = this.getDefinitions();
|
|
this.definitions = this.getDefinitions();
|
|
return;
|
|
return;
|
|
- }
|
|
|
|
|
|
+ }
|
|
return;
|
|
return;
|
|
- }
|
|
|
|
|
|
+ }
|
|
if (intersections.length > 1) {
|
|
if (intersections.length > 1) {
|
|
for (let index = 0; index < intersections.length; index++) {
|
|
for (let index = 0; index < intersections.length; index++) {
|
|
const intersection = intersections[index];
|
|
const intersection = intersections[index];
|
|
@@ -59,43 +66,55 @@ export class IntersectionModel extends PointModel {
|
|
this.posX = parseFloat(intersection.posX.toFixed(2));
|
|
this.posX = parseFloat(intersection.posX.toFixed(2));
|
|
this.posY = parseFloat(intersection.posY.toFixed(2));
|
|
this.posY = parseFloat(intersection.posY.toFixed(2));
|
|
this.visible = intersection.visible;
|
|
this.visible = intersection.visible;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
this.definitions = this.getDefinitions();
|
|
this.definitions = this.getDefinitions();
|
|
- }
|
|
|
|
|
|
+ } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: update(aggregator, event): erro!"); }
|
|
|
|
+ }
|
|
|
|
|
|
- getDefinitions() {
|
|
|
|
- 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 }];
|
|
|
|
- }
|
|
|
|
|
|
+ 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("app/components/intersection-component/models/intersection-model.js: getDefinitions(): erro!"); }
|
|
|
|
+ }
|
|
|
|
|
|
- bind(posX, posY, label, r, s, visible, index) {
|
|
|
|
|
|
+ bind (posX, posY, label, og1, og2, visible, index) { try{ //D //leo
|
|
super.bind(posX, posY, label);
|
|
super.bind(posX, posY, label);
|
|
- this.r = r;
|
|
|
|
- this.s = s;
|
|
|
|
|
|
+ this.og1 = og1;
|
|
|
|
+ this.og2 = og2;
|
|
this.visible = visible;
|
|
this.visible = visible;
|
|
this.index = index;
|
|
this.index = index;
|
|
this.color = -65536;
|
|
this.color = -65536;
|
|
this.definitions = this.getDefinitions();
|
|
this.definitions = this.getDefinitions();
|
|
super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
|
|
super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
|
|
- }
|
|
|
|
|
|
+ } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: bind(.): erro!\n" + e.stack); }
|
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
|
- * Create new Intersection By Line of Script .geo
|
|
|
|
- * @param {Map} map JavaScript Map
|
|
|
|
- * @param {[]} list List of Generic Objects
|
|
|
|
- */
|
|
|
|
- static do(map, list) {
|
|
|
|
|
|
+ // Create new Intersection By Line of Script .geo
|
|
|
|
+ // @param {Map} map JavaScript Map
|
|
|
|
+ // @param {[]} list List of Generic Objects
|
|
|
|
+ static do (map, list) { try{ //D //leo
|
|
const id = map.get("id");
|
|
const id = map.get("id");
|
|
- const rId = map.get("param")[0];
|
|
|
|
- const sId = map.get("param")[1];
|
|
|
|
|
|
+ const og1_Id = map.get("param")[0];
|
|
|
|
+ const og2_Id = map.get("param")[1];
|
|
const index = map.get("param")[2] - 1;
|
|
const index = map.get("param")[2] - 1;
|
|
- const x = (map.get("param")[3]) - 5;
|
|
|
|
- const y = (map.get("param")[4]) + 5;
|
|
|
|
const visible = map.get("param")[5] == 1;
|
|
const visible = map.get("param")[5] == 1;
|
|
- const label = map.get("label");
|
|
|
|
- const r = list.find(x => x.id == rId);
|
|
|
|
- const s = list.find(x => x.id == sId);
|
|
|
|
- return new IntersectionModel(x, y, label, r, s, visible, index, id);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ 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 intersections = og1.getIntersection(og2); // intersection providade by the first geometric object
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: do(.): erro!"); }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|