Skip to content

Commit

Permalink
- update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
polymonster committed Jan 28, 2024
1 parent 7f58eff commit 537c1dd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ lhs_scalar_vec_ops = []
casts = []
short_types = []
serde = ["dep:serde", "serde_json"]
hash = []
default = ["short_hand_constructors", "lhs_scalar_vec_ops", "casts", "short_types"]

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

Maths is a linear algebra library which aims to be ergonmic and fun to use for gamedev and graphics. If you like writing shaders you should feel right at home. In addition to the usual implementation of vectors, matrices and quaternions it includes a comprehensive collection of utility functions, vector swizzling, intersection tests, point tests, distance functions, trig functions, graphs and signal processing functions.

Most features of the crate are enabled by default, you can choose to opt out if you wish, `serde` support is optional and can be enabled with:
Most features of the crate are enabled by default, you can choose to opt out if you wish. `serde` and `hash` support is optional and disabled by default they can be enabled with:

```text
features = ["serde"]
features = ["serde", "hash"]
```

Most of this code was ported from my C++ [maths library](https://github.com/polymonster/maths), there is a live [WebGL demo](https://www.polymonster.co.uk/pmtech/examples/maths_functions.html) which showcases a lot of the features in an interactive way and was used to generate test data and verify the functions work correctly.
Expand Down
1 change: 1 addition & 0 deletions src/mat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ macro_rules! mat_impl {
$ColVecN:ident { $($col_field:ident, $col_field_index:expr),* } ) => {

#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature="hash", derive(Hash))]
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct $MatN<T> {
Expand Down
1 change: 1 addition & 0 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ macro_rules! vec_impl {
($VecN:ident { $($field:ident, $field_index:expr),* }, $len:expr, $module:ident) => {

#[cfg_attr(feature="serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature="hash", derive(Hash))]
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct $VecN<T> {
Expand Down
27 changes: 27 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6089,4 +6089,31 @@ fn test_serde() {
assert_eq!("{\"m\":[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0]}", serde_m);
assert_eq!("{\"x\":1.0,\"y\":1.0,\"z\":1.0,\"w\":1.0}", serde_v);
assert_eq!("{\"x\":0.0,\"y\":0.0,\"z\":0.0,\"w\":1.0}", serde_q);
}

#[cfg(feature = "hash")]
#[test]
fn test_hash() {
use std::collections::HashMap;

// integer vector
let vi = vec2i(5, 10);
let mut vmap = HashMap::new();
vmap.insert(
vi,
"vec2i(5, 10)".to_string()
);
assert_eq!("vec2i(5, 10)", vmap[&vi]);

// integer matrix
let mi = Mat2::<i32>::from((
vec2i(6, 11),
vec2i(7, 12),
));
let mut mmap = HashMap::new();
mmap.insert(
mi,
"[vec2i(6, 11), vec2i(7, 12)]".to_string()
);
assert_eq!("[vec2i(6, 11), vec2i(7, 12)]", mmap[&mi]);
}

0 comments on commit 537c1dd

Please sign in to comment.