1//! Allocator-flexible data types
23// When std is enabled, prefer those types
4#[cfg(feature = "std")]
5pub(crate) use self::std::*;
67// When alloc but not std is enabled, use those types
8#[cfg(all(feature = "alloc", not(feature = "std")))]
9pub(crate) use self::alloc::*;
1011// When neither alloc or std is enabled, use a heapless fallback
12#[cfg(all(not(feature = "alloc"), not(feature = "std")))]
13pub(crate) use self::core::*;
1415/// For when `std` is enabled
16#[cfg(feature = "std")]
17mod std {
18/// An allocation-backend agnostic vector type
19pub(crate) type Vec<A> = std::vec::Vec<A>;
20/// A vector of child nodes
21pub(crate) type ChildrenVec<A> = std::vec::Vec<A>;
22#[cfg(feature = "grid")]
23/// A vector of grid tracks
24pub(crate) type GridTrackVec<A> = std::vec::Vec<A>;
2526/// Creates a new vector with the capacity for the specified number of items before it must be resized
27#[must_use]
28pub(crate) fn new_vec_with_capacity<A>(capacity: usize) -> Vec<A> {
29 Vec::with_capacity(capacity)
30 }
3132/// Rounds to the nearest whole number
33#[must_use]
34 #[inline(always)]
35pub(crate) fn round(value: f32) -> f32 {
36 value.round()
37 }
3839/// Computes the absolute value
40#[must_use]
41 #[inline(always)]
42pub(crate) fn abs(value: f32) -> f32 {
43 value.abs()
44 }
4546/// Returns the largest of two f32 values
47#[inline(always)]
48pub(crate) fn f32_max(a: f32, b: f32) -> f32 {
49 a.max(b)
50 }
5152/// Returns the smallest of two f32 values
53#[inline(always)]
54pub(crate) fn f32_min(a: f32, b: f32) -> f32 {
55 a.min(b)
56 }
57}
5859/// For when `alloc` but not `std` is enabled
60#[cfg(all(feature = "alloc", not(feature = "std")))]
61mod alloc {
62extern crate alloc;
63use core::cmp::Ordering;
6465/// An allocation-backend agnostic vector type
66pub(crate) type Vec<A> = alloc::vec::Vec<A>;
67/// A vector of child nodes
68pub(crate) type ChildrenVec<A> = alloc::vec::Vec<A>;
69#[cfg(feature = "grid")]
70/// A vector of grid tracks
71pub(crate) type GridTrackVec<A> = alloc::vec::Vec<A>;
7273/// Creates a new vector with the capacity for the specified number of items before it must be resized
74#[must_use]
75pub(crate) fn new_vec_with_capacity<A>(capacity: usize) -> Vec<A> {
76 Vec::with_capacity(capacity)
77 }
7879/// Rounds to the nearest whole number
80#[must_use]
81 #[inline(always)]
82pub(crate) fn round(value: f32) -> f32 {
83 num_traits::float::FloatCore::round(value)
84 }
8586/// Computes the absolute value
87#[must_use]
88 #[inline(always)]
89pub(crate) fn abs(value: f32) -> f32 {
90 num_traits::float::FloatCore::abs(value)
91 }
9293/// Returns the largest of two f32 values
94#[inline(always)]
95pub(crate) fn f32_max(a: f32, b: f32) -> f32 {
96 a.max(b)
97 }
9899/// Returns the smallest of two f32 values
100#[inline(always)]
101pub(crate) fn f32_min(a: f32, b: f32) -> f32 {
102 a.min(b)
103 }
104}
105106/// For when neither `alloc` nor `std` is enabled
107#[cfg(all(not(feature = "alloc"), not(feature = "std")))]
108mod core {
109use core::cmp::Ordering;
110111/// The maximum number of nodes in the tree
112pub const MAX_NODE_COUNT: usize = 256;
113/// The maximum number of children of any given node
114pub const MAX_CHILD_COUNT: usize = 16;
115#[cfg(feature = "grid")]
116/// The maximum number of children of any given node
117pub const MAX_GRID_TRACKS: usize = 16;
118119/// An allocation-backend agnostic vector type
120pub(crate) type Vec<A> = arrayvec::ArrayVec<A, MAX_NODE_COUNT>;
121/// A vector of child nodes, whose length cannot exceed [`MAX_CHILD_COUNT`]
122pub(crate) type ChildrenVec<A> = arrayvec::ArrayVec<A, MAX_CHILD_COUNT>;
123#[cfg(feature = "grid")]
124/// A vector of grid tracks
125pub(crate) type GridTrackVec<A> = arrayvec::ArrayVec<A, MAX_GRID_TRACKS>;
126127/// Creates a new map with the capacity for the specified number of items before it must be resized
128 ///
129 /// This vector cannot be resized.
130#[must_use]
131pub(crate) fn new_vec_with_capacity<A, const CAP: usize>(_capacity: usize) -> arrayvec::ArrayVec<A, CAP> {
132 arrayvec::ArrayVec::new()
133 }
134135/// Rounds to the nearest whole number
136#[inline]
137 #[must_use]
138 #[inline(always)]
139pub(crate) fn round(value: f32) -> f32 {
140 num_traits::float::FloatCore::round(value)
141 }
142143/// Computes the absolute value
144#[inline]
145 #[must_use]
146 #[inline(always)]
147pub(crate) fn abs(value: f32) -> f32 {
148 num_traits::float::FloatCore::abs(value)
149 }
150151/// Returns the largest of two f32 values
152#[inline(always)]
153pub(crate) fn f32_max(a: f32, b: f32) -> f32 {
154 a.max(b)
155 }
156157/// Returns the smallest of two f32 values
158#[inline(always)]
159pub(crate) fn f32_min(a: f32, b: f32) -> f32 {
160 a.min(b)
161 }
162}