@Override public boolean intersects( Vector2 position, FlipInfo flip, CollisionVolume other, Vector2 otherPosition, FlipInfo otherFlip) { boolean result = false; if (other instanceof AABoxCollisionVolume) { // It's more accurate to do a sphere-as-box test than a box-as-sphere test. result = other.intersects(otherPosition, otherFlip, this, position, flip); } else { mWorkspaceVector.set(position); offsetByCenter(mWorkspaceVector, mCenter, flip); float otherRadius = 0; if (other instanceof SphereCollisionVolume) { SphereCollisionVolume sphereOther = (SphereCollisionVolume) other; mWorkspaceVector2.set(otherPosition); offsetByCenter(mWorkspaceVector2, sphereOther.getCenter(), otherFlip); mWorkspaceVector.subtract(mWorkspaceVector2); otherRadius = sphereOther.getRadius(); } else { // Whatever this volume is, pretend it's a sphere. final float deltaX = other.getMaxXPosition(otherFlip) - other.getMinXPosition(otherFlip); final float deltaY = other.getMaxYPosition(otherFlip) - other.getMinYPosition(otherFlip); final float centerX = deltaX / 2.0f; final float centerY = deltaY / 2.0f; mWorkspaceVector2.set(otherPosition); mWorkspaceVector2.x += centerX; mWorkspaceVector2.y += centerY; otherRadius = Math.max(deltaX, deltaY); } final float maxDistance = mRadius + otherRadius; final float distance2 = mWorkspaceVector.length2(); final float maxDistance2 = (maxDistance * maxDistance); if (distance2 < maxDistance2) { result = true; } } return result; }