use nalgebra::{Vector3, vector};
use polydf::{
NearestOptions,
nearest_t_3d,
nearest_t_within_3d,
is_definitely_far_3d,
};
fn helix(t: f32) -> Vector3<f32> {
vector![t.cos(), t.sin(), 0.5 * t]
}
fn main() {
let t_range = -10.0f32..=10.0f32;
let opts = NearestOptions { samples: 64, ..Default::default() };
let queries = [
vector![2.0, 0.0, 0.0], vector![0.0, 0.0, 5.0], vector![10.0, 10.0, 10.0], ];
let threshold = 5.0f32;
let speed_upper_bound = Some(1.2f32);
for (i, p) in queries.iter().enumerate() {
println!("Query {}: p = [{:.3}, {:.3}, {:.3}]", i + 1, p.x, p.y, p.z);
let far = is_definitely_far_3d(*p, helix, t_range.clone(), threshold, speed_upper_bound, opts.samples);
if far {
println!(" - definitely farther than threshold = {:.3}; skipping exact search", threshold);
} else {
let res = nearest_t_3d(*p, helix, t_range.clone(), opts);
println!(
" - nearest: t* = {:.4}, C(t*) = [{:.3}, {:.3}, {:.3}], d = {:.4}",
res.t, res.point.x, res.point.y, res.point.z, res.distance
);
let within = nearest_t_within_3d(*p, helix, t_range.clone(), threshold, speed_upper_bound, opts)
.map(|r| r.distance <= threshold)
.unwrap_or(false);
println!(" - within threshold {:.3}: {}", threshold, within);
}
}
}