diff --git a/src/satx.js b/src/satx.js index c2e544f..8b27b25 100644 --- a/src/satx.js +++ b/src/satx.js @@ -49,7 +49,11 @@ export default class SATX { return 1 / Math.cos(Math.PI / numberOfVertices) } - static entityTunnel(from, to, radius) { + static entityTunnel(from, to, radius = 0) { + if (radius <= 0) { + return this.line(from, to) + } + const length = to.clone().sub(from) const halfWidth = length.clone().normalize().multiplyScalar(radius).rotateAround(new Vector2(), Math.PI / 2) const width = halfWidth.clone().multiplyScalar(2) @@ -79,6 +83,10 @@ export default class SATX { return position } + static line(from, to) { + return new SAT.Polygon(new SAT.Vector(...from.toArray()), [new SAT.Vector(), new SAT.Vector(...to.toArray())]) + } + static polygonToThreeVector2(polygon) { const position = new Vector2(polygon.pos.x, polygon.pos.y) return polygon.points.map((p) => new Vector2(p.x, p.y).add(position))