Skip to main content

math_utils/
lib.rs

1//! Math types and traits
2//!
3//! ## Scalars
4//!
5//! - [`Positive`]
6//! - [`NonNegative`]
7//! - [`NonZero`]
8//! - [`Normalized`]
9//! - [`NormalSigned`]
10//! - [`Unit`]
11//! - [`Deg`]
12//! - [`Rad`]
13//! - [`Turn`]
14//! - [`AngleWrapped`]
15//! - [`AngleWrappedSigned`]
16//!
17//! ## Vectors & points
18//!
19//! - [`Vector2`]
20//! - [`Vector3`]
21//! - [`Vector4`]
22//! - [`Point2`]
23//! - [`Point3`]
24//! - [`Point4`]
25//! - [`Unit2`]
26//! - [`Unit3`]
27//! - [`Unit4`]
28//! - [`NonZero2`]
29//! - [`NonZero3`]
30//! - [`NonZero4`]
31//!
32//! ## Matrices & linear transformations
33//!
34//! Matrices are *column-major* for SIMD efficiency.
35//!
36//! - [`Angles3`]
37//! - [`Matrix2`]
38//! - [`Matrix3`]
39//! - [`Matrix4`]
40//! - [`LinearIso`]
41//! - [`LinearAuto`]
42//! - [`Rotation2`]
43//! - [`Rotation3`]
44//! - [`Quaternion`]
45//! - [`Versor`]
46//!
47//! ## Affine transformations and frames
48//!
49//! - [`Pose3`]
50//! - [`AffineMap`]
51//! - [`Affinity`]
52//! - [`Projectivity`]
53//! - [`frame::Line2`]
54//! - [`frame::Plane2`]
55//! - [`frame::Line3`]
56//! - [`frame::Plane3`]
57//! - [`frame::Space3`]
58
59#![feature(decl_macro)]
60#![feature(stmt_expr_attributes)]
61#![cfg_attr(test, feature(test))]
62
63pub use vek::approx;
64pub use vek::num_traits as num;
65pub use vek;
66
67pub mod data;
68pub mod geometry;
69pub mod algebra;
70
71mod fixed;
72mod traits;
73mod types;
74
75pub use self::fixed::*;
76pub use self::traits::*;
77pub use self::types::*;
78
79/// 0
80pub const COMPONENT_INDEX_X : usize = 0;
81/// 1
82pub const COMPONENT_INDEX_Y : usize = 1;
83/// 2
84pub const COMPONENT_INDEX_Z : usize = 2;
85/// 3
86pub const COMPONENT_INDEX_W : usize = 3;
87
88
89/// Convenience macro
90#[doc(hidden)]
91#[macro_export]
92macro_rules! show {
93  ($e:expr) => { println!("{}: {:?}", stringify!($e), $e); }
94}
95
96/// Convenience macro
97#[doc(hidden)]
98#[macro_export]
99macro_rules! display {
100  ($e:expr) => { println!("{}: {}", stringify!($e), $e); }
101}
102
103/// Print the sizes of some types
104pub fn report_sizes() {
105  use std::mem::size_of;
106  println!("report sizes...");
107  show!(size_of::<Vector2 <f32>>());
108  show!(size_of::<Vector3 <f32>>());
109  show!(size_of::<Vector4 <f32>>());
110  show!(size_of::<Matrix2 <f32>>());
111  show!(size_of::<Matrix3 <f32>>());
112  show!(size_of::<Rotation2 <f32>>());
113  show!(size_of::<Rotation3 <f32>>());
114  show!(size_of::<AffineMap <f32, Point3 <f32>, Point3 <f32>, Matrix3 <f32>>>());
115  show!(size_of::<AffineMap <f32, Point4 <f32>, Point4 <f32>, Matrix4 <f32>>>());
116  println!("...report sizes");
117}