|
@@ -13,7 +13,7 @@ import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
|
|
|
|
|
|
export class LineSegmentModel extends GeometricObject {
|
|
export class LineSegmentModel extends GeometricObject {
|
|
|
|
|
|
- constructor (pointA, pointB, label, id) {
|
|
+ constructor(pointA, pointB, label, id) {
|
|
super(id);
|
|
super(id);
|
|
this.pointA = pointA;
|
|
this.pointA = pointA;
|
|
this.pointB = pointB;
|
|
this.pointB = pointB;
|
|
@@ -21,9 +21,9 @@ export class LineSegmentModel extends GeometricObject {
|
|
super.setClass(ELEMENTS_CLASS.LINE_SEGMENT);
|
|
super.setClass(ELEMENTS_CLASS.LINE_SEGMENT);
|
|
this.definitions.push(this.pointA);
|
|
this.definitions.push(this.pointA);
|
|
this.definitions.push(this.pointB);
|
|
this.definitions.push(this.pointB);
|
|
- }
|
|
+ }
|
|
|
|
|
|
- getStraight () {
|
|
+ getStraight() {
|
|
const aX = this.pointA.posX;
|
|
const aX = this.pointA.posX;
|
|
const aY = this.pointA.posY;
|
|
const aY = this.pointA.posY;
|
|
const bX = this.pointB.posX;
|
|
const bX = this.pointB.posX;
|
|
@@ -32,10 +32,10 @@ export class LineSegmentModel extends GeometricObject {
|
|
const b = aX - bX;
|
|
const b = aX - bX;
|
|
const c = a * aX + b * aY;
|
|
const c = a * aX + b * aY;
|
|
return [a, b, c];
|
|
return [a, b, c];
|
|
- }
|
|
+ }
|
|
|
|
|
|
|
|
|
|
- getDirection () {
|
|
+ getDirection() {
|
|
const aX = this.pointA.posX;
|
|
const aX = this.pointA.posX;
|
|
const aY = this.pointA.posY;
|
|
const aY = this.pointA.posY;
|
|
const bX = this.pointB.posX;
|
|
const bX = this.pointB.posX;
|
|
@@ -43,16 +43,16 @@ export class LineSegmentModel extends GeometricObject {
|
|
const a = bX - aX;
|
|
const a = bX - aX;
|
|
const b = bY - aY;
|
|
const b = bY - aY;
|
|
return [a, b];
|
|
return [a, b];
|
|
- }
|
|
+ }
|
|
|
|
|
|
|
|
|
|
- getMiddlePoint () {
|
|
+ getMiddlePoint() {
|
|
const x = (this.pointA.posX + this.pointB.posX) / 2;
|
|
const x = (this.pointA.posX + this.pointB.posX) / 2;
|
|
const y = (this.pointA.posY + this.pointB.posY) / 2;
|
|
const y = (this.pointA.posY + this.pointB.posY) / 2;
|
|
- return { posX: x, posY: y };
|
|
+ return { posX: x, posY: y };
|
|
- }
|
|
+ }
|
|
|
|
|
|
- getIntersection (geometricObject) {
|
|
+ getIntersection(geometricObject) {
|
|
switch (geometricObject.elementClass) {
|
|
switch (geometricObject.elementClass) {
|
|
case ELEMENTS_CLASS.LINE:
|
|
case ELEMENTS_CLASS.LINE:
|
|
return geometricObject.getIntersectionWithStraightLine(this);
|
|
return geometricObject.getIntersectionWithStraightLine(this);
|
|
@@ -62,10 +62,10 @@ export class LineSegmentModel extends GeometricObject {
|
|
return this.getIntersectionByCircumference(geometricObject);
|
|
return this.getIntersectionByCircumference(geometricObject);
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- getDeterminantByLine (lineSegment) {
|
|
+ getDeterminantByLine(lineSegment) {
|
|
const og1 = this.getStraight();
|
|
const og1 = this.getStraight();
|
|
const og2 = lineSegment.getStraight();
|
|
const og2 = lineSegment.getStraight();
|
|
const a1 = og1[0];
|
|
const a1 = og1[0];
|
|
@@ -74,9 +74,9 @@ export class LineSegmentModel extends GeometricObject {
|
|
const b2 = og2[1];
|
|
const b2 = og2[1];
|
|
const determinant = a1 * b2 - a2 * b1;
|
|
const determinant = a1 * b2 - a2 * b1;
|
|
return determinant;
|
|
return determinant;
|
|
- }
|
|
+ }
|
|
|
|
|
|
- getIntersectionByLine (lineSegment) {
|
|
+ getIntersectionByLine(lineSegment) {
|
|
const og1 = this.getStraight();
|
|
const og1 = this.getStraight();
|
|
const og2 = lineSegment.getStraight();
|
|
const og2 = lineSegment.getStraight();
|
|
const a1 = og1[0];
|
|
const a1 = og1[0];
|
|
@@ -87,17 +87,17 @@ export class LineSegmentModel extends GeometricObject {
|
|
const c2 = og2[2];
|
|
const c2 = og2[2];
|
|
const determinant = a1 * b2 - a2 * b1;
|
|
const determinant = a1 * b2 - a2 * b1;
|
|
if (determinant == 0) {
|
|
if (determinant == 0) {
|
|
- return [new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, lineSegment, true,0)];
|
|
+ return [new IntersectionModel(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, lineSegment, true, 0)];
|
|
- }
|
|
+ }
|
|
else {
|
|
else {
|
|
const x = (b2 * c1 - b1 * c2) / determinant;
|
|
const x = (b2 * c1 - b1 * c2) / determinant;
|
|
const y = (a1 * c2 - a2 * c1) / determinant;
|
|
const y = (a1 * c2 - a2 * c1) / determinant;
|
|
return [new IntersectionModel(x, y, undefined, this, lineSegment, true, 0)];
|
|
return [new IntersectionModel(x, y, undefined, this, lineSegment, true, 0)];
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
- getIntersectionByCircumference (circumference) {
|
|
+ getIntersectionByCircumference(circumference) {
|
|
const pointA = this.pointA;
|
|
const pointA = this.pointA;
|
|
const pointB = this.pointB;
|
|
const pointB = this.pointB;
|
|
const center = circumference.center;
|
|
const center = circumference.center;
|
|
@@ -123,8 +123,8 @@ export class LineSegmentModel extends GeometricObject {
|
|
|
|
|
|
if (delta < 0) {
|
|
if (delta < 0) {
|
|
|
|
|
|
- return [PA,PB];
|
|
+ return [PA, PB];
|
|
- }
|
|
+ }
|
|
|
|
|
|
const deltaSqrt = Math.sqrt(delta);
|
|
const deltaSqrt = Math.sqrt(delta);
|
|
const root1 = -D + deltaSqrt;
|
|
const root1 = -D + deltaSqrt;
|
|
@@ -136,7 +136,15 @@ export class LineSegmentModel extends GeometricObject {
|
|
|
|
|
|
PA.bind(x1, y1, undefined, this, circumference, true, 0);
|
|
PA.bind(x1, y1, undefined, this, circumference, true, 0);
|
|
return [PA, PB];
|
|
return [PA, PB];
|
|
- }
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (delta == 0) {
|
|
|
|
+ PA.bind(x1, y1, undefined, this, circumference, true, 0);
|
|
|
|
+ return [
|
|
|
|
+ PA,
|
|
|
|
+ PB
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
|
|
const x2 = pointA.posX - dx * root2;
|
|
const x2 = pointA.posX - dx * root2;
|
|
const y2 = pointA.posY - dy * root2;
|
|
const y2 = pointA.posY - dy * root2;
|
|
@@ -144,20 +152,16 @@ export class LineSegmentModel extends GeometricObject {
|
|
PA.bind(x1, y1, undefined, this, circumference, true, 0);
|
|
PA.bind(x1, y1, undefined, this, circumference, true, 0);
|
|
PB.bind(x2, y2, undefined, this, circumference, true, 1);
|
|
PB.bind(x2, y2, undefined, this, circumference, true, 1);
|
|
|
|
|
|
- if (this.visible) {
|
|
+ if (!this.insideSegment(PB.posX, PB.posY))
|
|
- if (!this.insideSegment(PA.posX, PA.posY))
|
|
+ PB.bind(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 1);
|
|
- PA.bind(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 0)
|
|
|
|
|
|
|
|
- if (!this.insideSegment(PB.posX, PB.posY))
|
|
+ return [PA, PB];
|
|
- PB.bind(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, undefined, this, circumference, false, 1);
|
|
+ }
|
|
- }
|
|
|
|
- return [PA,PB];
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- insideSegment (intersecX, intersecY) {
|
|
+ insideSegment(intersecX, intersecY) {
|
|
|
|
|
|
const valuesR = this.getDirection();
|
|
const valuesR = this.getDirection();
|
|
const dirX = valuesR[0];
|
|
const dirX = valuesR[0];
|
|
@@ -169,7 +173,7 @@ export class LineSegmentModel extends GeometricObject {
|
|
|
|
|
|
if (cInterA < cRA) {
|
|
if (cInterA < cRA) {
|
|
return false;
|
|
return false;
|
|
- }
|
|
+ }
|
|
|
|
|
|
|
|
|
|
const cRB = dirX * this.pointB.posX + dirY * this.pointB.posY;
|
|
const cRB = dirX * this.pointB.posX + dirY * this.pointB.posY;
|
|
@@ -178,12 +182,12 @@ export class LineSegmentModel extends GeometricObject {
|
|
this.posX = Number.MAX_SAFE_INTEGER;
|
|
this.posX = Number.MAX_SAFE_INTEGER;
|
|
this.posY = Number.MAX_SAFE_INTEGER;
|
|
this.posY = Number.MAX_SAFE_INTEGER;
|
|
return false;
|
|
return false;
|
|
- }
|
|
+ }
|
|
|
|
|
|
return true;
|
|
return true;
|
|
- }
|
|
+ }
|
|
|
|
|
|
- static do (map, list) {
|
|
+ static do(map, list) {
|
|
const id = map.get("id");
|
|
const id = map.get("id");
|
|
const pointAId = map.get("param")[0];
|
|
const pointAId = map.get("param")[0];
|
|
const pointBId = map.get("param")[1];
|
|
const pointBId = map.get("param")[1];
|
|
@@ -191,6 +195,6 @@ export class LineSegmentModel extends GeometricObject {
|
|
const pointB = list.find(x => x.id === pointBId);
|
|
const pointB = list.find(x => x.id === pointBId);
|
|
const label = map.get("label")[0];
|
|
const label = map.get("label")[0];
|
|
return new LineSegmentModel(pointA, pointB, label, id);
|
|
return new LineSegmentModel(pointA, pointB, label, id);
|
|
- }
|
|
+ }
|
|
|
|
|
|
- }
|
|
+}
|