mr-crocs-adventures/js/geometry/GeometryStroke.js

55 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2020-01-19 00:45:17 +01:00
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);
}
2020-01-22 22:50:45 +01:00
getLength()
{
return this.pointA.getDistanceToPoint(this.pointB);
}
2020-01-19 00:45:17 +01:00
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);
}
}