A PlineView is a lightweight, non-copying representation of a subpart or selection of a source polyline. It borrows the source polyline to provide access to vertex data and geometric operations without the overhead of duplicating the underlying data.
To use a view, you follow a two-step process:
- Create
PlineViewData: This structure holds the minimum metadata (indices, start/end points, bulge adjustments) required to define a contiguous subpart of a polyline. It is detached from the source and can be serialized. - Create a
PlineView: Call PlineViewData::view(&source) to create an active view that borrows the source polyline. The resulting PlineView implements the PlineSource trait, allowing you to use it in any function that accepts a polyline source.
When you are finished with the view, you can call .detach() to consume the view and retrieve the underlying PlineViewData, releasing the borrow on the source polyline.
// 1. Create view data (e.g., from slice points)
let view_data = PlineViewData::from_slice_points(
&polyline,
start_point,
start_index,
end_point,
end_index,
1e-5
).expect("slice not collapsed");
// 2. Create the active view by borrowing the source
let view = view_data.view(&polyline);
// 3. Use the view as a polyline source
let length = view.path_length();
// 4. Detach to release the borrow
let detached_data = view.detach();