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
43pub use crate::angle::Angle;
44pub use crate::box2d::Box2D;
45pub use crate::homogen::HomogeneousVector;
46pub use crate::length::Length;
47pub use crate::point::{point2, point3, Point2D, Point3D};
48pub use crate::scale::Scale;
49pub use crate::transform2d::Transform2D;
50pub use crate::transform3d::Transform3D;
51pub use crate::vector::{bvec2, bvec3, BoolVector2D, BoolVector3D};
52pub use crate::vector::{vec2, vec3, Vector2D, Vector3D};
53
54pub use crate::box3d::{box3d, Box3D};
55pub use crate::rect::{rect, Rect};
56pub use crate::rigid::RigidTransform3D;
57pub use crate::rotation::{Rotation2D, Rotation3D};
58pub use crate::side_offsets::SideOffsets2D;
59pub use crate::size::{size2, size3, Size2D, Size3D};
60pub use crate::translation::{Translation2D, Translation3D};
61pub use crate::trig::Trig;
62
63#[macro_use]
64mod macros;
65
66mod angle;
67pub mod approxeq;
68pub mod approxord;
69mod box2d;
70mod box3d;
71mod homogen;
72mod length;
73pub mod num;
74mod point;
75mod rect;
76mod rigid;
77mod rotation;
78mod scale;
79mod side_offsets;
80mod size;
81mod transform2d;
82mod transform3d;
83mod translation;
84mod trig;
85mod vector;
86
87/// The default unit.
88#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
89pub struct UnknownUnit;
90
91pub mod default {
92 //! A set of aliases for all types, tagged with the default unknown unit.
93
94 use super::UnknownUnit;
95 pub type Length<T> = super::Length<T, UnknownUnit>;
96 pub type Point2D<T> = super::Point2D<T, UnknownUnit>;
97 pub type Point3D<T> = super::Point3D<T, UnknownUnit>;
98 pub type Vector2D<T> = super::Vector2D<T, UnknownUnit>;
99 pub type Vector3D<T> = super::Vector3D<T, UnknownUnit>;
100 pub type HomogeneousVector<T> = super::HomogeneousVector<T, UnknownUnit>;
101 pub type Size2D<T> = super::Size2D<T, UnknownUnit>;
102 pub type Size3D<T> = super::Size3D<T, UnknownUnit>;
103 pub type Rect<T> = super::Rect<T, UnknownUnit>;
104 pub type Box2D<T> = super::Box2D<T, UnknownUnit>;
105 pub type Box3D<T> = super::Box3D<T, UnknownUnit>;
106 pub type SideOffsets2D<T> = super::SideOffsets2D<T, UnknownUnit>;
107 pub type Transform2D<T> = super::Transform2D<T, UnknownUnit, UnknownUnit>;
108 pub type Transform3D<T> = super::Transform3D<T, UnknownUnit, UnknownUnit>;
109 pub type Rotation2D<T> = super::Rotation2D<T, UnknownUnit, UnknownUnit>;
110 pub type Rotation3D<T> = super::Rotation3D<T, UnknownUnit, UnknownUnit>;
111 pub type Translation2D<T> = super::Translation2D<T, UnknownUnit, UnknownUnit>;
112 pub type Translation3D<T> = super::Translation3D<T, UnknownUnit, UnknownUnit>;
113 pub type Scale<T> = super::Scale<T, UnknownUnit, UnknownUnit>;
114 pub type RigidTransform3D<T> = super::RigidTransform3D<T, UnknownUnit, UnknownUnit>;
115}
116