mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Basic implementations
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import GeometryPoint from "./GeometryPoint.js";
|
||||
import GeometryStroke from "./GeometryStroke.js";
|
||||
import GeometryPointCollection from "./GeometryPointCollection.js";
|
||||
import GeometryLine from "./GeometryLine.js";
|
||||
|
||||
export default class GeometryRect
|
||||
{
|
||||
@@ -31,6 +32,11 @@ export default class GeometryRect
|
||||
return containsHorizontally && containsVertically;
|
||||
}
|
||||
|
||||
hasIntersectionWithRect(rect)
|
||||
{
|
||||
return this.getBorderIntersectonsWithRect(rect).getLength() > 0;
|
||||
}
|
||||
|
||||
getBorderTop()
|
||||
{
|
||||
return new GeometryStroke(
|
||||
@@ -92,6 +98,12 @@ export default class GeometryRect
|
||||
return intersections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the intersection points between the border lines and the given stroke.
|
||||
*
|
||||
* @param stroke
|
||||
* @returns {GeometryPointCollection}
|
||||
*/
|
||||
getBorderIntersectionsWithStroke(stroke)
|
||||
{
|
||||
let borders = [
|
||||
@@ -172,6 +184,12 @@ export default class GeometryRect
|
||||
*/
|
||||
getRectIntersection(rect)
|
||||
{
|
||||
let distanceToOrigin = this.getCenter().getDistanceToPoint(rect.getCenter());
|
||||
|
||||
if (distanceToOrigin > this.getDiagonal() * 0.5 + rect.getDiagonal() * 0.5) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let intersectionPoints = new GeometryPointCollection();
|
||||
|
||||
this.getRectanglePoints().forEach(
|
||||
@@ -211,6 +229,22 @@ export default class GeometryRect
|
||||
return null;
|
||||
}
|
||||
|
||||
getCenter()
|
||||
{
|
||||
return new GeometryPoint(
|
||||
this.position.x + this.width * 0.5,
|
||||
this.position.y + this.height * 0.5
|
||||
);
|
||||
}
|
||||
|
||||
getDiagonal()
|
||||
{
|
||||
return new GeometryStroke(
|
||||
this.position,
|
||||
new GeometryPoint(this.position.x + this.width, this.position.y + this.height)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visualizes the rect.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user