lineq/lib.rs
1//! Structs and methods for linear algebra.
2//!
3//! This crate provides 3 main types of structs that implement basic arithmetic operations
4//! like + and -, and also pervide useful methods:
5//!
6//! - Structs for handling vectors like [Vec2](crate::vec2::Vec2) and [Vec3](crate::vec3::Vec3).
7//! - Structs for handling arrays of vectors with different types of memory orginization, like
8//! [Vec3arr](crate::vec3arr::Vec3arr) and [Vec3box](crate::vec3arr::Vec3box), for fixed length
9//! arrays and boxed arrays respectively.
10//! - Structs for handling square matricies like [Mat22](crate::mat22::Mat22) and
11//! [Mat33](crate::mat33::Mat33).
12//!
13//! Vectors can be easily initialized and used:
14//! ```rust
15//! # extern crate lineq
16//! use lineq::vec3::Vec3;
17//! let a : Vec3 = Vec3::UP;
18//! let b : Vec3 = Vec3 { x: -1.0, y: 0.0, z: 0.0 };
19//! assert_eq!(a.cross(b),Vec3::IN);
20//! ```
21//!
22//! Arrays of vectors can be used to parallelize arithmetic:
23//! ```rust
24//! # extern crate lineq
25//! use lineq::vec3::Vec3;
26//! use lineq::vec3arr::Vec3arr;
27//! //using a and b from last example:
28//! # let a : Vec3 = Vec3::UP;
29//! # let b : Vec3 = Vec3::LEFT;
30//! let ab : Vec3arr = Vec3arr([a,b]);
31//! let cd : Vec3arr = Vec3arr([Vec3::DOWN,Vec3::RIGHT]);
32//! assert_eq!(ab + cd, Vec3arr([Vec3::ZERO,Vec3::ZERO]));
33//! ```
34//!
35//! Matricies are indexed like x1, y2, z3 ... where x, y, z
36//! are the rows and 1, 2, 3 are the columns:
37//! ```rust
38//! # extern crate lineq
39//! use lineq::vec3::Vec3;
40//! use lineq::mat33::Mat33;
41//! //using a and b from first example:
42//! # let a : Vec3 = Vec3::UP;
43//! # let b : Vec3 = Vec3::LEFT;
44//! let c : Vec3 = Vec3{ x: 1.0, y: -1.0, z: 2.0 };
45//! let m1 : Mat33 = Mat33::augment(a,b,c);
46//! let m2 : Mat33 = Mat33{
47//! x1: 0.0, x2: -1.0, x3: 1.0,
48//! y1: 1.0, y2: 0.0, y3: -1.0,
49//! z1: 0.0, z2: 0.0, z3: 2.0 }
50//! assert_eq!(m1,m2);
51//! ```
52
53#![feature(new_uninit)]
54#![feature(slice_ptr_get)]
55#![feature(test)]
56
57pub mod vec2;
58pub mod vec3;
59pub mod mat22;
60pub mod mat33;
61pub mod vec3arr;
62pub mod vec2arr;
63mod arrmacro;