Skip to main content

Module subpath

Module subpath 

Source
Expand description

Provides an iterator to decompose a Path into its individual subpaths.

A Path can contain multiple disconnected shapes (e.g., the letter ‘i’ has two). This module provides the SubpathIter iterator, which is created via the IntoIterator implementation for &Path. This allows you to easily loop over each continuous segment of a larger path.

§Example

use path_offset::path::Path;
use lyon::path::Path as LyonPath;

// Create a path with two separate subpaths.
let mut builder = LyonPath::builder();
builder.begin(lyon::math::point(0.0, 0.0));
builder.line_to(lyon::math::point(10.0, 0.0));
builder.end(false); // First subpath
builder.begin(lyon::math::point(20.0, 0.0));
builder.line_to(lyon::math::point(30.0, 0.0));
builder.end(false); // Second subpath
let lyon_path = builder.build();

let path = Path::from(lyon_path);

// Iterate over the subpaths.
let mut subpath_count = 0;
for subpath in &path {
    subpath_count += 1;
    // Each `subpath` is a `path_offset::path::Path` containing one continuous shape.
}

assert_eq!(subpath_count, 2);

Structs§

SubpathIter
An iterator that decomposes a path containing multiple shapes into individual subpaths.