1 // Copyright 2013 The Servo Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9 
10 #![cfg_attr(not(test), no_std)]
11 
12 //! A collection of strongly typed math tools for computer graphics with an inclination
13 //! towards 2d graphics and layout.
14 //!
15 //! All types are generic over the scalar type of their component (`f32`, `i32`, etc.),
16 //! and tagged with a generic Unit parameter which is useful to prevent mixing
17 //! values from different spaces. For example it should not be legal to translate
18 //! a screen-space position by a world-space vector and this can be expressed using
19 //! the generic Unit parameter.
20 //!
21 //! This unit system is not mandatory and all structures have an alias
22 //! with the default unit: `UnknownUnit`.
23 //! for example ```default::Point2D<T>``` is equivalent to ```Point2D<T, UnknownUnit>```.
24 //! Client code typically creates a set of aliases for each type and doesn't need
25 //! to deal with the specifics of typed units further. For example:
26 //!
27 //! ```rust
28 //! use euclid::*;
29 //! pub struct ScreenSpace;
30 //! pub type ScreenPoint = Point2D<f32, ScreenSpace>;
31 //! pub type ScreenSize = Size2D<f32, ScreenSpace>;
32 //! pub struct WorldSpace;
33 //! pub type WorldPoint = Point3D<f32, WorldSpace>;
34 //! pub type ProjectionMatrix = Transform3D<f32, WorldSpace, ScreenSpace>;
35 //! // etc...
36 //! ```
37 //!
38 //! All euclid types are marked `#[repr(C)]` in order to facilitate exposing them to
39 //! foreign function interfaces (provided the underlying scalar type is also `repr(C)`).
40 //!
41 #![deny(unconditional_recursion)]
42 
43 #[cfg(feature = "serde")]
44 #[macro_use]
45 extern crate serde;
46 
47 #[cfg(feature = "mint")]
48 pub extern crate mint;
49 extern crate num_traits;
50 #[cfg(test)]
51 use std as core;
52 
53 pub use angle::Angle;
54 pub use box2d::Box2D;
55 pub use length::Length;
56 pub use scale::Scale;
57 pub use transform2d::Transform2D;
58 pub use transform3d::Transform3D;
59 pub use point::{Point2D, Point3D, point2, point3};
60 pub use vector::{Vector2D, Vector3D, vec2, vec3};
61 pub use vector::{BoolVector2D, BoolVector3D, bvec2, bvec3};
62 pub use homogen::HomogeneousVector;
63 pub use nonempty::NonEmpty;
64 
65 pub use rect::{rect, Rect};
66 pub use rigid::{RigidTransform3D};
67 pub use box3d::{box3d, Box3D};
68 pub use translation::{Translation2D, Translation3D};
69 pub use rotation::{Rotation2D, Rotation3D};
70 pub use side_offsets::SideOffsets2D;
71 pub use size::{Size2D, Size3D, size2, size3};
72 pub use trig::Trig;
73 
74 #[macro_use]
75 mod macros;
76 
77 mod angle;
78 pub mod approxeq;
79 pub mod approxord;
80 mod box2d;
81 mod homogen;
82 pub mod num;
83 mod length;
84 mod point;
85 mod rect;
86 mod rigid;
87 mod rotation;
88 mod scale;
89 mod side_offsets;
90 mod size;
91 mod transform2d;
92 mod transform3d;
93 mod translation;
94 mod trig;
95 mod vector;
96 mod box3d;
97 mod nonempty;
98 
99 /// The default unit.
100 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
101 pub struct UnknownUnit;
102 
103 pub mod default {
104     //! A set of aliases for all types, tagged with the default unknown unit.
105 
106     use super::UnknownUnit;
107     pub type Length<T> = super::Length<T, UnknownUnit>;
108     pub type Point2D<T> = super::Point2D<T, UnknownUnit>;
109     pub type Point3D<T> = super::Point3D<T, UnknownUnit>;
110     pub type Vector2D<T> = super::Vector2D<T, UnknownUnit>;
111     pub type Vector3D<T> = super::Vector3D<T, UnknownUnit>;
112     pub type HomogeneousVector<T> = super::HomogeneousVector<T, UnknownUnit>;
113     pub type Size2D<T> = super::Size2D<T, UnknownUnit>;
114     pub type Size3D<T> = super::Size3D<T, UnknownUnit>;
115     pub type Rect<T> = super::Rect<T, UnknownUnit>;
116     pub type Box2D<T> = super::Box2D<T, UnknownUnit>;
117     pub type Box3D<T> = super::Box3D<T, UnknownUnit>;
118     pub type SideOffsets2D<T> = super::SideOffsets2D<T, UnknownUnit>;
119     pub type Transform2D<T> = super::Transform2D<T, UnknownUnit, UnknownUnit>;
120     pub type Transform3D<T> = super::Transform3D<T, UnknownUnit, UnknownUnit>;
121     pub type Rotation2D<T> = super::Rotation2D<T, UnknownUnit, UnknownUnit>;
122     pub type Rotation3D<T> = super::Rotation3D<T, UnknownUnit, UnknownUnit>;
123     pub type Translation2D<T> = super::Translation2D<T, UnknownUnit, UnknownUnit>;
124     pub type Translation3D<T> = super::Translation3D<T, UnknownUnit, UnknownUnit>;
125     pub type Scale<T> = super::Scale<T, UnknownUnit, UnknownUnit>;
126     pub type RigidTransform3D<T> = super::RigidTransform3D<T, UnknownUnit, UnknownUnit>;
127 }
128