Skip to content

Commit a9a3fe1

Browse files
committed
Make domain push dupe checks debug-only and use push_unchecked in the Morph node
1 parent a459ced commit a9a3fe1

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

node-graph/libraries/vector-types/src/vector/vector_attributes.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,16 @@ impl PointDomain {
129129
}
130130

131131
pub fn push(&mut self, id: PointId, position: DVec2) {
132+
#[cfg(debug_assertions)]
132133
if self.id.contains(&id) {
134+
warn!("Tried to push a duplicate point to a point domain");
133135
return;
134136
}
135137

136-
self.id.push(id);
137-
self.position.push(position);
138+
self.push_unchecked(id, position);
138139
}
139140

141+
#[inline(always)]
140142
pub fn push_unchecked(&mut self, id: PointId, position: DVec2) {
141143
self.id.push(id);
142144
self.position.push(position);
@@ -316,9 +318,15 @@ impl SegmentDomain {
316318
pub fn push(&mut self, id: SegmentId, start: usize, end: usize, handles: BezierHandles, stroke: StrokeId) {
317319
#[cfg(debug_assertions)]
318320
if self.id.contains(&id) {
319-
warn!("Tried to push an existing point to a point domain");
321+
warn!("Tried to push a duplicate segment to a segment domain");
322+
return;
320323
}
321324

325+
self.push_unchecked(id, start, end, handles, stroke);
326+
}
327+
328+
#[inline(always)]
329+
pub fn push_unchecked(&mut self, id: SegmentId, start: usize, end: usize, handles: BezierHandles, stroke: StrokeId) {
322330
self.id.push(id);
323331
self.start_point.push(start);
324332
self.end_point.push(end);
@@ -531,10 +539,17 @@ impl RegionDomain {
531539
}
532540

533541
pub fn push(&mut self, id: RegionId, segment_range: std::ops::RangeInclusive<SegmentId>, fill: FillId) {
542+
#[cfg(debug_assertions)]
534543
if self.id.contains(&id) {
535-
warn!("Duplicate region");
544+
warn!("Tried to push a duplicate region to a region domain");
536545
return;
537546
}
547+
548+
self.push_unchecked(id, segment_range, fill);
549+
}
550+
551+
#[inline(always)]
552+
pub fn push_unchecked(&mut self, id: RegionId, segment_range: std::ops::RangeInclusive<SegmentId>, fill: FillId) {
538553
self.id.push(id);
539554
self.segment_range.push(segment_range);
540555
self.fill.push(fill);

node-graph/nodes/vector/src/vector_nodes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,18 +2028,18 @@ async fn morph<I: IntoGraphicTable + 'n + Send + Clone>(
20282028
let Some(first) = manips.first() else { return };
20292029

20302030
let first_point_index = vector.point_domain.ids().len();
2031-
vector.point_domain.push(point_id.next_id(), first.anchor);
2031+
vector.point_domain.push_unchecked(point_id.next_id(), first.anchor);
20322032
let mut prev_point_index = first_point_index;
20332033
let mut first_segment_id = None;
20342034

20352035
for manip_window in manips.windows(2) {
20362036
let point_index = vector.point_domain.ids().len();
2037-
vector.point_domain.push(point_id.next_id(), manip_window[1].anchor);
2037+
vector.point_domain.push_unchecked(point_id.next_id(), manip_window[1].anchor);
20382038

20392039
let handles = handles_from_manips(manip_window[0].out_handle, manip_window[1].in_handle);
20402040
let seg_id = segment_id.next_id();
20412041
first_segment_id.get_or_insert(seg_id);
2042-
vector.segment_domain.push(seg_id, prev_point_index, point_index, handles, StrokeId::ZERO);
2042+
vector.segment_domain.push_unchecked(seg_id, prev_point_index, point_index, handles, StrokeId::ZERO);
20432043

20442044
prev_point_index = point_index;
20452045
}
@@ -2048,10 +2048,10 @@ async fn morph<I: IntoGraphicTable + 'n + Send + Clone>(
20482048
let handles = handles_from_manips(manips.last().unwrap().out_handle, manips[0].in_handle);
20492049
let closing_seg_id = segment_id.next_id();
20502050
first_segment_id.get_or_insert(closing_seg_id);
2051-
vector.segment_domain.push(closing_seg_id, prev_point_index, first_point_index, handles, StrokeId::ZERO);
2051+
vector.segment_domain.push_unchecked(closing_seg_id, prev_point_index, first_point_index, handles, StrokeId::ZERO);
20522052

20532053
let region_id = vector.region_domain.next_id();
2054-
vector.region_domain.push(region_id, first_segment_id.unwrap()..=closing_seg_id, FillId::ZERO);
2054+
vector.region_domain.push_unchecked(region_id, first_segment_id.unwrap()..=closing_seg_id, FillId::ZERO);
20552055
}
20562056
}
20572057

0 commit comments

Comments
 (0)