Skip to content

Commit

Permalink
Add std feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
n3vu0r committed Mar 24, 2024
1 parent c09974f commit dd877d0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
14 changes: 13 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ keywords = [
"welzl-algorithm",
]
categories = [
"no-std",
"science",
"graphics",
"algorithms",
Expand All @@ -31,9 +32,20 @@ include = [
"LICENSES/*",
]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
nalgebra = { version = "0.32.4", default-features = false, features = ["alloc"] }
stacker = { version = "0.1.15", optional = true }

[features]
default = ["std"]
std = ["dep:stacker"]

[dev-dependencies]
nalgebra = { version = "0.32.4", features = ["rand"] }
stacker = "0.1.15"

[profile.test]
opt-level = 2
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Lower trait bounds on `Ball` and `Enclosing`.
* Use `T` in favor of `R` as does `nalgebra`.
* Allow `no_std` by gating `stacker` dependency and `Deque` implementations behind `std` feature.

# Version 0.3.0 (2024-03-17)

Expand Down
3 changes: 3 additions & 0 deletions src/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#[cfg(feature = "std")]
use std::collections::{LinkedList, VecDeque};

/// Minimum double-ended queue interface.
Expand All @@ -29,6 +30,7 @@ pub trait Deque<T> {
}
}

#[cfg(feature = "std")]
impl<T> Deque<T> for VecDeque<T> {
#[inline]
fn len(&self) -> usize {
Expand All @@ -54,6 +56,7 @@ impl<T> Deque<T> for VecDeque<T> {
}
}

#[cfg(feature = "std")]
impl<T> Deque<T> for LinkedList<T> {
#[inline]
fn len(&self) -> usize {
Expand Down
19 changes: 14 additions & 5 deletions src/enclosing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use super::{Deque, OVec};
use core::mem::size_of;
use nalgebra::{
base::allocator::Allocator, DefaultAllocator, DimName, DimNameAdd, DimNameSum, OPoint,
RealField, U1,
};
#[cfg(feature = "std")]
use stacker::maybe_grow;
use std::mem::size_of;

#[cfg(not(feature = "std"))]
#[inline]
fn maybe_grow<R, F: FnOnce() -> R>(_red_zone: usize, _stack_size: usize, callback: F) -> R {
callback()
}

/// Minimum enclosing ball.
pub trait Enclosing<T: RealField, D: DimName>
Expand Down Expand Up @@ -72,15 +79,17 @@ where
/// to the front and enclosed ones to the back.
///
/// Implements [Welzl's recursive algorithm] with move-to-front heuristic. No allocations happen
/// unless real field `T` is not [`Copy`] or stack size enters dimension-dependant red zone in
/// which case temporary stack space will be allocated.
/// unless the real field `T` is not [`Copy`] or the stack size enters the dimension-dependant
/// red zone in which case temporary stack space will be allocated on the heap if the `std`
/// feature is enabled.
///
/// [Welzl's recursive algorithm]: https://api.semanticscholar.org/CorpusID:17569809
///
/// # Complexity
///
/// Expected time complexity is *O*(*n*) for *n* randomly permuted points. Complexity constant
/// *c* as in *cn* is significantly reduced by reusing permuted points of previous invocations.
/// Expected time complexity is *O*((*n*+1)(*n*+1)!*m*) for *m* randomly permuted
/// *n*-dimensional points. The complexity constant in *m* is significantly reduced by reusing
/// permuted points of previous invocations.
///
/// # Example
///
Expand Down
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@
//! * Find minimum enclosing *n*-ball of *n*-balls.
//! * Find minimum-volume enclosing *n*-ellipsoid.
//! * Improve numerical stability and performance.
//!
//! # Features
//!
//! * `std` for spilling recursion stack over to the heap if necessary. Enabled by `default`.
#![forbid(missing_docs)]
#![forbid(unsafe_code)]
#![forbid(missing_docs)]
#![forbid(rustdoc::broken_intra_doc_links)]
#![allow(clippy::tabs_in_doc_comments)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

mod ball;
mod deque;
Expand Down
2 changes: 1 addition & 1 deletion src/ovec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use core::mem::take;
use nalgebra::{base::allocator::Allocator, DefaultAllocator, DimName, OVector};
use std::mem::take;

/// Owned vector of item `T` and capacity `D`.
#[doc(hidden)]
Expand Down

0 comments on commit dd877d0

Please sign in to comment.