scirs2_spatial/convex_hull/geometry/mod.rs
1//! Geometric utility functions for convex hull computations
2//!
3//! This module provides geometric calculations needed for convex hull algorithms,
4//! organized by dimensionality for optimal performance and clarity.
5//!
6//! # Module Organization
7//!
8//! - [`calculations_2d`] - 2D geometric calculations (cross products, areas, perimeters)
9//! - [`calculations_3d`] - 3D geometric calculations (volumes, surface areas, vector operations)
10//! - [`high_dimensional`] - High-dimensional calculations and approximations
11//!
12//! # Examples
13//!
14//! ## 2D Calculations
15//! ```rust
16//! use scirs2_spatial::convex_hull::geometry::calculations_2d::{cross_product_2d, compute_polygon_area};
17//! use scirs2_core::ndarray::array;
18//!
19//! // Check orientation of three points
20//! let p1 = [0.0, 0.0];
21//! let p2 = [1.0, 0.0];
22//! let p3 = [0.0, 1.0];
23//! let cross = cross_product_2d(p1, p2, p3);
24//! assert!(cross > 0.0); // Counterclockwise orientation
25//!
26//! // Compute polygon area
27//! let points = array![[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]];
28//! let vertices = vec![0, 1, 2, 3];
29//! let area = compute_polygon_area(&points.view(), &vertices).unwrap();
30//! assert!((area - 1.0).abs() < 1e-10);
31//! ```
32//!
33//! ## 3D Calculations
34//! ```rust
35//! use scirs2_spatial::convex_hull::geometry::calculations_3d::{tetrahedron_volume, triangle_area_3d};
36//!
37//! // Compute tetrahedron volume
38//! let p0 = [0.0, 0.0, 0.0];
39//! let p1 = [1.0, 0.0, 0.0];
40//! let p2 = [0.0, 1.0, 0.0];
41//! let p3 = [0.0, 0.0, 1.0];
42//! let volume = tetrahedron_volume(p0, p1, p2, p3);
43//! assert!((volume.abs() - 1.0/6.0).abs() < 1e-10);
44//!
45//! // Compute triangle area in 3D
46//! let area = triangle_area_3d(p0, p1, p2);
47//! assert!((area - 0.5).abs() < 1e-10);
48//! ```
49//!
50//! ## High-Dimensional Calculations
51//! ```rust
52//! use scirs2_spatial::convex_hull::geometry::high_dimensional::{compute_centroid, compute_bounding_box};
53//! use scirs2_core::ndarray::array;
54//!
55//! let points = array![
56//! [0.0, 0.0, 0.0, 0.0],
57//! [1.0, 0.0, 0.0, 0.0],
58//! [0.0, 1.0, 0.0, 0.0],
59//! [0.0, 0.0, 1.0, 0.0]
60//! ];
61//! let vertices = vec![0, 1, 2, 3];
62//!
63//! let centroid = compute_centroid(&points.view(), &vertices);
64//! let (min_coords, max_coords) = compute_bounding_box(&points.view(), &vertices);
65//! ```
66
67pub mod calculations_2d;
68pub mod calculations_3d;
69pub mod high_dimensional;
70
71// Re-export commonly used functions for convenience
72pub use calculations_2d::{
73 compute_2d_hull_equations, compute_polygon_area, compute_polygon_perimeter, cross_product_2d,
74 distance_squared_2d, is_counterclockwise, polar_angle,
75};
76
77pub use calculations_3d::{
78 compute_polyhedron_surface_area, compute_polyhedron_volume, cross_product_3d, dot_product_3d,
79 normalize_3d, tetrahedron_volume, triangle_area_3d, vector_magnitude_3d,
80};
81
82pub use high_dimensional::{
83 compute_bounding_box, compute_centroid, compute_characteristic_size,
84 compute_high_dim_surface_area, compute_high_dim_volume, estimate_facet_area,
85};