1#[cfg(feature = "std")]
5pub(crate) use self::std::*;
6
7#[cfg(all(feature = "alloc", not(feature = "std")))]
9pub(crate) use self::alloc::*;
10
11#[cfg(all(not(feature = "alloc"), not(feature = "std")))]
13pub(crate) use self::core::*;
14
15#[cfg(feature = "std")]
17mod std {
18 pub(crate) use std::format;
29
30 pub(crate) type String = std::string::String;
32 pub(crate) type DefaultCheapStr = String;
34 pub(crate) type Map<K, V> = std::collections::HashMap<K, V, std::collections::hash_map::RandomState>;
36 pub(crate) type Vec<A> = std::vec::Vec<A>;
38 pub(crate) type ChildrenVec<A> = std::vec::Vec<A>;
40 #[cfg(feature = "grid")]
41 pub(crate) type GridTrackVec<A> = std::vec::Vec<A>;
43
44 #[must_use]
46 pub(crate) fn new_vec_with_capacity<A>(capacity: usize) -> Vec<A> {
47 Vec::with_capacity(capacity)
48 }
49
50 #[must_use]
52 #[inline(always)]
53 pub(crate) fn round(value: f32) -> f32 {
54 (value + 0.5).floor()
55 }
56
57 #[must_use]
59 #[inline(always)]
60 pub(crate) fn ceil(value: f32) -> f32 {
61 value.ceil()
62 }
63
64 #[must_use]
66 #[inline(always)]
67 pub(crate) fn floor(value: f32) -> f32 {
68 value.floor()
69 }
70
71 #[must_use]
73 #[inline(always)]
74 pub(crate) fn abs(value: f32) -> f32 {
75 value.abs()
76 }
77
78 #[inline(always)]
80 pub(crate) fn f32_max(a: f32, b: f32) -> f32 {
81 a.max(b)
82 }
83
84 #[inline(always)]
86 pub(crate) fn f32_min(a: f32, b: f32) -> f32 {
87 a.min(b)
88 }
89}
90
91#[cfg(all(feature = "alloc", not(feature = "std")))]
93mod alloc {
94 extern crate alloc;
95 use core::cmp::Ordering;
96
97 pub(crate) use alloc::format;
108
109 pub(crate) type String = alloc::string::String;
111 pub(crate) type DefaultCheapStr = String;
113 pub(crate) type Map<K, V> = alloc::collections::BTreeMap<K, V>;
116 pub(crate) type Vec<A> = alloc::vec::Vec<A>;
118 pub(crate) type ChildrenVec<A> = alloc::vec::Vec<A>;
120 #[cfg(feature = "grid")]
121 pub(crate) type GridTrackVec<A> = alloc::vec::Vec<A>;
123
124 #[must_use]
126 pub(crate) fn new_vec_with_capacity<A>(capacity: usize) -> Vec<A> {
127 Vec::with_capacity(capacity)
128 }
129
130 pub(crate) use super::polyfill::round;
132
133 pub(crate) use super::polyfill::ceil;
135
136 pub(crate) use super::polyfill::floor;
138
139 pub(crate) use super::polyfill::abs;
141
142 #[inline(always)]
144 pub(crate) fn f32_max(a: f32, b: f32) -> f32 {
145 a.max(b)
146 }
147
148 #[inline(always)]
150 pub(crate) fn f32_min(a: f32, b: f32) -> f32 {
151 a.min(b)
152 }
153}
154
155#[cfg(all(not(feature = "alloc"), not(feature = "std")))]
157mod core {
158 use core::cmp::Ordering;
159
160 pub const MAX_NODE_COUNT: usize = 256;
162 pub const MAX_CHILD_COUNT: usize = 16;
164 #[cfg(feature = "grid")]
165 pub const MAX_GRID_TRACKS: usize = 16;
167
168 pub(crate) type String = &'static str;
170 pub(crate) type DefaultCheapStr = &'static str;
172
173 pub(crate) type Vec<A> = arrayvec::ArrayVec<A, MAX_NODE_COUNT>;
175 pub(crate) type ChildrenVec<A> = arrayvec::ArrayVec<A, MAX_CHILD_COUNT>;
177 #[cfg(feature = "grid")]
178 pub(crate) type GridTrackVec<A> = arrayvec::ArrayVec<A, MAX_GRID_TRACKS>;
180
181 #[must_use]
185 pub(crate) fn new_vec_with_capacity<A, const CAP: usize>(_capacity: usize) -> arrayvec::ArrayVec<A, CAP> {
186 arrayvec::ArrayVec::new()
187 }
188
189 pub(crate) use super::polyfill::round;
191
192 pub(crate) use super::polyfill::abs;
194
195 #[inline(always)]
197 pub(crate) fn f32_max(a: f32, b: f32) -> f32 {
198 a.max(b)
199 }
200
201 #[inline(always)]
203 pub(crate) fn f32_min(a: f32, b: f32) -> f32 {
204 a.min(b)
205 }
206}
207
208#[cfg(not(feature = "std"))]
211mod polyfill {
212 #[must_use]
213 #[inline(always)]
214 fn fract(value: f32) -> f32 {
215 if value == 0.0 {
216 0.0
217 } else {
218 value % 1.0
219 }
220 }
221
222 #[must_use]
223 #[inline(always)]
224 pub(crate) fn round(value: f32) -> f32 {
225 let f = fract(value);
226 if f.is_nan() || f == 0.0 {
227 value
228 } else if value > 0.0 {
229 if f < 0.5 {
230 value - f
231 } else {
232 value - f + 1.0
233 }
234 } else if -f < 0.5 {
235 value - f
236 } else {
237 value - f - 1.0
238 }
239 }
240
241 #[must_use]
242 #[inline(always)]
243 pub(crate) fn floor(value: f32) -> f32 {
244 let f = fract(value);
245 if f.is_nan() || f == 0.0 {
246 value
247 } else if value < 0.0 {
248 value - f - 1.0
249 } else {
250 value - f
251 }
252 }
253
254 #[must_use]
255 #[inline(always)]
256 pub(crate) fn ceil(value: f32) -> f32 {
257 let f = fract(value);
258 if f.is_nan() || f == 0.0 {
259 value
260 } else if value > 0.0 {
261 value - f + 1.0
262 } else {
263 value - f
264 }
265 }
266
267 #[must_use]
269 #[inline(always)]
270 pub(crate) fn abs(value: f32) -> f32 {
271 if value.is_sign_positive() {
272 return value;
273 } else if value.is_sign_negative() {
274 return -value;
275 } else {
276 f32::NAN
277 }
278 }
279}