Crates.io | mdmath_core |
lib.rs | mdmath_core |
version | 0.2.0 |
source | src |
created_at | 2024-09-17 09:37:49.49271 |
updated_at | 2024-10-28 11:01:38.191572 |
description | Multidimensional math, fundamental functionality and types. |
homepage | |
repository | https://github.com/Wandalen/cg_tools |
max_upload_size | |
id | 1377273 |
size | 117,067 |
Fundamental functionality and types, representation slices and tuples as vectors.
Add to your example [dependencies]
in Cargo.toml
configuration file:
mdmath_core = { workspace = true }
let vec_a = [ 1.0, 2.0, 3.0 ];
let vec_b = [ 4.0, 5.0, 6.0 ];
let result = mdmath_core::vector::dot( &vec_a, &vec_b );
assert_eq!( result, 32.0 );
let vec_a = [ 1.0, 2.0, 3.0 ];
let result = mdmath_core::vector::mag2( &vec_a );
assert_ulps_eq!( result, 14.0 );
let vec_a = [ 3.0, 4.0 ];
let mut result = vec_a.clone();
mdmath_core::vector::normalize( &mut result, &vec_a );
let expected = [ 0.6, 0.8 ];
assert_eq!( result, expected );
let mut vec_a = [ 1.0, 2.0, 3.0 ];
let vec_b = [ 4.0, 5.0, 6.0 ];
mdmath_core::vector::project_on( &mut vec_a, &vec_b );
let expected = [ 1.6623376623376624, 2.077922077922078, 2.4935064935064934 ];
assert_eq!( vec_a, expected );
let vec_a = [ 1.0, 0.0 ];
let vec_b = [ 0.0, 1.0 ];
let result = mdmath_core::vector::angle( &vec_a, &vec_b );
assert_ulps_eq!( result, std::f32::consts::FRAC_PI_2 );
let vec_a = [ 1.0, 0.0 ];
let vec_b = [ 0.0, 1.0 ];
assert!( mdmath_core::vector::is_orthogonal( &vec_a, &vec_b ), "Orthogonal test failed for orthogonal vectors" );