mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Init
This commit is contained in:
50
js/geometry/GeometryStroke.js
Normal file
50
js/geometry/GeometryStroke.js
Normal file
@@ -0,0 +1,50 @@
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user