Expand description
Geometric shape implementations for 3D physics simulations.
This module provides a collection of primitive geometric shapes commonly used in physics
engines, along with their basic properties and operations. All shapes are designed to be
FFI-safe through the #[repr(C)] attribute and support optional serialization via the serde
feature.
§Available Shapes
Sphere- A perfect sphere defined by its radiusCapsule- A capsule with cylindrical body and hemispherical capsCuboid- A rectangular box (also known as a box or rectangular prism)Cylinder- A cylinder with circular cross-sectionInfinitePlane- An infinite plane (primarily for geometric computations)Tetrahedron- A tetrahedron defined by four vertices
§Common Properties
All shapes share these characteristics:
- FFI-safe: All shapes use
#[repr(C)]for C compatibility - Serializable: Support
serdeserialization when the feature is enabled - Validated: Construction validates parameters (e.g., positive dimensions)
- Copy-friendly: All shapes implement
CopyandClone
§Usage Examples
use phys_geom::shape::{Sphere, Capsule, Cuboid, Cylinder};
// Create a sphere
let sphere = Sphere::new(1.0);
assert_eq!(sphere.radius(), 1.0);
// Create a capsule with cylindrical half-height 2.0 and radius 0.5
let capsule = Capsule::new(2.0, 0.5);
assert_eq!(capsule.height(), 4.0); // cylinder height (excluding caps)
// Create a cuboid (box) with dimensions 2x3x1
let cuboid = Cuboid::new([2.0, 3.0, 1.0]);
assert_eq!(cuboid.length(), [2.0, 3.0, 1.0]);
// Create a cylinder
let cylinder = Cylinder::new(1.5, 0.8); // half-height=1.5, radius=0.8
assert_eq!(cylinder.height(), 3.0);Structs§
- Capsule
- A capsule shape centered at the origin, aligned along the Y-axis.
- Cuboid
- A cuboid (rectangular box) shape centered at the origin.
- Cylinder
- A cylinder shape centered at the origin, aligned along the Y-axis.
- Infinite
Plane - An infinite plane in 3D space.
- Sphere
- A sphere shape centered at the origin.
- Tetrahedron
- A tetrahedron defined by four vertices in 3D space.
- Triangle
- A triangle defined by three vertices in 3D space.