rs_math3d/
lib.rs

1// Copyright 2020-Present (c) Raja Lehtihet & Wael El Oraiby
2//
3// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are met:
5//
6// 1. Redistributions of source code must retain the above copyright notice,
7// this list of conditions and the following disclaimer.
8//
9// 2. Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12//
13// 3. Neither the name of the copyright holder nor the names of its contributors
14// may be used to endorse or promote products derived from this software without
15// specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27// POSSIBILITY OF SUCH DAMAGE.
28
29#![no_std]
30#![allow(unused_imports)]
31pub mod basis;
32pub mod matrix;
33pub mod primitives;
34pub mod quaternion;
35pub mod queries;
36pub mod scalar;
37pub mod transforms;
38pub mod vector;
39
40pub use basis::*;
41pub use matrix::{Matrix2, Matrix3, Matrix4};
42pub use primitives::*;
43pub use quaternion::Quat;
44pub use queries::*;
45pub use scalar::{FloatScalar, Scalar};
46pub use transforms::*;
47pub use vector::{
48    CrossProduct, FloatVector, Swizzle2, Swizzle3, Vector, Vector2, Vector3, Vector4,
49};
50
51pub type Color4b = Vector4<u8>;
52
53pub type Vec2i = Vector2<i32>;
54pub type Vec3i = Vector3<i32>;
55pub type Vec4i = Vector4<i32>;
56
57pub type Vec2f = Vector2<f32>;
58pub type Vec3f = Vector3<f32>;
59pub type Vec4f = Vector4<f32>;
60
61pub type Vec2d = Vector2<f64>;
62pub type Vec3d = Vector3<f64>;
63pub type Vec4d = Vector4<f64>;
64
65pub type Quatf = Quat<f32>;
66pub type Quatd = Quat<f64>;
67
68pub type Mat2f = Matrix2<f32>;
69pub type Mat3f = Matrix3<f32>;
70pub type Mat4f = Matrix4<f32>;
71
72pub type Mat2d = Matrix2<f64>;
73pub type Mat3d = Matrix3<f64>;
74pub type Mat4d = Matrix4<f64>;
75
76pub type Recti = Rect<i32>;
77pub type Rectf = Rect<f32>;
78pub type Rectd = Rect<f64>;
79
80pub type Dimensioni = Dimension<i32>;
81pub type Dimensionf = Dimension<f32>;
82
83pub type Line2f = Line<f32, Vec2f>;
84pub type Line2d = Line<f64, Vec2d>;
85pub type Line3f = Line<f32, Vec3f>;
86pub type Line3d = Line<f64, Vec3d>;
87
88pub type Segment2f = Segment<f32, Vec2f>;
89pub type Segment2d = Segment<f64, Vec2d>;
90pub type Segment3f = Segment<f32, Vec3f>;
91pub type Segment3d = Segment<f64, Vec3d>;
92
93pub type Planef = Plane<f32>;
94pub type Planed = Plane<f64>;
95
96pub type Ray3f = Ray<f32, Vec3f>;
97pub type Ray3d = Ray<f64, Vec3d>;
98
99pub type Box3f = Box3<f32>;
100pub type Box3d = Box3<f64>;
101
102pub type Basisf = Basis<f32>;
103pub type Basisd = Basis<f64>;
104
105pub type ParametricPlanef = ParametricPlane<f32>;
106pub type ParametricPlaned = ParametricPlane<f64>;
107
108pub fn color4b(r: u8, g: u8, b: u8, a: u8) -> Color4b {
109    Color4b {
110        x: r,
111        y: g,
112        z: b,
113        w: a,
114    }
115}
116
117#[cfg(feature = "fixedpoint")]
118mod fixedpoint {
119    use super::*;
120    pub use scalar::{Hx, Lx};
121
122    pub type Vec2x = Vector2<Lx>;
123    pub type Vec3x = Vector3<Lx>;
124    pub type Vec4x = Vector4<Lx>;
125
126    pub type Vec2X = Vector2<Hx>;
127    pub type Vec3X = Vector3<Hx>;
128    pub type Vec4X = Vector4<Hx>;
129
130    pub type Quatx = Quat<Lx>;
131    pub type QuatX = Quat<Hx>;
132
133    pub type Mat2x = Matrix2<Lx>;
134    pub type Mat3x = Matrix3<Lx>;
135    pub type Mat4x = Matrix4<Lx>;
136
137    pub type Mat2X = Matrix2<Hx>;
138    pub type Mat3X = Matrix3<Hx>;
139    pub type Mat4X = Matrix4<Hx>;
140
141    pub type Rectx = Rect<Lx>;
142    pub type RectX = Rect<Hx>;
143
144    pub type Dimensionx = Dimension<Lx>;
145    pub type DimensionX = Dimension<Hx>;
146
147    pub type Line2x = Line<Lx, Vec2x>;
148    pub type Line2X = Line<Hx, Vec2X>;
149    pub type Line3x = Line<Lx, Vec3x>;
150    pub type Line3X = Line<Hx, Vec3X>;
151
152    pub type Segment2x = Segment<Lx, Vec2x>;
153    pub type Segment2X = Segment<Hx, Vec2X>;
154    pub type Segment3x = Segment<Lx, Vec3x>;
155    pub type Segment3X = Segment<Hx, Vec3X>;
156
157    pub type Planex = Plane<Lx>;
158    pub type PlaneX = Plane<Hx>;
159
160    pub type Ray3x = Ray<Lx, Vec3f>;
161    pub type Ray3X = Ray<Hx, Vec3X>;
162
163    pub type Box3x = Box3<Lx>;
164    pub type Box3X = Box3<Hx>;
165}
166
167#[cfg(feature = "fixedpoint")]
168pub use fixedpoint::*;