A body needs a shape to collide. The simplest is a circle, and the cheapest thing you can ask of any shape is its axis-aligned bounding box. Today you build both.
Define a circle shape and compute its axis-aligned bounding box around a center.
A circle is the friendliest shape in a physics engine - it is the same from every
angle, so it has no rotation to worry about, and its collision tests are pure distance
checks. All it needs is a radius; its center is wherever the body sits. Define the
Circle type now, and it becomes the first thing a body can actually collide with.
Every shape also needs to report an axis-aligned bounding box (AABB): the smallest
upright rectangle that fully contains it, described by its minimum and maximum corners.
For a circle that is simply the center plus and minus the radius in each direction.
Bounding boxes are what the broadphase will use later to reject pairs that cannot
possibly be touching, cheaply, before running the exact test - so giving every shape a
Bounds is the foundation of making collision detection fast.
type AABB struct{ Min, Max Vec2 }type Circle struct{ Radius float64 }// the box just fits the circle: center plus and minus the radiusfunc (c Circle) Bounds(center Vec2) AABB {r := Vec2{c.Radius, c.Radius}return AABB{Min: Sub(center, r), Max: Add(center, r)}}