spatial_decomposition/
lib.rs

1//! This crate contains algorithms to decompose spatial sets into smaller subdomains.
2//! To this date, only `1D` and `2D` algorithms are implemented.
3//!
4//! ## Overview
5//! | Domain | Function | Reference |
6//! |:--- | --- |:--- |
7//! | [Rectangle] | [kmr_decompose] | [Kong, Mount and Roscoe](https://scispace.com/pdf/the-decomposition-of-a-rectangle-into-rectangles-of-minimal-3whu99wjdy.pdf) |
8//! | [Rectangle] | [kmr_digitize_1] | [Kong, Mount and Roscoe](https://scispace.com/pdf/the-decomposition-of-a-rectangle-into-rectangles-of-minimal-3whu99wjdy.pdf) |
9//! | [Rectangle] | [kmr_digitize_1_single] | [Kong, Mount and Roscoe](https://scispace.com/pdf/the-decomposition-of-a-rectangle-into-rectangles-of-minimal-3whu99wjdy.pdf) |
10
11use approx::RelativeEq;
12
13/// Generalized cuboid in `D` dimensions
14///
15/// ```
16/// use spatial_decomposition::*;
17/// use approx::assert_abs_diff_eq;
18///
19/// let c1 = Cuboid {
20///     min: [1.; 4],
21///     max: [15., 15., 10., 10.],
22/// };
23/// let c2 = Cuboid {
24///     min: [1.1; 4],
25///     max: [14.9, 14.99, 10.02, 9.97],
26/// };
27///
28/// assert_abs_diff_eq!(c1, c2, epsilon = 0.11);
29/// ```
30#[derive(Clone, Debug, PartialEq, RelativeEq)]
31#[approx(epsilon_type = F)]
32pub struct Cuboid<F, const D: usize> {
33    /// Lower bounds of cuboid
34    #[approx(into_iter)]
35    pub min: [F; D],
36    /// Upper bounds of cuboid
37    #[approx(into_iter)]
38    pub max: [F; D],
39}
40
41unsafe impl<F, const D: usize> Send for Cuboid<F, D> {}
42unsafe impl<F, const D: usize> Sync for Cuboid<F, D> {}
43
44/// `2D` variant of the [Cuboid]
45pub type Rectangle<F> = Cuboid<F, 2>;
46
47/// `1D` variant of the [Cuboid]
48pub type Line<F> = Cuboid<F, 1>;
49
50mod kong_mount_roscoe;
51
52pub use kong_mount_roscoe::*;