Well found a very old aabb overlap test of mine, still works but well... it may be slow, maybe its slowest ever - or it is not that bad?
Try to beat it
union Vec2f {
struct {
float x, y;
};
float m[2];
};
union AABB {
struct {
Vec2f min, max;
};
Vec2f m[2];
};
bool IsAABBOverlap(const AABB &a, const AABB &b) {
// @SPEED: This is the slowest aabb overlap test ever exists!
float distanceX = a.max.x - a.min.x;
float distanceY = a.max.y - a.min.y;
float otherDistanceX = b.max.x - b.min.x;
float otherDistanceY = b.max.y - b.min.y;
float bothRadiusX = (Abs(distanceX) + Abs(otherDistanceX)) * 0.5f;
float bothRadiusY = (Abs(distanceY) + Abs(otherDistanceY)) * 0.5f;
float otherCenterX = b.min.x + otherDistanceX * 0.5f;
float otherCenterY = b.min.y + otherDistanceY * 0.5f;
float centerX = a.min.x + distanceX * 0.5f;
float centerY = a.min.y + distanceY * 0.5f;
float diffX = Abs(centerX - otherCenterX);
float diffY = Abs(centerY - otherCenterY);
float overlapX = diffX - bothRadiusX;
float overlapY = diffY - bothRadiusY;
float result = !(overlapX > 0 || overlapY > 0);
return(result);
}
↧