Skip to main content

box2d_rust/geometry/
mod.rs

1// Port of box2d-cpp-reference/src/geometry.c.
2//
3// Split to satisfy the 800-line file limit:
4// - shapes.rs     — polygon constructors and transforms
5// - mass.rs       — mass properties for circle, capsule, polygon
6// - bounds.rs     — shape AABB computation (fat and tight)
7// - point_ray.rs  — point-in-shape tests and ray casts
8// - shape_cast.rs — shape cast wrappers and mover collision
9//
10// SPDX-FileCopyrightText: 2023 Erin Catto
11// SPDX-License-Identifier: MIT
12
13mod bounds;
14mod mass;
15mod point_ray;
16mod shape_cast;
17mod shapes;
18
19pub use bounds::{
20    compute_capsule_aabb, compute_circle_aabb, compute_fat_shape_aabb, compute_polygon_aabb,
21    compute_segment_aabb,
22};
23pub use mass::{compute_capsule_mass, compute_circle_mass, compute_polygon_mass};
24pub use point_ray::{
25    point_in_capsule, point_in_circle, point_in_polygon, ray_cast_capsule, ray_cast_circle,
26    ray_cast_polygon, ray_cast_segment,
27};
28pub use shape_cast::{
29    collide_mover_and_capsule, collide_mover_and_circle, collide_mover_and_polygon,
30    collide_mover_and_segment, shape_cast_capsule, shape_cast_circle, shape_cast_polygon,
31    shape_cast_segment,
32};
33pub use shapes::{
34    make_box, make_offset_box, make_offset_polygon, make_offset_rounded_box,
35    make_offset_rounded_polygon, make_polygon, make_rounded_box, make_square, transform_polygon,
36};
37
38use crate::collision::RayCastInput;
39use crate::constants::huge;
40use crate::math_functions::{is_valid_float, is_valid_vec2};
41
42/// Validate ray cast input data (NaN, etc). (b2IsValidRay)
43pub fn is_valid_ray(input: &RayCastInput) -> bool {
44    is_valid_vec2(input.origin)
45        && is_valid_vec2(input.translation)
46        && is_valid_float(input.max_fraction)
47        && 0.0 <= input.max_fraction
48        && input.max_fraction < huge()
49}