cuadra/
lib.rs

1// cuadra
2//
3//! ## Layout
4//!
5//! Several primitives are defined for `Position`, `Size` and their combination
6//! as a `Zone`.
7//!
8//! Types have 8, 16, 32 and 64 bit sizes implementations, and they are limited
9//! to values of just half the range of an equivalent bit-size signed integer,
10//! leaving 1/4th of the range for positive values.
11//!
12//! Positions can have negative values, while Sizes can only be positive.
13//!
14//! For example, a [`Position8`] can hold values between `-64,-64` and `63,63`,
15//! while a [`Size16`] can have values of between `1,1` and `16_383,16_383`.
16//!
17//! The non-negative range from 0 to the clamped maximum is always 1/4th of the
18//! primitive's maximum.
19//! This allows to have a safety margin around which allows to move the biggest
20//! size to the furthest position, and still be able to represent all its points
21//! with the same inner bit-size.
22//!
23//! The following diagram shows the example range of values of a [`Position8`],
24//! around the inner centered square, with the outer safety margin around it,
25//! and the maximum positive clamped size filled with `+`.
26//! ```diagram
27//!       -128,127       0,127     127,127
28//!           .-----|-----|-----|-----ยท
29//!           |                       |
30//!           |  -64,63       63,63   |
31//!           |     .-----------.     --
32//!           |     |     |+++++|     |
33//!           |     |     |+++++|     |
34//!   -128,0 --     |----0,0----|     -- 127,0
35//!           |     |     |     |     |
36//!           |     |     |     |     |
37//!           |     .-----------.     --
38//!           |  -64,-64      63,-64  |
39//!           |                       |
40//!           .-----|-----|-----|-----.
41//!       -128,-128      0,-128    127,-128
42//! ```
43//
44
45#![warn(clippy::all)]
46#![cfg_attr(not(feature = "std"), no_std)]
47#![forbid(unsafe_code)]
48
49#[cfg(test)]
50mod tests;
51
52mod clamper;
53mod position;
54mod size;
55mod zone;
56
57pub use clamper::{Clamper16, Clamper32, Clamper64, Clamper8};
58pub use position::{Position16, Position32, Position64, Position8};
59pub use size::{Size16, Size32, Size64, Size8};
60pub use zone::{Zone16, Zone32, Zone64, Zone8};