🎯 ndarray_cg
High-performance computer graphics mathematics built on ndarray
A comprehensive matrix and linear algebra library specifically designed for computer graphics applications. Built on top of the powerful ndarray
crate, ndarray_cg provides specialized functionality for 2D/3D transformations, graphics pipelines, and geometric operations with excellent performance characteristics.
✨ Features
🔄 Matrix Operations
- 2D/3D/4D Matrices - Specialized matrix types for graphics (Mat2, Mat3, Mat4)
- Row & Column Major - Support for both memory layouts
- Operator Overloading - Natural mathematical syntax (+, -, *, etc.)
- In-Place Operations - Memory-efficient computations
🎮 Graphics Transformations
- Rotation Matrices - 2D/3D rotation operations
- Translation - Homogeneous coordinate translations
- Scaling - Uniform and non-uniform scaling
- Reflection - Mirror transformations
- Shearing - Skew transformations
🚀 Performance Optimized
- SIMD Support - Vectorized operations via ndarray
- Zero-Copy Views - Efficient memory access patterns
- Stack Allocation - Small matrices on stack
- Generic Types - Works with f32, f64, and other numeric types
🔧 Developer Experience
- Type Aliases - Convenient F32x2x2, F32x3x3, F32x4x4 types
- Indexed Iteration - Multiple iteration patterns
- Debug Support - Rich debugging and display traits
📦 Installation
Add to your Cargo.toml
:
= { = true, = ["enabled"] }
🚀 Quick Start
Basic Matrix Operations
use *;
Common Graphics Transformations
use *;
use PI;
Matrix Arithmetic Operations
use *;
Matrix Multiplication
use *;
use DescriptorOrderRowMajor;
📖 API Reference
Matrix Types
Type | Description | Use Case |
---|---|---|
Mat2 / F32x2x2 |
2x2 matrix | 2D transformations |
Mat3 / F32x3x3 |
3x3 matrix | 2D homogeneous coords |
Mat4 / F32x4x4 |
4x4 matrix | 3D transformations |
Transformation Functions
Function | Purpose | Example |
---|---|---|
mat2x2::rot(angle) |
2D rotation | mat2x2::rot(PI / 4.0) |
mat2x2::scale([sx, sy]) |
2D scaling | mat2x2::scale([2.0, 3.0]) |
mat2x2h::translate([tx, ty]) |
2D translation | mat2x2h::translate([5.0, 10.0]) |
mat2x2::reflect_x() |
X-axis reflection | mat2x2::reflect_x() |
mat2x2::shear([shx, shy]) |
Shearing | mat2x2::shear([1.0, 0.5]) |
Advanced Features
use *;
use DescriptorOrderRowMajor;
🎯 Use Cases
- 2D Game Development - Sprite transformations and camera systems
- 3D Graphics Programming - Model-view-projection matrices
- Computer Vision - Image transformations and homography
- Animation Systems - Skeletal animation and keyframe interpolation
- Physics Simulations - Coordinate system transformations
🔧 Advanced Configuration
Features
enabled
- Core functionality (default)full
- All features enabled
Memory Layout Options
use *;
use ;
// Row-major (default for graphics)
let row_major = from_row_major;
// Column-major (for compatibility with certain graphics APIs)
let col_major = default;
âš¡ Performance Notes
- Built on ndarray's highly optimized SIMD operations
- Zero-cost abstractions over raw array operations
- Efficient memory layouts for cache performance
- Generic over numeric types (f32, f64, etc.)