1 unstable release
Uses new Rust 2024
| 0.1.0 | Dec 25, 2025 |
|---|
#1313 in Game dev
Used in 3 crates
76KB
1.5K
SLoC
Minimal 2D math primitives for game development and physics simulation.
This crate provides core mathematical types that are used throughout the Gravita engine:
Vec2— 2D vector with common operations (add, scale, normalize, rotate, etc.)AABB— Axis-aligned bounding box for collision queriesCircle— Circle primitive for collision detectionRay2D— Ray for raycasting and intersection testsTransform2D— Position + rotation transform
Design Goals
- Zero dependencies: Core math should compile instantly
- Inline everything: Performance-critical code path
- Simple API: Prefer free functions and methods over traits
Examples
use gravita_math::{Vec2, clamp, lerp};
let velocity = Vec2::new(100.0, 50.0);
let normalized = velocity.normalize();
let clamped = clamp(velocity.length(), 0.0, 200.0);
gravita-math
Minimal 2D math primitives for game development and physics simulation.
Features
Vec2— 2D vector with full operator supportAABB— Axis-aligned bounding boxCircle— Circle primitiveRay2D— Ray for intersection testsTransform2D— Position + rotation
Design Goals
- Zero external dependencies
- All operations inlined for performance
- Simple, predictable API
Usage
use gravita_math::{Vec2, AABB, Circle, lerp, clamp};
// Vector operations
let v = Vec2::new(3.0, 4.0);
assert_eq!(v.length(), 5.0);
assert_eq!(v.normalize().length(), 1.0);
// AABB operations
let box1 = AABB::from_center_size(Vec2::ZERO, Vec2::new(10.0, 10.0));
let box2 = AABB::from_center_size(Vec2::new(5.0, 0.0), Vec2::new(10.0, 10.0));
assert!(box1.intersects(&box2));
// Utility functions
let clamped = clamp(150.0, 0.0, 100.0); // 100.0
let interpolated = lerp(0.0, 100.0, 0.5); // 50.0
License
MIT OR Apache-2.0