123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
- import { LineSegmentModel } from "../../line-segment-component/models/line-segment-model";
- import { IntersectionModel } from "../../intersection-component/models/intersection-model";
- const Erro = 0.00001;
- export class LineModel extends LineSegmentModel {
- constructor(pointA, pointB, label, id) {
- super(pointA, pointB, undefined, label, id);
- this.setClass(ELEMENTS_CLASS.LINE);
- }
-
- insideSegment(intersecX, intersecY) {
- return true;
- }
-
- getIntersectionWithCircumference(circ) {
-
- return super.getIntersectionWithCircumference(circ);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- getIntersectionWithStraightLine(sl) {
- try {
- const A1 = this.pointA, A2 = this.pointB;
- const A3 = sl.pointA, A4 = sl.pointB;
- var A1x = A1.posX, A1y = A1.posY,
- A2x = A2.posX, A2y = A2.posY;
- var B1x = A3.posX, B1y = A3.posY,
- B2x = A4.posX, B2y = A4.posY;
- var d1x = A2x - A1x, d1y = A2y - A1y,
- d2x = B2x - B1x, d2y = B2y - B1y,
- O1x = -d1y, O1y = d1x,
- O2x = -d2y, O2y = d2x,
- x, y;
- if (O2y * O1x - O1y * O2x == 0) {
- console.log("/app/components/line-component/models/line-model.js: erro: divisao por zero!");
- return null;
- }
- x = (O2y * (O1x * A1x + O1y * A1y) - O1y * (O2x * B1x + O2y * B1y)) / (O2y * O1x - O1y * O2x);
- if (Math.abs(O1y) > Erro)
- y = (O1x * A1x + O1y * A1y - O1x * x) / O1y;
- else
- if (Math.abs(O2y) > Erro)
- y = (O2x * B1x + O2y * B1y - O2x * x) / O2y;
- else
- if (O1y != 0.0)
- y = (O1x * A1x + O1y * A1y - O1x * x) / O1y;
- else
- if (O2y != 0.0)
- y = (O2x * B1x + O2y * B1y - O2x * x) / O2y;
- else {
- console.log("/app/components/line-component/models/line-model.js: erro: O2y=0!");
- return null;
- }
-
-
- return [new IntersectionModel(x, y, undefined, this, sl, true, 0)];
- } catch (e) { console.log("app/components/line-component/models/line-model.js: getIntersectionWithStraightLine(.): erro!\n" + e.stack); }
- }
-
-
-
- getIntersectionWithSegment(segm) {
-
-
- return segm.getIntersectionByLine(this);
- }
-
- getIntersection(geometricObject) {
- try {
-
- switch (geometricObject.elementClass) {
- case ELEMENTS_CLASS.LINE:
- return this.getIntersectionWithStraightLine(geometricObject);
- case ELEMENTS_CLASS.LINE_SEGMENT:
- return this.getIntersectionWithStraightLine(geometricObject);
- case ELEMENTS_CLASS.CIRCUMFERENCE:
- return this.getIntersectionWithCircumference(geometricObject);
- default: break;
- }
- } catch (e) { console.log("app/components/line-component/models/line-model.js: getIntersection(.): erro!\n" + e.stack); }
- }
- static do(map, list) {
- const id = map.get("id");
- const pointAId = map.get("param")[0];
- const pointBId = map.get("param")[1];
- const pointA = list.find(x => x.id === pointAId);
- const pointB = list.find(x => x.id === pointBId);
- const label = map.get("label")[0];
- return new LineModel(pointA, pointB, label, id);
- }
- }
|