Fixes circular SAT
This commit is contained in:
@@ -33,7 +33,14 @@ export class Polygon {
|
||||
return center;
|
||||
}
|
||||
|
||||
get circularHitbox(): CircleLike {
|
||||
_circularBoundingBox?: CircleLike;
|
||||
|
||||
get circularBoundingBox(): CircleLike {
|
||||
this._circularBoundingBox = this.calculateCircularBoundingBox();
|
||||
return this._circularBoundingBox;
|
||||
}
|
||||
|
||||
private calculateCircularBoundingBox() {
|
||||
let greatestDistance = 0;
|
||||
for (const p of this.points) {
|
||||
greatestDistance = Math.max(
|
||||
@@ -50,13 +57,11 @@ export class Polygon {
|
||||
|
||||
_aabb?: axisAlignedBoundingBox;
|
||||
get AABB(): axisAlignedBoundingBox {
|
||||
if (!this._aabb) {
|
||||
this._aabb = this.recalculateAABB();
|
||||
}
|
||||
this._aabb = this.recalculateAABB();
|
||||
return this._aabb;
|
||||
}
|
||||
|
||||
recalculateAABB(): axisAlignedBoundingBox {
|
||||
private recalculateAABB(): axisAlignedBoundingBox {
|
||||
let smallestX, biggestX, smallestY, biggestY;
|
||||
smallestX =
|
||||
smallestY =
|
||||
@@ -74,8 +79,8 @@ export class Polygon {
|
||||
}
|
||||
|
||||
return {
|
||||
x: smallestX,
|
||||
y: smallestY,
|
||||
x: smallestX + this.center.x,
|
||||
y: smallestY + this.center.y,
|
||||
w: biggestX - smallestX,
|
||||
h: biggestY - smallestY,
|
||||
};
|
||||
@@ -118,6 +123,6 @@ export class Polygon {
|
||||
for (const point of this.points) {
|
||||
if (p.dist(point) < p.dist(nearest)) nearest = point;
|
||||
}
|
||||
return nearest;
|
||||
return nearest.copy().add(this.center);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user