diff --git a/Cargo.toml b/Cargo.toml index be2e2c2..c18aa00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "miniball" description = "Minimum enclosing ball" authors = ["Rouven Spreckels "] -version = "0.3.0" +version = "0.3.1" rust-version = "1.61.0" edition = "2021" documentation = "https://docs.rs/miniball" diff --git a/RELEASES.md b/RELEASES.md index 587b791..855f878 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,6 +1,10 @@ +# Version 0.3.1 (2024-03-22) + + * Lower trait bounds on `Ball` and `Enclosing`. + # Version 0.3.0 (2024-03-17) - * Replace `Point` with `OPoint` supporting static as well as dynamic dimensions. + * Replace `Point` with `OPoint` supporting arithmetic at compile-time. * Replace `ArrayVec` with `OVec>` supporting stabe Rust. # Version 0.2.0 (2023-04-01) diff --git a/src/ball.rs b/src/ball.rs index ceb386e..c729d6d 100644 --- a/src/ball.rs +++ b/src/ball.rs @@ -6,13 +6,12 @@ use super::Enclosing; use nalgebra::{ - base::allocator::Allocator, DefaultAllocator, DimNameAdd, DimNameSum, OMatrix, OPoint, OVector, - RealField, U1, + base::allocator::Allocator, DefaultAllocator, DimName, OMatrix, OPoint, OVector, RealField, }; /// Ball over real field `R` of dimension `D` with center and radius squared. #[derive(Debug, Clone, PartialEq)] -pub struct Ball> +pub struct Ball where DefaultAllocator: Allocator, { @@ -22,24 +21,25 @@ where pub radius_squared: R, } -impl> Copy for Ball +impl Copy for Ball where OPoint: Copy, DefaultAllocator: Allocator, { } -impl> Enclosing for Ball +impl Enclosing for Ball where - DefaultAllocator: - Allocator + Allocator + Allocator, DimNameSum>, - , DimNameSum>>::Buffer: Default, + DefaultAllocator: Allocator, { #[inline] fn contains(&self, point: &OPoint) -> bool { (point - &self.center).norm_squared() <= self.radius_squared } - fn with_bounds(bounds: &[OPoint]) -> Option { + fn with_bounds(bounds: &[OPoint]) -> Option + where + DefaultAllocator: Allocator, + { let length = bounds.len().checked_sub(1).filter(|&len| len <= D::USIZE)?; let points = OMatrix::::from_fn(|row, column| { if column < length { diff --git a/src/enclosing.rs b/src/enclosing.rs index 46fd053..56f515e 100644 --- a/src/enclosing.rs +++ b/src/enclosing.rs @@ -6,17 +6,17 @@ use super::{Deque, OVec}; use nalgebra::{ - base::allocator::Allocator, DefaultAllocator, DimNameAdd, DimNameSum, OPoint, RealField, U1, + base::allocator::Allocator, DefaultAllocator, DimName, DimNameAdd, DimNameSum, OPoint, + RealField, U1, }; use stacker::maybe_grow; use std::mem::size_of; /// Minimum enclosing ball. -pub trait Enclosing> +pub trait Enclosing where Self: Clone, - DefaultAllocator: Allocator + Allocator, DimNameSum>, - , DimNameSum>>::Buffer: Default, + DefaultAllocator: Allocator, { #[doc(hidden)] /// Guaranteed stack size per recursion step. @@ -59,7 +59,9 @@ where /// assert_eq!(radius_squared, 3.0); /// ``` #[must_use] - fn with_bounds(bounds: &[OPoint]) -> Option; + fn with_bounds(bounds: &[OPoint]) -> Option + where + DefaultAllocator: Allocator; /// Returns minimum ball enclosing `points`. /// @@ -130,7 +132,12 @@ where /// ``` #[must_use] #[inline] - fn enclosing_points(points: &mut impl Deque>) -> Self { + fn enclosing_points(points: &mut impl Deque>) -> Self + where + D: DimNameAdd, + DefaultAllocator: Allocator + Allocator, DimNameSum>, + , DimNameSum>>::Buffer: Default, + { maybe_grow(Self::RED_ZONE, Self::STACK_SIZE, || { Self::enclosing_points_with_bounds( points, @@ -147,7 +154,12 @@ where fn enclosing_points_with_bounds( points: &mut impl Deque>, bounds: &mut OVec, DimNameSum>, - ) -> Option { + ) -> Option + where + D: DimNameAdd, + DefaultAllocator: Allocator + Allocator, DimNameSum>, + , DimNameSum>>::Buffer: Default, + { // Take point from back. if let Some(point) = points.pop_back().filter(|_| !bounds.is_full()) { let ball = maybe_grow(Self::RED_ZONE, Self::STACK_SIZE, || { diff --git a/src/ovec.rs b/src/ovec.rs index cbc5a2c..cfb956d 100644 --- a/src/ovec.rs +++ b/src/ovec.rs @@ -61,7 +61,6 @@ where /// Panics if [`Self::is_full()`]. #[inline] pub fn push(&mut self, item: T) { - assert!(!self.is_full()); self.data[self.size] = item; self.size += 1; }