Skip to main content

hisab/
lib.rs

1//! # Hisab
2//!
3//! حساب (Arabic: calculation, reckoning) — Higher mathematics library for the AGNOS ecosystem.
4//!
5//! Provides typed mathematical operations — linear algebra, geometry, calculus,
6//! and numerical methods — built on [glam](https://docs.rs/glam).
7//!
8//! ## Feature flags
9//!
10//! | Feature | Default | Description |
11//! |---------|---------|-------------|
12//! | `transforms` | yes | 2D/3D transforms, projections, slerp, lerp, glam re-exports |
13//! | `geo` | yes | Primitives, intersections, BVH, k-d tree, quadtree, octree, spatial hash, GJK/EPA |
14//! | `calc` | yes | Differentiation, integration, Bezier 2D/3D, splines, easing, Gauss-Legendre |
15//! | `num` | yes | Root finding, LU/Cholesky/QR/SVD, FFT, optimization, ODE solvers |
16//! | `autodiff` | no | Forward-mode automatic differentiation (dual numbers) |
17//! | `interval` | no | Interval arithmetic for verified numerics |
18//! | `symbolic` | no | Symbolic expression tree with differentiation and simplification |
19//! | `tensor` | no | N-dimensional dense tensor type |
20//! | `parallel` | no | Rayon-powered parallel batch operations |
21//! | `ai` | no | Daimon/hoosh AI client (requires network deps) |
22//! | `logging` | no | Structured logging via tracing-subscriber |
23//! | `full` | — | Enables all features |
24
25pub mod error;
26pub use error::HisabError;
27
28#[cfg(feature = "ai")]
29pub use error::DaimonError;
30
31/// Convenience alias for `Result<T, HisabError>`.
32pub type Result<T> = std::result::Result<T, HisabError>;
33
34/// Default tolerance for f32 comparisons.
35pub const EPSILON_F32: f32 = 1e-7;
36
37/// Default tolerance for f64 comparisons.
38pub const EPSILON_F64: f64 = 1e-12;
39
40#[cfg(feature = "transforms")]
41pub mod transforms;
42
43#[cfg(feature = "geo")]
44pub mod geo;
45
46#[cfg(feature = "calc")]
47pub mod calc;
48
49#[cfg(feature = "num")]
50pub mod num;
51
52#[cfg(feature = "autodiff")]
53pub mod autodiff;
54
55#[cfg(feature = "interval")]
56pub mod interval;
57
58#[cfg(feature = "symbolic")]
59pub mod symbolic;
60
61#[cfg(feature = "tensor")]
62pub mod tensor;
63
64#[cfg(feature = "parallel")]
65pub mod parallel;
66
67#[cfg(feature = "ai")]
68pub mod ai;
69
70#[cfg(feature = "logging")]
71pub mod logging;
72
73// ---------------------------------------------------------------------------
74// Convenience re-exports
75// ---------------------------------------------------------------------------
76
77#[cfg(feature = "transforms")]
78pub use transforms::{EulerOrder, Transform2D, Transform3D};
79
80// f32 types
81#[cfg(feature = "transforms")]
82pub use glam::{Mat3, Mat4, Quat, Vec2, Vec3, Vec4};
83
84// f64 types
85#[cfg(feature = "transforms")]
86pub use glam::{DMat3, DMat4, DQuat, DVec2, DVec3, DVec4};
87
88#[cfg(feature = "geo")]
89pub use geo::{
90    Aabb, Bvh, Capsule, ContactConstraint, ContactEdge, ConvexDecomposition, ConvexHull3D,
91    ConvexPolygon, ConvexSupport, ConvexSupport3D, Frustum, HalfEdge, HalfEdgeMesh, Island, KdTree,
92    Line, Obb, Octree, Penetration3D, Plane, Quadtree, Ray, Rect, Segment, SpatialHash, Sphere,
93    TriMesh, Triangle,
94};
95
96#[cfg(feature = "num")]
97pub use num::{Complex, CsrMatrix, DenseMatrix, EigenDecomposition, OptResult, Pcg32, Svd};
98
99#[cfg(feature = "autodiff")]
100pub use autodiff::{Dual, Tape, Var};
101
102#[cfg(feature = "interval")]
103pub use interval::Interval;
104
105#[cfg(feature = "symbolic")]
106pub use symbolic::{Expr, ExprValue, Pattern, RewriteRule, SolveOptions};
107
108#[cfg(feature = "tensor")]
109pub use tensor::Tensor;
110
111#[cfg(feature = "ai")]
112pub use ai::DaimonClient;
113
114// ---------------------------------------------------------------------------
115// Compile-time Send + Sync assertions
116// ---------------------------------------------------------------------------
117
118#[cfg(test)]
119mod assert_traits {
120    fn _assert_send_sync<T: Send + Sync>() {}
121
122    #[test]
123    fn public_types_are_send_sync() {
124        #[cfg(feature = "transforms")]
125        {
126            _assert_send_sync::<super::Transform2D>();
127            _assert_send_sync::<super::Transform3D>();
128        }
129
130        #[cfg(feature = "geo")]
131        {
132            _assert_send_sync::<super::Ray>();
133            _assert_send_sync::<super::Aabb>();
134            _assert_send_sync::<super::Sphere>();
135            _assert_send_sync::<super::Plane>();
136            _assert_send_sync::<super::Triangle>();
137            _assert_send_sync::<super::Line>();
138            _assert_send_sync::<super::Segment>();
139            _assert_send_sync::<super::Frustum>();
140            _assert_send_sync::<super::Obb>();
141            _assert_send_sync::<super::Capsule>();
142            _assert_send_sync::<super::Penetration3D>();
143        }
144
145        #[cfg(feature = "num")]
146        {
147            _assert_send_sync::<super::Complex>();
148        }
149    }
150}