Module simulation

Module simulation 

Source
Expand description

Tools for simulating progress along a route.

§Example

Here’s an example usage with the polyline constructor. This can serve as a template for writing your own test code. You may also get some inspiration from the Swift or Kotlin SimulatedLocationProvider implementations which wrap this.

use ferrostar::simulation::{advance_location_simulation, location_simulation_from_polyline, LocationBias};

let polyline_precision = 6;
// Build the initial state from an encoded polyline.
// You can create a simulation from coordinates or even a [Route] as well.
let mut state = location_simulation_from_polyline(
    "wzvmrBxalf|GcCrX}A|Nu@jI}@pMkBtZ{@x^_Afj@Inn@`@veB",
    polyline_precision,
    // Passing `Some(number)` will resample your polyline at uniform distances.
    // This is often desirable to create a smooth simulated movement when you don't have a GPS trace.
    None,
    LocationBias::None,
)?;

loop {
    let mut new_state = advance_location_simulation(&state);
    if new_state == state {
        // When the simulation reaches the end, it keeps yielding the input state.
        break;
    }
    state = new_state;
    // Do something; maybe sleep for some period of time until the next timestamp?
}

Structs§

LocationSimulationState
The current state of the simulation.

Enums§

LocationBias
Controls how simulated locations deviate from the actual route line. This simulates real-world GPS behavior where readings often have systematic bias.
SimulationError

Functions§

advance_location_simulation
Returns the next simulation state based on the desired strategy. Results of this can be thought of like a stream from a generator function.
location_simulation_from_coordinates
Creates a location simulation from a set of coordinates.
location_simulation_from_polyline
Creates a location simulation from a polyline.
location_simulation_from_route
Creates a location simulation from a route.