From b827dbefb936d0a226d75cc794358b68283bef46 Mon Sep 17 00:00:00 2001 From: Nicolas Maman Date: Wed, 25 Nov 2026 15:43:30 -0300 Subject: [PATCH] Fat bounds: the convex kinds' own boxes, inline Every awake body's shapes get their fat bounds in finalize each step, and compute_fat_shape_aabb went through compute_shape_aabb, whose dispatch over every kind stays a call with its transform and box through memory. The hull, the sphere and the capsule now take their own small bounds there, which inline; the rest keep the call. Pinned, best of five: many pyramids 14.90 to 14.33 ms a step (median 15.77 to 14.97), the convex pile 9.88 to 9.79; the large pyramid and sleep within noise. Bits unchanged. --- aephysics/shape/module.ae | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/aephysics/shape/module.ae b/aephysics/shape/module.ae index c7a1ae2..a75a572 100644 --- a/aephysics/shape/module.ae +++ b/aephysics/shape/module.ae @@ -179,10 +179,20 @@ compute_shape_aabb(shape: *Shape, t: Transform) -> AABB { // The bounds under a transform inflated by a margin: built in the shape's // frame and inflated before the translation, so the margin survives far // from the origin. +// +// Every awake body's shapes go through here each step (finalize). The +// convex kinds, nearly all of them, take their own small bounds here, +// which inline; the rest go through compute_shape_aabb, whose dispatch +// over every kind stays a call, with its transform and box through memory. compute_fat_shape_aabb(shape: *Shape, t: Transform, extra: float) -> AABB { r = math.vec3(extra, extra, extra) rotation = Transform { p: math.vec3_zero(), q: t.q } - local_box = compute_shape_aabb(shape, rotation) + kind = shape.kind + local_box = AABB { lower: math.vec3_zero(), upper: math.vec3_zero() } + if kind == SHAPE_HULL { local_box = hull.compute_hull_aabb(shape.hull, rotation) } + else if kind == SHAPE_SPHERE { local_box = sphere.compute_sphere_aabb(shape.sphere, rotation) } + else if kind == SHAPE_CAPSULE { local_box = capsule.compute_capsule_aabb(shape.capsule, rotation) } + else { local_box = compute_shape_aabb(shape, rotation) } local_box.lower = math.sub(local_box.lower, r) local_box.upper = math.add(local_box.upper, r) return math.offset_aabb(local_box, t.p)