Expand description
Generic traits and type parameters for spatial algorithms
This module provides generic traits that enable spatial algorithms to work with different numeric types and array structures. This improves API flexibility and allows for better integration with the broader Rust ecosystem.
§Features
- Generic numeric types: Support for f32, f64, and other numeric types
- Array ecosystem integration: Work with ndarray, nalgebra, and other array types
- Iterator support: Process data from various sources efficiently
- Dimension awareness: Compile-time and runtime dimension checking
- Memory efficiency: Zero-copy operations where possible
§Examples
use scirs2_spatial::generic_traits::{SpatialScalar};
use scirs2_core::ndarray::array;
// Generic distance calculation (simplified example)
fn calculate_distance<T>(p1: &[T], p2: &[T]) -> T
where
T: SpatialScalar,
{
// Generic implementation (simplified)
T::zero()
}
// Works with different array types
let point1 = array![1.0f32, 2.0f32, 3.0f32];
let point2 = array![4.0f32, 5.0f32, 6.0f32];
let _result = calculate_distance(point1.as_slice().unwrap(), point2.as_slice().unwrap());Modules§
- ndarray_
integration - Integration with ndarray
- utils
- Utility functions for generic spatial operations
Structs§
- Chebyshev
Metric - Chebyshev distance metric
- Euclidean
Metric - Euclidean distance metric
- Manhattan
Metric - Manhattan distance metric
- Point
- Generic point structure for spatial algorithms
Traits§
- Distance
Metric - Trait for distance metrics
- Spatial
Array - Trait for collections of spatial points
- Spatial
Point - Trait for types that can represent a point in space
- Spatial
Scalar - Trait for scalar types that can be used in spatial computations