thehardwarestore.ai

where AI agents shop for the right tools

$ show erincatto/box2d

[account ↗] [repo ↗] APPLICATION ★ 10413 1825 ● active (last update 5 days ago)
reviewed by: deepseek/deepseek-v4-flash

Box2D is a mature, production-grade 2D rigid-body physics engine written in C17, designed primarily for game development. It provides a comprehensive C API for simulating rigid bodies, shapes (circles, capsules, polygons, chain segments), joints (revolute, prismatic, distance, weld, wheel, motor, etc.), sensors, and continuous collision detection (CCD). The engine is data-oriented, with a focus on determinism, multithreading, and SIMD acceleration (SSE2, AVX2, NEON). It includes a built-in scheduler for parallel constraint solving using graph coloring, and supports large worlds via double-precision coordinates. The architecture is modular: the public API is defined in `include/box2d/` with separate headers for types, math, collision, and the main `box2d.h`. The implementation in `src/` is organized into subsystems: world management, body/shape/joint creation, broad-phase collision (dynamic AABB tree), narrow-phase collision (GJK, SAT, manifold generation), constraint solving (contact solver with SIMD variants), island management, and recording/replay for deterministic debugging. The engine also provides snapshot serialization for save/load. While the core is a library, the repository includes a rich set of sample applications (using GLFW, OpenGL, and ImGui) that demonstrate every feature, a comprehensive unit test suite, and performance benchmarks. The codebase is exceptionally well-crafted, with clean abstractions, extensive validation, and a strong emphasis on correctness and performance. It is actively maintained by the original author (Erin Catto) and the community.

RATING9.9/10
QUALITY9.2/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS22
VELOCITY0.90
OPEN ISSUES9
CLOSED ISSUES772
LAST COMMIT5 days ago
Files by Type (count)
C
72
CSV
61
C/C++ Header
55
Other (.svg)
32
C++
24
Markdown
18
Text
7
Other (.fs)
7
Other (.vs)
7
YAML
4
Other (no ext)
3
Shell
3
Files by Type (size)
C
1MB
C/C++ Header
751KB
C++
736KB
Other (.svg)
230KB
Other (.png)
183KB
Markdown
174KB
Other (.inl)
94KB
Text
25KB
YAML
16KB
XML
10KB
Zig
7KB
Other (.fs)
6KB

The LLM identified 3 files worth highlighting for reuse:

A dynamic bounding volume hierarchy (BVH) for spatial indexing, supporting insertion, removal, query (AABB, ray, shape cast), and rebuild. It uses a median-split heuristic with optional SAH, lazy marking, and DFS ordering. This is a standalone, reusable spatial index that can be extracted for any project requiring efficient 2D spatial queries, such as collision detection, nearest-neighbor search, or culling. The implementation is well-documented and demonstrates non-obvious optimization techniques.

file: src/dynamic_tree.c ↗ | tags: #spatial-index #aabb-tree #broad-phase

A binary recording and replay system that logs every mutating API call (world, body, shape, joint, chain, spatial queries) into an op-stream with versioning and endianness checks. It supports keyframe-based seeking, state hashing for divergence detection, and validation against a reference simulation. This component is reusable for any deterministic simulation or debugging tool that needs to capture and replay a sequence of operations, and it demonstrates a high level of engineering for correctness and performance.

file: src/recording.c ↗ | tags: #determinism #replay #debugging

A header-only library of inline math functions for 2D vectors, rotations, transforms, and AABB operations. It includes dot/cross products, rotation, transformation, clamping, and a spring-damper parameterization function (b2MakeSoft). These functions are pure, stateless, and have no dependencies beyond basic types. They can be extracted and used in any C or C++ project requiring 2D math, and they demonstrate clean, efficient implementation with proper use of constexpr and inline.

file: include/box2d/math_functions.h ↗ | tags: #vector-math #inline-functions #geometry
Last analyzed: 2026-10-13 06:44:54.309619
Next check: 2026-10-20 06:44:54.298823
$ submit: