hexga_math/lib.rs
1//! # A Math library that contains
2//!
3//! ## N Dimension stuff and Array Programming
4//!
5//! This crate define N dimensional math stuff (2d, 3d, 4d, ... nd) like vector/point of any type (float, int, uint, or even user defined) :
6//!
7//! - [`Vector`] (fixed size array wrapper)
8//! - [`Rectangle`]
9//! - [`Grid`]
10//! - [`Matrix`]
11//!
12//! The *same* common functions such as [`min`], [`max`], [`mix`],
13//! [`abs`], and [`clamp`] work for
14//! - primitive values(`u32`, `i32`, `f32`, `bool`, ...)
15//! - and on composite types (`Array`, `Vector`, `Color`, `Rectangle`, `Matrix`, `Grid`, ...) that implement the [`Map`] / [`MapWith`] / [`MapIntern`] / [`MapInternWith`] traits.
16//!
17//! Any external type implementing these traits automatically gains support for these common functions.
18//!
19//! ## Useful type like
20//!
21//! - [`Angle`]
22//! - [`Time`],
23//!
24//! ## Generic Casting trait
25//! The crate also provide generic traits for casting with the same behavior as the [as keyword](https://practice.course.rs/type-conversions/as.html) :
26//! - [`CastInto`], [`CastFrom`],
27//!
28//! ## Generic Remapping trait
29//!
30//! Similar traits for casting remapping the range of an primitive to another primitive range also exist :
31//! - [`CastRangeInto`], [`CastRangeFrom`]
32//!
33//! ## Quick start with the prelude
34//!
35//! There are some quick typedef in the prelude :
36//!
37//! - [`int`], [`uint`] and [`float`] : The default primitive precision used in the typedef. (can be change with the feature flags)
38//! - [`Point2`], [`Point3`], [`Point4`] for Vector of [`int`],
39//! - [`Vec2`], [`Vec3`], [`Vec4`] for Vector of [`float`],
40//! - [`Rect2`], [`Rect3`], [`Rect4`] for Rectangle of [`float`],
41//! - [`Rect2i`], [`Rect3i`], [`Rect4i`] for Rectangle of [`int`] (`P` for point),
42//! - [`Mat2`], [`Mat3`], [`Mat4`] for Matrix of [`float`], and [`Mat2i`], [`Mat3i`], [`Mat4i`] use [`int`],
43//! - [`Grid2`], [`Grid3`], [`Grid3`] can only be indexed by `Point` by default.
44//!
45//! ## More advanced type
46//!
47//! If you need more control about the precision, each type have another more generic base type :
48//!
49//! - [`Grid`] type uses a `Point` for the indexing precision, but that can be changed by using with the [`hexga_math::grid::GridBase`] type.
50//! - [`Angle`] and [`Time`] use a [`float`] precision that can be changed using [`AngleOf`] and [`TimeOf`]
51
52#![allow(unused_imports)]
53#![feature(formatting_options)]
54// For grid view, to display aligned value they need to be fomatted in a temporary formatter
55//#![feature(try_trait_v2, try_trait_v2_residual)] // TryMap
56#![feature(array_try_map)] // array try_map
57
58use hexga_core::cfg::*;
59use hexga_core::prelude::*;
60use rayon::prelude::*;
61use std::cmp::Ordering;
62use std::hash::{Hash, Hasher};
63use std::iter::{ExactSizeIterator, FusedIterator};
64use std::marker::PhantomData;
65use std::ops::*;
66use std::{
67 fmt,
68 num::{Saturating, Wrapping},
69};
70
71#[cfg(feature = "serde")]
72use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor, ser::SerializeStruct};
73
74pub use hexga_typedef as typedef;
75mod utils;
76pub use utils::*;
77pub mod array;
78//pub mod bijection;
79pub mod convert;
80pub mod derive;
81mod geometry;
82pub mod map_on;
83pub mod number;
84pub mod range;
85pub mod unit;
86pub use geometry::*;
87
88// For macro
89#[doc(hidden)]
90pub use hexga_core;
91
92// For macro
93#[cfg(feature = "serde")]
94#[doc(hidden)]
95pub use serde;
96
97use prelude::*;
98pub mod prelude
99{
100 pub use super::array::*;
101 //pub use super::bijection::prelude::*;
102 pub use super::convert::*;
103 pub use super::derive::prelude::*;
104 pub use super::geometry::prelude::*;
105 pub use super::map_on::*;
106 pub use super::number::*;
107 pub use super::range::*;
108 pub use super::typedef::*;
109 pub use super::unit::*;
110 pub use super::utils::prelude::*;
111}