Skip to content

Commit e1bc46a

Browse files
authored
Draw vector pool paths in their stored order and direction instead of re-walking segments (#4737)
* Stitch contours from stored path order and direction in place of the walker * Keep each path's boundary through the working form * Bake the straightest route through junctions into legacy segment soups * Keep Extrude's split pieces in their segment's place and order shared Close Path placements
1 parent 9e19a46 commit e1bc46a

9 files changed

Lines changed: 951 additions & 290 deletions

File tree

‎node-graph/libraries/vector-types/src/vector/algorithms/merge_by_distance.rs‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ impl MergeByDistanceExt for Vector {
103103

104104
// Drop the collapsed segments, then the merged-away points, remapping segment endpoints
105105
let keep_segment: Vec<bool> = working.segment_ids.iter().map(|id| !segments_to_delete.contains(id)).collect();
106+
working.carry_path_beginnings(&keep_segment);
106107
retain_by(&mut working.segment_ids, &keep_segment);
107108
retain_by(&mut working.segment_start, &keep_segment);
108109
retain_by(&mut working.segment_end, &keep_segment);
109110
retain_by(&mut working.segment_handles, &keep_segment);
111+
retain_by(&mut working.segment_begins_path, &keep_segment);
110112

111113
let mut point_map = Vec::with_capacity(working.point_ids.len());
112114
let mut new_index = 0;
@@ -130,7 +132,7 @@ impl MergeByDistanceExt for Vector {
130132
}
131133

132134
fn merge_by_distance_spatial(&mut self, paths: &mut List<Path>, transform: DAffine2, distance: f64) {
133-
let working = WorkingVector::flatten(self, paths);
135+
let mut working = WorkingVector::flatten(self, paths);
134136
let point_count = working.point_positions.len();
135137

136138
// Find min x and y for grid cell normalization
@@ -212,24 +214,29 @@ impl MergeByDistanceExt for Vector {
212214
}
213215
}
214216

215-
// Build the merged working form, skipping segments with endpoints that collapsed together
217+
// Segments with endpoints that collapsed together drop out, handing on any path they began
218+
let keep_segment: Vec<bool> = (0..working.segment_ids.len())
219+
.map(|segment_index| point_index_map[working.segment_start[segment_index]] != point_index_map[working.segment_end[segment_index]])
220+
.collect();
221+
working.carry_path_beginnings(&keep_segment);
222+
223+
// Build the merged working form from the kept segments
216224
let mut merged = WorkingVector {
217225
point_ids: merged_indices,
218226
point_positions: merged_positions,
219227
colinear: working.colinear,
220228
..Default::default()
221229
};
222230

223-
for segment_index in 0..working.segment_ids.len() {
231+
for segment_index in (0..working.segment_ids.len()).filter(|&segment_index| keep_segment[segment_index]) {
224232
let new_start = point_index_map[working.segment_start[segment_index]].unwrap();
225233
let new_end = point_index_map[working.segment_end[segment_index]].unwrap();
226234

227-
if new_start != new_end {
228-
merged.segment_ids.push(working.segment_ids[segment_index]);
229-
merged.segment_start.push(new_start);
230-
merged.segment_end.push(new_end);
231-
merged.segment_handles.push(working.segment_handles[segment_index]);
232-
}
235+
merged.segment_ids.push(working.segment_ids[segment_index]);
236+
merged.segment_start.push(new_start);
237+
merged.segment_end.push(new_end);
238+
merged.segment_handles.push(working.segment_handles[segment_index]);
239+
merged.segment_begins_path.push(working.segment_begins_path.get(segment_index).copied().unwrap_or(false));
233240
}
234241

235242
merged.reweave(self, paths);

0 commit comments

Comments
 (0)