Crate geo_nd[−][src]
Expand description
Geometry library
This library provides for N-dimensional geometrical objects, particularly Vectors, Matrix, Quaternion operations.
The underlying type is [Num; N], so the data may be shared simply with other libraries, including OpenGL.
The library mirrors the operation of ‘glm’ in some sense.
The desire for the library is that it does not undergo much development; it provides a stable and simple basis for operations that are common mathematical operations, with no aim for it to grow into a larger linear algebra library.
The library operates on arrays of elements that support the
Num
trait, which requires basic arithmetic operations, copy,
clone, debug and display; some functions further require the
Float
trait, which also requires operations such as sqrt,
sin/cos, etc.
The library does not expose any types: all of the operations it supports are provided through functions.
Caveats
The functions in the library use const generics, but as const generic
evaulations are currently unstable it requires more consts than should
be required. For example, to create an identity square matrix the
matrix::identity
function has the generic signature <V:Num, const D2:usize, const D:usize>
. The value of D2
must equal D*D
. The
function returns [V; D2]
.
Ideally the function should just take D as a const generic argument
and the type would be [V;D*D]
, but that is unstable (and there are
some other issues).
Additionally, the inference of a type for V
is sometimes required to
be forced, so there may be a small amount of turbofish notation such
as identity2::<f32>()
.
Basic operation
use geo_nd::vector;
let y = [0., 1.];
let x = [1., 0.];
assert_eq!( vector::dot(&x, &y), 0., "Dot product of X and Y axis vectors is zero");
let xy = vector::add(x,&y,2.);
assert_eq!( xy, [1., 2.], "x + 2*y");
assert_eq!( vector::length_sq(&xy), (5.), "|x + 2*y|^2 = 5");
assert_eq!( vector::length(&xy), (5.0f64).sqrt(), "|x + 2*y| = sqrt(5)");
Modules
Structs
Traits
The Float trait is required for matrix or vector elements which have a float aspect, such as sqrt
.
This is an experimental trait - it bundles together a Vec2 and a Mat2.
The Geometry3D trait supplies a framework for implementing 3D vector and matrix operations, and should also include the quaternion type.
The Num trait is required for matrix or vector elements; it is not a float, and so some of the matrix and vector operations can operate on integer types such as i32, i64 and isize
The Quaternion trait describes a 4-dimensional vector of Float type.
The SqMatrix trait describes an N-dimensional square matrix of Float type that operates on a Vector.
This is probably a temporary trait used until SIMD supports Geometry3D and Geometry2D