Skip to main content

select_resampled_subset

Function select_resampled_subset 

Source
pub fn select_resampled_subset(
    gnss_positions: &[GnssPosition],
    resampling_distance: f64,
) -> Vec<usize>
Expand description

Select a resampled subset of GNSS positions for path calculation

Takes every Nth position based on the resampling distance and mean spacing. This reduces computational load while maintaining path structure accuracy.

§Arguments

  • gnss_positions - Full set of GNSS positions in temporal order
  • resampling_distance - Target distance between resampled positions (meters)

§Returns

Indices of positions to use for path calculation. Returns all indices if resampling is not beneficial (fewer than 3 positions, or step size < 2).

§Examples

use tp_lib_core::GnssPosition;
use chrono::Utc;

// Create 100 positions at 1m spacing
let positions: Vec<GnssPosition> = (0..100)
    .map(|i| {
        let mut pos = GnssPosition::new(
            50.85 + i as f64 * 0.00001,
            4.35,
            Utc::now().into(),
            "EPSG:4326".to_string()
        ).unwrap();
        pos.distance = Some(i as f64); // 1m spacing
        pos
    })
    .collect();

// Resample at 10m intervals
let indices = tp_lib_core::select_resampled_subset(&positions, 10.0);
// Approximately 10-12 positions selected (includes first and last)
assert!(indices.len() >= 10 && indices.len() <= 12);
assert_eq!(indices[0], 0); // First position always included
assert_eq!(*indices.last().unwrap(), 99); // Last position always included