Module lyon_algorithms::walk

source ·
Expand description

Move at a defined speed along a path.

Path walking

Overview

In principle, walking a path is similar to iterating over it, but instead of going from receiving path segments (of varying sizes), the path walker makes it possible to advance by a certain distance along the path.

Example

use lyon_algorithms::walk::{RegularPattern, walk_along_path, WalkerEvent};
use lyon_algorithms::path::PathSlice;
use lyon_algorithms::path::iterator::*;
use lyon_algorithms::path::math::Point;

fn dots_along_path(path: PathSlice, dots: &mut Vec<Point>) {
    let mut pattern = RegularPattern {
        callback: &mut |event: WalkerEvent| {
            dots.push(event.position);
            true // Return true to continue walking the path.
        },
        // Invoke the callback above at a regular interval of 3 units.
        interval: 3.0,
    };

    let tolerance = 0.1; // The path flattening tolerance.
    let start_offset = 0.0; // Start walking at the beginning of the path.
    walk_along_path(
        path.iter(),
        start_offset,
        tolerance,
        &mut pattern
    );
}

Structs

  • A helper struct to walk along a flattened path using a builder API.
  • A simple pattern that invokes a callback at regular intervals.
  • A pattern that invokes a callback at a repeated sequence of constant intervals.

Traits

  • Types implementing the Pattern can be used to walk along a path at constant speed.

Functions

  • Walks along the path staring at offset start and applies a Pattern.