|
@@ -17,6 +17,15 @@ export class LineSegmentModel extends GeometricObject {
|
|
|
const c = a * aX + b * aY;
|
|
|
return [a, b, c];
|
|
|
}
|
|
|
+ getDirection() {
|
|
|
+ const aX = this.pointA.posX;
|
|
|
+ const aY = this.pointA.posY;
|
|
|
+ const bX = this.pointB.posX;
|
|
|
+ const bY = this.pointB.posY;
|
|
|
+ const a = bX - aX;
|
|
|
+ const b = bY - aY;
|
|
|
+ return [a, b];
|
|
|
+ }
|
|
|
getIntersection(lineSegment) {
|
|
|
const r = this.getStraight();
|
|
|
const s = lineSegment.getStraight();
|
|
@@ -41,4 +50,29 @@ export class LineSegmentModel extends GeometricObject {
|
|
|
return new IntersectionModel(x, y, undefined, this, lineSegment);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ insideSegment(intersecX, intersecY) {
|
|
|
+ const valuesR = this.getDirection();
|
|
|
+ const dirX = valuesR[0];
|
|
|
+ const dirY = valuesR[1];
|
|
|
+ const cInterA = dirX * intersecX + dirY * intersecY;
|
|
|
+
|
|
|
+ // comparaca cv do ponto A > cv da intersec => vazio
|
|
|
+ const cRA = dirX * this.pointA.posX + dirY * this.pointA.posY;
|
|
|
+
|
|
|
+ if (cInterA < cRA) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // comparaca cv do ponto B < cv da intersec => vazio
|
|
|
+ const cRB = dirX * this.pointB.posX + dirY * this.pointB.posY;
|
|
|
+
|
|
|
+ if (cInterA > cRB) {
|
|
|
+ this.posX = Number.MAX_SAFE_INTEGER;
|
|
|
+ this.posY = Number.MAX_SAFE_INTEGER;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|