primitives/
lib.rs

1//! The library provides the basic building blocks for creating games and regular applications. 
2//! It contains behavior definitions for game applications and basic structures.
3//! 
4//! The basic fundamental entity for graphical applications such as games is color. 
5//! This library contains sufficient functionality for working with color, including storage, 
6//! processing and conversion between different color spaces. 
7//! 
8//! It also provides support for multiple color schemes and contains the 
9//! OpenColor palette for the convenience and higher quality of your applications.
10
11
12#![doc(html_logo_url = "https://dudochkin-victor.github.io/assets/ux-primitives/logo.svg")]
13
14#![warn(missing_docs)]
15
16pub mod foundation;
17
18pub mod prelude;
19
20
21// /// A one-dimensional distance, with value represented by `T` and unit of measurement `Unit`.
22// ///
23// /// `T` can be any numeric type, for example a primitive type like `u64` or `f32`.
24// ///
25// /// `Unit` is not used in the representation of a `Length` value. It is used only at compile time
26// /// to ensure that a `Length` stored with one unit is converted explicitly before being used in an
27// /// expression that requires a different unit.  It may be a type without values, such as an empty
28// /// enum.
29// ///
30// /// You can multiply a `Length` by a `scale::Scale` to convert it from one unit to
31// /// another. See the [`Scale`] docs for an example.
32// ///
33// /// [`Scale`]: struct.Scale.html
34// #[repr(C)]
35// pub struct Length<T, Unit>(pub T, #[doc(hidden)] pub PhantomData<Unit>);
36
37// /// A 2d size tagged with a unit.
38// #[repr(C)]
39// pub struct Size2D<T, U> {
40//     /// The extent of the element in the `U` units along the `x` axis (usually horizontal).
41//     pub width: T,
42//     /// The extent of the element in the `U` units along the `y` axis (usually vertical).
43//     pub height: T,
44//     #[doc(hidden)]
45//     pub _unit: PhantomData<U>,
46// }
47
48// /// A 3d size tagged with a unit.
49// #[repr(C)]
50// pub struct Size3D<T, U> {
51//     /// The extent of the element in the `U` units along the `x` axis.
52//     pub width: T,
53//     /// The extent of the element in the `U` units along the `y` axis.
54//     pub height: T,
55//     /// The extent #![warn(missing_docs)]of the element in the `U` units along the `z` axis.
56//     pub depth: T,
57//     #[doc(hidden)]
58//     pub _unit: PhantomData<U>,
59// }
60
61// /// A 2d Rectangle optionally tagged with a unit.
62// ///
63// /// # Representation
64// ///
65// /// `Rect` is represented by an origin point and a size.
66// ///
67// /// See [`Box2D`] for a rectangle represented by two endpoints.
68// ///
69// /// # Empty rectangle
70// ///
71// /// A rectangle is considered empty (see [`is_empty`]) if any of the following is true:
72// /// - it's area is empty,
73// /// - it's area is negative (`size.x < 0` or `size.y < 0`),
74// /// - it contains NaNs.
75// ///
76// /// [`is_empty`]: #method.is_empty
77// /// [`Box2D`]: struct.Box2D.html
78// #[repr(C)]
79// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
80// #[cfg_attr(
81//     feature = "serde",
82//     serde(bound(serialize = "T: Serialize", deserialize = "T: Deserialize<'de>"))
83// )]
84// pub struct Rect<T, U> {
85//     pub origin: Point2D<T, U>,
86//     pub size: Size2D<T, U>,
87// }
88
89// /// A 2d axis aligned rectangle represented by its minimum and maximum coordinates.
90// ///
91// /// # Representation
92// ///
93// /// This struct is similar to [`Rect`], but stores rectangle as two endpoints
94// /// instead of origin point and size. Such representation has several advantages over
95// /// [`Rect`] representation:
96// /// - Several operations are more efficient with `Box2D`, including [`intersection`],
97// ///   [`union`], and point-in-rect.
98// /// - The representation is less susceptible to overflow. With [`Rect`], computation
99// ///   of second point can overflow for a large range of values of origin and size.
100// ///   However, with `Box2D`, computation of [`size`] cannot overflow if the coordinates
101// ///   are signed and the resulting size is unsigned.
102// ///
103// /// A known disadvantage of `Box2D` is that translating the rectangle requires translating
104// /// both points, whereas translating [`Rect`] only requires translating one point.
105// ///
106// /// # Empty box
107// ///
108// /// A box is considered empty (see [`is_empty`]) if any of the following is true:
109// /// - it's area is empty,
110// /// - it's area is negative (`min.x > max.x` or `min.y > max.y`),
111// /// - it contains NaNs.
112// ///
113// /// [`Rect`]: struct.Rect.html
114// /// [`intersection`]: #method.intersection
115// /// [`is_empty`]: #method.is_empty
116// /// [`union`]: #method.union
117// /// [`size`]: #method.size
118// #[repr(C)]
119// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
120// #[cfg_attr(
121//     feature = "serde",
122//     serde(bound(serialize = "T: Serialize", deserialize = "T: Deserialize<'de>"))
123// )]
124// pub struct Box2D<T, U> {
125//     pub min: Point2D<T, U>,
126//     pub max: Point2D<T, U>,
127// }
128
129// /// An axis aligned 3D box represented by its minimum and maximum coordinates.
130// #[repr(C)]
131// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
132// #[cfg_attr(
133//     feature = "serde",
134//     serde(bound(serialize = "T: Serialize", deserialize = "T: Deserialize<'de>"))
135// )]
136// pub struct Box3D<T, U> {
137//     pub min: Point3D<T, U>,
138//     pub max: Point3D<T, U>,
139// }
140
141// /// A group of 2D side offsets, which correspond to top/right/bottom/left for borders, padding,
142// /// and margins in CSS, optionally tagged with a unit.
143// #[repr(C)]
144// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
145// #[cfg_attr(
146//     feature = "serde",
147//     serde(bound(serialize = "T: Serialize", deserialize = "T: Deserialize<'de>"))
148// )]
149// pub struct SideOffsets2D<T, U> {
150//     pub top: T,
151//     pub right: T,
152//     pub bottom: T,
153//     pub left: T,
154//     #[doc(hidden)]
155//     pub _unit: PhantomData<U>,
156// }