| Crates.io | mdmath_core |
| lib.rs | mdmath_core |
| version | 0.4.0 |
| created_at | 2024-09-17 09:37:49.49271+00 |
| updated_at | 2025-08-09 18:28:41.997694+00 |
| description | Core multidimensional mathematics library with fundamental types, traits, and operations |
| homepage | https://github.com/Wandalen/cgtools/tree/master/module/math/mdmath_core |
| repository | https://github.com/Wandalen/cgtools |
| max_upload_size | |
| id | 1377273 |
| size | 159,979 |
Fundamental multidimensional mathematics for computer graphics and scientific computing
A high-performance, type-safe mathematics library providing essential vector operations and geometric primitives. Built specifically for computer graphics applications with support for n-dimensional vector spaces and optimized operations.
Add to your Cargo.toml:
mdmath_core = { workspace = true }
Or with specific features:
mdmath_core = { workspace = true, features = ["full"] }
use mdmath_core::vector;
fn main() {
// Create vectors as arrays
let vec_a = [1.0, 2.0, 3.0];
let vec_b = [4.0, 5.0, 6.0];
// Dot product
let dot_result = vector::dot(&vec_a, &vec_b);
println!("Dot product: {}", dot_result); // 32.0
// Vector magnitude
let magnitude: f32 = vector::mag2(&vec_a);
let magnitude = magnitude.sqrt();
println!("Magnitude: {}", magnitude); // ~3.74
// Normalize vector
let mut normalized = vec_a;
vector::normalize(&mut normalized, &vec_a);
println!("Normalized: {:?}", normalized);
}
use mdmath_core::vector;
use approx::assert_ulps_eq;
fn advanced_example() {
// Vector projection
let mut vec_a = [1.0, 2.0, 3.0];
let vec_b = [4.0, 5.0, 6.0];
vector::project_on(&mut vec_a, &vec_b);
// Angle between vectors
let vec_x = [1.0, 0.0];
let vec_y = [0.0, 1.0];
let angle = vector::angle(&vec_x, &vec_y);
assert_ulps_eq!(angle, std::f32::consts::FRAC_PI_2);
// Check orthogonality
let is_orthogonal = vector::is_orthogonal(&vec_x, &vec_y);
assert!(is_orthogonal);
}
| Function | Description | Example |
|---|---|---|
dot(a, b) |
Compute dot product | vector::dot(&[1,2], &[3,4]) |
mag2(v) |
Squared magnitude | vector::mag2(&[3,4]) → 25.0 |
normalize(dst, src) |
Normalize vector | vector::normalize(&mut v, &src) |
project_on(a, b) |
Project a onto b | vector::project_on(&mut a, &b) |
angle(a, b) |
Angle between vectors | vector::angle(&a, &b) |
is_orthogonal(a, b) |
Check perpendicularity | vector::is_orthogonal(&a, &b) |
Enable additional functionality:
mdmath_core = { workspace = true, features = ["full", "approx", "arithmetics"] }
full - All features enabledapprox - Floating-point comparison utilitiesarithmetics - Advanced arithmetic operationsnd - N-dimensional array supportmdmath_core is designed for high-performance applications: