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#![cfg_attr(feature = "derive_serdes", feature(cfg_eval))]
63
64pub use vek::approx;
65pub use vek::num_traits as num;
66pub use vek;
67
68pub mod data;
69pub mod geometry;
70pub mod algebra;
71
72mod fixed;
73mod traits;
74mod types;
75
76pub use self::fixed::*;
77pub use self::traits::*;
78pub use self::types::*;
79
80/// 0
81pub const COMPONENT_INDEX_X : usize = 0;
82/// 1
83pub const COMPONENT_INDEX_Y : usize = 1;
84/// 2
85pub const COMPONENT_INDEX_Z : usize = 2;
86/// 3
87pub const COMPONENT_INDEX_W : usize = 3;
88
89
90/// Convenience macro
91#[doc(hidden)]
92#[macro_export]
93macro_rules! show {
94  ($e:expr) => { println!("{}: {:?}", stringify!($e), $e); }
95}
96
97/// Convenience macro
98#[doc(hidden)]
99#[macro_export]
100macro_rules! display {
101  ($e:expr) => { println!("{}: {}", stringify!($e), $e); }
102}
103
104/// Print the sizes of some types
105pub fn report_sizes() {
106  use std::mem::size_of;
107  println!("report sizes...");
108  show!(size_of::<Vector2 <f32>>());
109  show!(size_of::<Vector3 <f32>>());
110  show!(size_of::<Vector4 <f32>>());
111  show!(size_of::<Matrix2 <f32>>());
112  show!(size_of::<Matrix3 <f32>>());
113  show!(size_of::<Rotation2 <f32>>());
114  show!(size_of::<Rotation3 <f32>>());
115  show!(size_of::<AffineMap <f32, Point3 <f32>, Point3 <f32>, Matrix3 <f32>>>());
116  show!(size_of::<AffineMap <f32, Point4 <f32>, Point4 <f32>, Matrix4 <f32>>>());
117  println!("...report sizes");
118}