euclid/
lib.rs

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