Crates.io | vecmath |
lib.rs | vecmath |
version | 1.0.0 |
source | src |
created_at | 2014-12-11 12:03:12.569597 |
updated_at | 2019-05-23 18:09:23.318737 |
description | A simple and type agnostic library for vector math designed for reexporting |
homepage | https://github.com/pistondevelopers/vecmath |
repository | https://github.com/pistondevelopers/vecmath.git |
max_upload_size | |
id | 511 |
size | 58,481 |
A simple and type agnostic Rust library for vector math designed for reexporting
It is hard to agree on the "the best" way of designing a linear algebra or game math library.
Sometimes you only need a few functions, like dot or cross product and don't want to deal with traits.
Perhaps you know the math, but the type system gets in your way?
This library is designed to be simple, generic and easy to build abstractions on top of.
If this is not what you looking for, here are some alternatives:
A good convention is to reexport the library in a vecmath
module in your library/executable.
By reexporting you can add new functions and send pull requests without breaking the code.
Besides, it is nicer to put custom math functions under the same name space,
even if those never will be added to the original vector math library.
Open up 'Cargo.toml' in a text editor and add the following:
[dependencies.vecmath]
version = "1.0.0"
Add the following to 'lib.rs':
extern crate vecmath;
mod math; // Use 'pub mod' if you want it to be visible outside library.
Create a new file 'math.rs' in your 'src/' directory. Open 'math.rs' in a text editor and type:
pub use multiply = vecmath::row_mat2x3_mul;
pub type Matrix2d = vecmath::Matrix2x3<f64>;
// etc.
You can add your own custom functions and rename the existing ones for your usage.
All methods are prefixed with a short name version.
Examples:
mat3x4_
a 3x4 matrix.
mat4_
a 4x4 matrix.
vec3_
a vector with 3 components.
col_mat4x3_
the matrix is treated as a matrix with column major
For simplicity, all methods should take a generic parameter with specific operations, e.g. <T: Add<T, Output = T>>
for addition.
In cases where extra methods are required, traits::Float
should be used instead.
All arguments are passed by value, so Copy
can be added as requirement when needed.
Inlining will remove the overhead.
This increases readability and is good enough for the usage of this library.