Performance-oriented Rust library providing a suite of geometry primitives and algorithms for efficient computational geometry.
(f32, f32),(f64, f64)- rust tuples[f32;2],[f64;2]- rust arraysVec2frombevycratePoint2<T>fromnalgebracrateCoord<T>fromgeocrate
- 2D
- convex hull
- farthest points
use geomancer::algorithms::convex_hull;
// ...
let points = [(0.1, 0.2), (10.0, -1.0), (5.0, 2.0), (7.0, 7.0)];
let result = convex_hull(&points).unwrap();
println!("Points that are part of the convex hull: {:?}", result.hull_points());
println!("Points that are not part of the convex hull: {:?}", result.inside_points());
println!("Area: {} Perimeter: {}", result.area(), result.perimeter());
// Find convex hull using exact math, without rounding and floating point errors.
let result_exact = convex_hull_exact(&points, false /* include_collinear */).unwrap();use geomancer::algorithms::farthest_points;
// ...
let points = [(0.0, 0.0), (10.0, 1.0), (-5.0, -1.0)];
let (point_a_idx, point_b_idx) = farthest_points(&points).unwrap();Geomancer provides a range of default kernels tailored to different libraries. Each kernel defines a set of operations for a specific vector or point type. By enabling the corresponding feature, the DefaultKernel trait is automatically implemented for that type.
Below is a summary of the supported kernels:
| Library | Vector Type | Default Kernel | Feature | Dimension | Exact |
|---|---|---|---|---|---|
| bevy_math | Vec2 | BevyVec2Kernel | bevy_math | 2D | No |
| nalgebra | Vector2 | NalgebraVector2Kernel | nalgebra | 2D | No |
| nalgebra | Point2 | NalgebraPoint2Kernel | nalgebra | 2D | No |
| geo | Coord | GeoCoordKernel | geo | 2D | No |
| (T, T) | TupleKernel2D | tuple_kernels | 2D | No | |
| [T; 2] | ArrayKernel2D | array_kernels | 2D | No | |
| Any V: Point2D | GenericKernel2D* | - | 2D | No |
*If the data type or library you are using is not listed, you can still use the generic kernel. The generic kernel works with any type that implements the Point2D trait. Simply add the following implementations to your code:
impl Point2D for MY_VECTOR_TYPE {
// Provide the implementation for the Point2D trait.
}
impl DefaultKernel for MY_VECTOR_TYPE {
type Kernel = GenericKernel2D<MY_VECTOR_TYPE>;
}Using a specialized kernel is preferable when available, as it may include optimizations tailored to that particular vector type.
/// A trait for 2D points with x and y coordinates
pub trait Point2D {
type Scalar;
fn x(&self) -> Self::Scalar;
fn y(&self) -> Self::Scalar;
}
/// Base trait for 2 dimensional geometric kernel that defines number and point type.
pub trait Kernel2D {
type Point;
type Scalar;
}Geomancer is free and open source library, all code in this repository is dual-licensed under:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)