Skip to main content

box3d_rust/geometry/
mod.rs

1//! Shape geometry queries: sphere, capsule, and hull mass/AABB/overlap/cast.
2//!
3//! Port of `box3d-cpp-reference/src/sphere.c`, `capsule.c`, and the query APIs
4//! at the end of `hull.c`. Types come from `include/box3d/types.h`.
5//!
6//! Layout (mirrors box2d-rust `geometry/`):
7//! - `types.rs`  — MassData, Sphere, Capsule, RayCastInput, ShapeCastInput
8//! - `sphere.rs` — sphere mass, AABB, overlap, ray/shape cast
9//! - `capsule.rs` — capsule mass, AABB, overlap, ray/shape cast
10//!
11//! Hull queries live in [`crate::hull::queries`] and are re-exported here.
12//!
13//! SPDX-FileCopyrightText: 2026 Erin Catto
14//! SPDX-License-Identifier: MIT
15
16mod capsule;
17mod sphere;
18pub(crate) mod types;
19
20pub use capsule::{
21    collide_mover_and_capsule, compute_capsule_aabb, compute_capsule_mass,
22    compute_swept_capsule_aabb, overlap_capsule, ray_cast_capsule, shape_cast_capsule,
23};
24pub use sphere::{
25    collide_mover_and_sphere, compute_sphere_aabb, compute_sphere_mass, compute_swept_sphere_aabb,
26    overlap_sphere, ray_cast_hollow_sphere, ray_cast_sphere, shape_cast_sphere,
27};
28pub use types::{
29    default_surface_material, Capsule, CollisionPlane, MassData, PlaneResult, PlaneSolverResult,
30    RayCastInput, ShapeCastInput, ShapeExtent, ShapeType, Sphere, SurfaceMaterial,
31    SURFACE_MATERIAL_SIZE,
32};
33
34pub use crate::distance::CastOutput;
35pub use crate::hull::{
36    collide_mover_and_hull, compute_hull_aabb, compute_hull_mass, compute_swept_hull_aabb,
37    overlap_hull, ray_cast_hull, shape_cast_hull,
38};
39
40use crate::constants::huge;
41use crate::math_functions::{is_valid_float, is_valid_vec3};
42
43/// Validate ray cast input data (NaN, etc). (b3IsValidRay)
44pub fn is_valid_ray(input: &RayCastInput) -> bool {
45    is_valid_vec3(input.origin)
46        && is_valid_vec3(input.translation)
47        && is_valid_float(input.max_fraction)
48        && 0.0 <= input.max_fraction
49        && input.max_fraction < huge()
50}