Crate mdmath_core

Source
Expand description

§mdmath_core

Fundamental functionality and types, representation slices and tuples as vectors.

§Implemented Features

  • Vector:
    • Operations:
      • Dot product of two vectors.
      • Magnitude of the vector.
      • Normalizing the vector.
      • Projection on another vector.
      • Angle beetween two vectors.
      • Orthogonal checking between two vectors.
      • Dimension offset of the vector.
    • Mut/Unmut ref from slice and tuple.
    • Mut/Unmut iterators.

§Installation

Add to your example [dependencies] in Cargo.toml configuration file:

mdmath_core = { workspace = true }

§Examples

§Dot product of two vectors

  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 );

§Magnitude of the vector

  let vec_a = [ 1.0, 2.0, 3.0 ];
  let result = mdmath_core::vector::mag2( &vec_a );
  assert_ulps_eq!( result, 14.0 );

§Normalizing the vector

  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 );

§Projection on another vector

  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 );

§Angle beetween two vectors

  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 );

§Orthogonal checking between two vectors

  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" );

Modules§

exposed
Exposed namespace of the module.
orphan
Orphan namespace of the module.
own
Own namespace of the module.
plain
Strides for plain multidemnsional space. Provides functionality for converting multidimensional indices into flat offsets, particularly useful for operations involving multidimensional arrays or grids.
prelude
Prelude to use essentials: use my_module::prelude::*.
traits
General traits, not necessarily special for math.
vector
Univeral vector. Provides traits and implementations for working with vectors and collections of scalars. This module is useful for operations that require fixed-size arrays and compile-time length information.

Traits§

Collection
A trait for collections of scalars.
ConstLength
A trait implemented for entities with known length at compile-time.
ToRef
Trait for converting a value, reference, or mutable reference to an immutable reference.
ToValue
Trait for obtaining a value from a reference or mutable reference.
VectorIter
Trait to get iterator over elements of a vector. Should be implemented even for scalars.
VectorIterMut
Trait to get iterator over elements of a vector.
VectorIterator
Trait that encapsulates an vector elements iterator with specific characteristics and implemetning CloneDyn.
VectorIteratorRef
Trait that encapsulates an vector elements iterator with specific characteristics and implemetning CloneDyn.
VectorMut
A trait for accessing a mutable reference to a fixed-size array from a collection.
VectorRef
A trait for accessing a reference to a fixed-size array from a collection.
VectorWithLength
A trait indicate that entity in case of referencing it can be interpreted as such having specified length LEN.
VectorWithLengthMut
A trait indicate that entity in case of mutable referencing it can be interpreted as such having specified length LEN.