intersection-model.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { PointModel } from "../../point-component/models/point-model";
  2. import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
  3. export class IntersectionModel extends PointModel {
  4. constructor(posX, posY, label, r, s, visible, index, id) {
  5. super(posX, posY, label, id);
  6. this.r = r;
  7. this.s = s;
  8. super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
  9. this.visible = visible;
  10. this.index = index;
  11. this.color = -65536;
  12. this.definitions = [{ id: this.r.id }, { id: this.s.id }, { id: this.index + 1 }];
  13. }
  14. update(aggregator, event) {
  15. this.visible = true;
  16. const intersections = this.r.getIntersection(this.s);
  17. if (intersections.length == 1) {
  18. const intersection = intersections[0];
  19. this.posX = parseFloat(intersection.posX.toFixed(2));
  20. this.posY = parseFloat(intersection.posY.toFixed(2));
  21. if (!this.r.insideSegment(this.posX, this.posY)) {
  22. this.posX = Number.MAX_SAFE_INTEGER;
  23. this.posY = Number.MAX_SAFE_INTEGER;
  24. this.visible = false;
  25. return;
  26. }
  27. if (!this.s.insideSegment(this.posX, this.posY)) {
  28. this.posX = Number.MAX_SAFE_INTEGER;
  29. this.posY = Number.MAX_SAFE_INTEGER;
  30. this.visible = false;
  31. return;
  32. }
  33. return;
  34. }
  35. if (intersections.length > 1) {
  36. for (let index = 0; index < intersections.length; index++) {
  37. const intersection = intersections[index];
  38. if (this.index == intersection.index) {
  39. this.posX = parseFloat(intersection.posX.toFixed(2));
  40. this.posY = parseFloat(intersection.posY.toFixed(2));
  41. }
  42. continue;
  43. }
  44. }
  45. }
  46. }