fall back to lines when radius is zero
This commit is contained in:
+9
-1
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user