Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let bodyB = collision.bodyB;
// Find the support points; there is always either exactly one or two
let verticesB = SAT.findSupports(bodyA, bodyB, collision.normal),
supports = [];
// Find the supports from bodyB that are inside bodyA
if (Vertices.contains(bodyA.vertices, verticesB[0]))
supports.push(verticesB[0]);
if (Vertices.contains(bodyA.vertices, verticesB[1]))
supports.push(verticesB[1]);
// Find the supports from bodyA that are inside bodyB
if (supports.length < 2) {
let verticesA = SAT.findSupports(bodyB, bodyA, Vector.neg(collision.normal));
if (Vertices.contains(bodyB.vertices, verticesA[0]))
supports.push(verticesA[0]);
if (supports.length < 2 && Vertices.contains(bodyB.vertices, verticesA[1]))
supports.push(verticesA[1]);
}
// Account for the edge case of overlapping but no vertex containment
if (supports.length < 1)
supports = [verticesB[0]];
return supports;
}
};
// Is there a trailing edge, is it convex?
if (hasVertex3) {
edge2 = Vector.sub(m_v3, m_v2);
edge2 = Vector.normalise(edge2);
convex2 = Vector.cross(edge1, edge2) >= 0.0;
}
// Determine collision normal limits for front and back collisions
if (hasVertex0 && hasVertex3) {
if (convex1 && convex2) {
front.normal = m_normal1;
front.lowerLimit = m_normal0;
front.upperLimit = m_normal2;
back.normal = Vector.neg(m_normal1);
back.lowerLimit = Vector.neg(m_normal1);
back.upperLimit = Vector.neg(m_normal1);
} else if (convex1) {
front.normal = m_normal1;
front.lowerLimit = m_normal0;
front.upperLimit = m_normal1;
back.normal = Vector.neg(m_normal1);
back.lowerLimit = Vector.neg(m_normal2);
back.upperLimit = Vector.neg(m_normal1);
} else if (convex2) {
front.normal = m_normal1;
front.lowerLimit = m_normal1;
front.upperLimit = m_normal2;
back.normal = Vector.neg(m_normal1);
back.lowerLimit = Vector.neg(m_normal1);
// Is there a trailing edge, is it convex?
if (hasVertex3) {
edge2 = Vector.sub(m_v3, m_v2);
edge2 = Vector.normalise(edge2);
convex2 = Vector.cross(edge1, edge2) >= 0.0;
}
// Determine collision normal limits for front and back collisions
if (hasVertex0 && hasVertex3) {
if (convex1 && convex2) {
front.normal = m_normal1;
front.lowerLimit = m_normal0;
front.upperLimit = m_normal2;
back.normal = Vector.neg(m_normal1);
back.lowerLimit = Vector.neg(m_normal1);
back.upperLimit = Vector.neg(m_normal1);
} else if (convex1) {
front.normal = m_normal1;
front.lowerLimit = m_normal0;
front.upperLimit = m_normal1;
back.normal = Vector.neg(m_normal1);
back.lowerLimit = Vector.neg(m_normal2);
back.upperLimit = Vector.neg(m_normal1);
} else if (convex2) {
front.normal = m_normal1;
front.lowerLimit = m_normal1;
front.upperLimit = m_normal2;
back.normal = Vector.neg(m_normal1);
} else {
front.normal = m_normal1;
front.lowerLimit = m_normal1;
front.upperLimit = m_normal1;
back.normal = Vector.neg(m_normal1);
back.lowerLimit = Vector.neg(m_normal2);
back.upperLimit = Vector.neg(m_normal0);
}
} else if (hasVertex0) {
if (convex1) {
front.normal = m_normal1;
front.lowerLimit = m_normal0;
front.upperLimit = Vector.neg(m_normal1);
back.normal = Vector.neg(m_normal1);
back.lowerLimit = m_normal1;
back.upperLimit = Vector.neg(m_normal1);
} else {
front.normal = m_normal1;
front.lowerLimit = m_normal1;
front.upperLimit = Vector.neg(m_normal1);
back.normal = Vector.neg(m_normal1);
back.lowerLimit = m_normal1;
back.upperLimit = Vector.neg(m_normal0);
}
} else if (hasVertex3) {
if (convex2) {
front.normal = m_normal1;
front.lowerLimit = Vector.neg(m_normal1);
front.upperLimit = m_normal2;
} else if (convex1) {
front.normal = m_normal1;
front.lowerLimit = m_normal0;
front.upperLimit = m_normal1;
back.normal = Vector.neg(m_normal1);
back.lowerLimit = Vector.neg(m_normal2);
back.upperLimit = Vector.neg(m_normal1);
} else if (convex2) {
front.normal = m_normal1;
front.lowerLimit = m_normal1;
front.upperLimit = m_normal2;
back.normal = Vector.neg(m_normal1);
back.lowerLimit = Vector.neg(m_normal1);
back.upperLimit = Vector.neg(m_normal0);
} else {
front.normal = m_normal1;
front.lowerLimit = m_normal1;
front.upperLimit = m_normal1;
back.normal = Vector.neg(m_normal1);
back.lowerLimit = Vector.neg(m_normal2);
back.upperLimit = Vector.neg(m_normal0);
}
} else if (hasVertex0) {
if (convex1) {
front.normal = m_normal1;
front.lowerLimit = m_normal0;
front.upperLimit = Vector.neg(m_normal1);
back.normal = Vector.neg(m_normal1);
} else if (hasVertex3) {
if (convex2) {
front.normal = m_normal1;
front.lowerLimit = Vector.neg(m_normal1);
front.upperLimit = m_normal2;
back.normal = Vector.neg(m_normal1);
back.lowerLimit = Vector.neg(m_normal1);
back.upperLimit = m_normal1;
} else {
front.normal = m_normal1;
front.lowerLimit = Vector.neg(m_normal1);
front.upperLimit = m_normal1;
back.normal = Vector.neg(m_normal1);
back.lowerLimit = Vector.neg(m_normal2);
back.upperLimit = m_normal1;
}
} else {
front.normal = m_normal1;
front.lowerLimit = Vector.neg(m_normal1);
front.upperLimit = Vector.neg(m_normal1);
back.normal = Vector.neg(m_normal1);
back.lowerLimit = m_normal1;
back.upperLimit = m_normal1;
}
edge.convexPrev = convex1;
edge.convexNext = convex2;
edge.normalRanges = {
back.lowerLimit = Vector.neg(m_normal1);
back.upperLimit = Vector.neg(m_normal0);
} else {
front.normal = m_normal1;
front.lowerLimit = m_normal1;
front.upperLimit = m_normal1;
back.normal = Vector.neg(m_normal1);
back.lowerLimit = Vector.neg(m_normal2);
back.upperLimit = Vector.neg(m_normal0);
}
} else if (hasVertex0) {
if (convex1) {
front.normal = m_normal1;
front.lowerLimit = m_normal0;
front.upperLimit = Vector.neg(m_normal1);
back.normal = Vector.neg(m_normal1);
back.lowerLimit = m_normal1;
back.upperLimit = Vector.neg(m_normal1);
} else {
front.normal = m_normal1;
front.lowerLimit = m_normal1;
front.upperLimit = Vector.neg(m_normal1);
back.normal = Vector.neg(m_normal1);
back.lowerLimit = m_normal1;
back.upperLimit = Vector.neg(m_normal0);
}
} else if (hasVertex3) {
if (convex2) {
front.normal = m_normal1;