123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- import { PointModel } from "../../point-component/models/point-model";
- import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
- import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
- import { GeometricObject } from "../../../core/models/objects/geometric-object";
- import { setWith } from "lodash";
- export class IntersectionModel extends PointModel {
-
-
-
-
-
- constructor(posX, posY, label, og1, og2, visible, index, id) {
- try {
- super(posX, posY, label, id);
- this.og1 = og1;
- this.og2 = og2;
- super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
- this.visible = visible;
- this.index = index;
- this.color = -65536;
- this.definitions = this.getDefinitions();
- } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: constructor(.): erro!\n" + e.stack); }
- }
-
-
-
- update(aggregator, event) {
- try {
- const intersections = this.og1.getIntersection(this.og2);
- if (intersections.length == 1) {
- this.visible = true;
- const intersection = intersections[0];
- this.posX = parseFloat(intersection.posX.toFixed(2));
- this.posY = parseFloat(intersection.posY.toFixed(2));
-
- if (!this.og1.insideSegment(this.posX, this.posY)) {
- this.posX = Number.MAX_SAFE_INTEGER;
- this.posY = Number.MAX_SAFE_INTEGER;
- this.visible = false;
- this.definitions = this.getDefinitions();
- return;
- }
- if (!this.og2.insideSegment(this.posX, this.posY)) {
- this.posX = Number.MAX_SAFE_INTEGER;
- this.posY = Number.MAX_SAFE_INTEGER;
- this.visible = false;
- this.definitions = this.getDefinitions();
- return;
- }
- return;
- }
- if (intersections.length > 1) {
- for (let index = 0; index < intersections.length; index++) {
- const intersection = intersections[index];
- if (this.index == index) {
- this.posX = parseFloat(intersection.posX.toFixed(2));
- this.posY = parseFloat(intersection.posY.toFixed(2));
- this.visible = intersection.visible;
- }
- }
- }
- this.definitions = this.getDefinitions();
- } catch (e) { console.log("app/components/intersection-component/models/intersection-model.js: update(aggregator, event): erro!"); }
- }
- getDefinitions() {
- try {
- 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, og1, og2, visible, index) {
- try {
- super.bind(posX, posY, label);
- this.og1 = og1;
- this.og2 = og2;
- this.visible = visible;
- this.index = index;
- this.color = -65536;
- 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); }
- }
-
-
-
- static do(map, list) {
- try {
- 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 intersections = og1.getIntersection(og2);
- 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!"); }
- }
- }
|