intersection-model.js 974 B

12345678910111213141516171819202122232425262728293031
  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) {
  5. super(posX, posY, label);
  6. this.r = r;
  7. this.s = s;
  8. super.setClass(ELEMENTS_CLASS.INTERSECTION_POINT);
  9. }
  10. update(aggregator, event) {
  11. const intersection = this.r.getIntersection(this.s);
  12. this.posX = parseFloat(intersection.posX.toFixed(2));
  13. this.posY = parseFloat(intersection.posY.toFixed(2));
  14. if (!this.r.insideSegment(this.posX, this.posY)) {
  15. this.posX = Number.MAX_SAFE_INTEGER;
  16. this.posY = Number.MAX_SAFE_INTEGER;
  17. this.visible = false;
  18. return;
  19. }
  20. if (!this.s.insideSegment(this.posX, this.posY)) {
  21. this.posX = Number.MAX_SAFE_INTEGER;
  22. this.posY = Number.MAX_SAFE_INTEGER;
  23. this.visible = false;
  24. return;
  25. }
  26. this.visible = true;
  27. }
  28. }