polydf 0.1.1

Distance queries for parametric curves in 2D and 3D (nearest point, unsigned distance, early-out with speed bounds).
Documentation
// Simple 3D example: nearest-point queries to a helix in R^3.
// Run with: cargo run --example nearest_helix_3d

use nalgebra::{Vector3, vector};
use polydf::{
    NearestOptions,
    nearest_t_3d,
    nearest_t_within_3d,
    is_definitely_far_3d,
};

// Helix: C(t) = [cos t, sin t, 0.5 t]
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],  // near t ~ 0, d ~ 1
        vector![0.0, 0.0, 5.0],  // near t ~ 10, z = 0.5 t
        vector![10.0, 10.0, 10.0], // far
    ];

    let threshold = 5.0f32;
    // For this helix, |C'(t)| = sqrt(1 + 0.5^2) = sqrt(1.25) ~ 1.118...
    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);

        // Demonstrate early-out when provably far
        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 {
            // Compute the true nearest point/distance
            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
            );

            // Or, use the combined thresholded API
            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);
        }
    }
}