Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,12 @@ impl Vector {
/// The boolean in the tuple indicates if the path is closed.
/// The groups pair index-for-index with the contours emission, both stitching the same contours.
pub fn stroke_manipulator_groups(&self, paths: &List<Path>) -> impl Iterator<Item = (Vec<ManipulatorGroup>, bool)> {
self.stroke_manipulator_groups_and_anchor_indices(paths)
.map(|(manipulators_list, _, closed)| (manipulators_list, closed))
}

/// Like [`Self::stroke_manipulator_groups`], with the pool index of each group's anchor beside the groups.
pub fn stroke_manipulator_groups_and_anchor_indices(&self, paths: &List<Path>) -> impl Iterator<Item = (Vec<ManipulatorGroup>, Vec<u32>, bool)> {
let mut groups = Vec::new();

let curve_types: Vec<CurveType> = curve_types_of(paths).collect();
Expand All @@ -746,6 +752,7 @@ impl Vector {

for contour in contours(self.point_count(), paths) {
let mut manipulators_list: Vec<ManipulatorGroup> = Vec::new();
let mut anchor_indices = Vec::new();
let mut in_handle: Option<DVec2> = None;

for &part in &contour.parts {
Expand All @@ -764,6 +771,7 @@ impl Vector {
out_handle: handles.start(),
id: id_at(anchor),
});
anchor_indices.push(anchor);

in_handle = handles.end();
}
Expand All @@ -780,10 +788,11 @@ impl Vector {
out_handle: None,
id: id_at(contour.exit),
});
anchor_indices.push(contour.exit);
}

if !manipulators_list.is_empty() {
groups.push((manipulators_list, contour.closed));
groups.push((manipulators_list, anchor_indices, contour.closed));
}
}

Expand Down
9 changes: 6 additions & 3 deletions node-graph/libraries/vector-types/src/vector/vector_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,15 @@ impl Vector {

/// Drops the paths and every point used only as a handle, leaving the anchors and free points as a bare cloud.
/// A point serving as an anchor in any path is kept even where another path uses it as a handle.
pub fn keep_only_anchors(&mut self, paths: &mut List<Path>) {
/// Returns the former pool index of each kept point, in their kept order.
pub fn keep_only_anchors(&mut self, paths: &mut List<Path>) -> Vec<usize> {
let anchors = self.anchor_indices(paths);
let pool = anchors.into_iter().filter_map(|index| self.0.clone_item(index)).collect();
let pool = anchors.iter().filter_map(|&index| self.0.clone_item(index)).collect();

self.0 = pool;
*paths = List::new();

anchors
}

/// The positions of all anchor points and free points in pool order, skipping handles.
Expand Down Expand Up @@ -614,7 +617,7 @@ impl Vector {
}

/// Sets the smooth flag on many anchors at once, reading one connectivity rather than one per anchor.
pub(crate) fn set_smooth_at_indices(&mut self, paths: &mut List<Path>, indices: impl IntoIterator<Item = u32>, smooth: bool) {
pub fn set_smooth_at_indices(&mut self, paths: &mut List<Path>, indices: impl IntoIterator<Item = u32>, smooth: bool) {
let mut indices = indices.into_iter().peekable();
if indices.peek().is_none() {
return;
Expand Down
Loading
Loading