123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import { PointModel } from "../../point-component/models/point-model";
- import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
- export class IntersectionModel extends PointModel {
- constructor(posX, posY, label, r, s, visible, index, id) {
- super(posX, posY, label, id);
- this.r = r;
- this.s = s;
- super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
- this.visible = visible;
- this.index = index;
- this.color = -65536;
- this.definitions = [{ id: this.r.id }, { id: this.s.id }, { id: this.index + 1 }];
- }
- update(aggregator, event) {
- this.visible = true;
- const intersections = this.r.getIntersection(this.s);
- if (intersections.length == 1) {
- const intersection = intersections[0];
- this.posX = parseFloat(intersection.posX.toFixed(2));
- this.posY = parseFloat(intersection.posY.toFixed(2));
- if (!this.r.insideSegment(this.posX, this.posY)) {
- this.posX = Number.MAX_SAFE_INTEGER;
- this.posY = Number.MAX_SAFE_INTEGER;
- this.visible = false;
- return;
- }
- if (!this.s.insideSegment(this.posX, this.posY)) {
- this.posX = Number.MAX_SAFE_INTEGER;
- this.posY = Number.MAX_SAFE_INTEGER;
- this.visible = false;
- return;
- }
- return;
- }
- if (intersections.length > 1) {
- for (let index = 0; index < intersections.length; index++) {
- const intersection = intersections[index];
- if (this.index == intersection.index) {
- this.posX = parseFloat(intersection.posX.toFixed(2));
- this.posY = parseFloat(intersection.posY.toFixed(2));
- }
- continue;
- }
- }
- }
- }
|