55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
import GeometryLine from "./GeometryLine.js";
|
|
import GeometryRect from "./GeometryRect.js";
|
|
|
|
export default class GeometryStroke extends GeometryLine
|
|
{
|
|
getIntersectionWithLine(line) {
|
|
let intersection = super.getIntersectionWithLine(line);
|
|
|
|
if (
|
|
intersection === null ||
|
|
!this.getRect().isContainingPoint(intersection)
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
return intersection;
|
|
}
|
|
|
|
getLine()
|
|
{
|
|
return new GeometryLine(this.pointA, this.pointB);
|
|
}
|
|
|
|
getLength()
|
|
{
|
|
return this.pointA.getDistanceToPoint(this.pointB);
|
|
}
|
|
|
|
getIntersectionWithStroke(stroke)
|
|
{
|
|
let intersection = super.getIntersectionWithLine(stroke);
|
|
|
|
if (
|
|
intersection === null ||
|
|
!this.getRect().isContainingPoint(intersection) ||
|
|
!stroke.getRect().isContainingPoint(intersection)
|
|
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
return intersection;
|
|
}
|
|
|
|
getRect()
|
|
{
|
|
let x = Math.min(this.pointA.x, this.pointB.x);
|
|
let y = Math.min(this.pointA.y, this.pointB.y);
|
|
|
|
let width = Math.max(this.pointA.x, this.pointB.x) - x;
|
|
let height = Math.max(this.pointA.y, this.pointB.y) - y;
|
|
|
|
return new GeometryRect(x, y, width, height);
|
|
}
|
|
} |