Skip to content

Commit cbeac5a

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

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

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);
@@ -618,10 +626,17 @@ impl RegionDomain {
618626
}
619627

620628
pub fn push(&mut self, id: RegionId, segment_range: std::ops::RangeInclusive<SegmentId>, fill: FillId) {
629+
#[cfg(debug_assertions)]
621630
if self.id.contains(&id) {
622-
warn!("Duplicate region");
631+
warn!("Tried to push a duplicate region to a region domain");
623632
return;
624633
}
634+
635+
self.push_unchecked(id, segment_range, fill);
636+
}
637+
638+
#[inline(always)]
639+
pub fn push_unchecked(&mut self, id: RegionId, segment_range: std::ops::RangeInclusive<SegmentId>, fill: FillId) {
625640
self.id.push(id);
626641
self.segment_range.push(segment_range);
627642
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
@@ -2120,18 +2120,18 @@ async fn morph<I: IntoGraphicTable + 'n + Send + Clone>(
21202120
let Some(first) = manips.first() else { return };
21212121

21222122
let first_point_index = vector.point_domain.ids().len();
2123-
vector.point_domain.push(point_id.next_id(), first.anchor);
2123+
vector.point_domain.push_unchecked(point_id.next_id(), first.anchor);
21242124
let mut prev_point_index = first_point_index;
21252125
let mut first_segment_id = None;
21262126

21272127
for manip_window in manips.windows(2) {
21282128
let point_index = vector.point_domain.ids().len();
2129-
vector.point_domain.push(point_id.next_id(), manip_window[1].anchor);
2129+
vector.point_domain.push_unchecked(point_id.next_id(), manip_window[1].anchor);
21302130

21312131
let handles = handles_from_manips(manip_window[0].out_handle, manip_window[1].in_handle);
21322132
let seg_id = segment_id.next_id();
21332133
first_segment_id.get_or_insert(seg_id);
2134-
vector.segment_domain.push(seg_id, prev_point_index, point_index, handles, StrokeId::ZERO);
2134+
vector.segment_domain.push_unchecked(seg_id, prev_point_index, point_index, handles, StrokeId::ZERO);
21352135

21362136
prev_point_index = point_index;
21372137
}
@@ -2140,10 +2140,10 @@ async fn morph<I: IntoGraphicTable + 'n + Send + Clone>(
21402140
let handles = handles_from_manips(manips.last().unwrap().out_handle, manips[0].in_handle);
21412141
let closing_seg_id = segment_id.next_id();
21422142
first_segment_id.get_or_insert(closing_seg_id);
2143-
vector.segment_domain.push(closing_seg_id, prev_point_index, first_point_index, handles, StrokeId::ZERO);
2143+
vector.segment_domain.push_unchecked(closing_seg_id, prev_point_index, first_point_index, handles, StrokeId::ZERO);
21442144

21452145
let region_id = vector.region_domain.next_id();
2146-
vector.region_domain.push(region_id, first_segment_id.unwrap()..=closing_seg_id, FillId::ZERO);
2146+
vector.region_domain.push_unchecked(region_id, first_segment_id.unwrap()..=closing_seg_id, FillId::ZERO);
21472147
}
21482148
}
21492149

0 commit comments

Comments
 (0)