Skip to content

Commit 7db9c62

Browse files
Keavontimon-schelling
authored andcommitted
Make domain push dupe checks debug-only and use push_unchecked in the Morph node
1 parent 6979e45 commit 7db9c62

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
@@ -2045,18 +2045,18 @@ async fn morph<I: IntoGraphicTable + 'n + Send + Clone>(
20452045
let Some(first) = manips.first() else { return };
20462046

20472047
let first_point_index = vector.point_domain.ids().len();
2048-
vector.point_domain.push(point_id.next_id(), first.anchor);
2048+
vector.point_domain.push_unchecked(point_id.next_id(), first.anchor);
20492049
let mut prev_point_index = first_point_index;
20502050
let mut first_segment_id = None;
20512051

20522052
for manip_window in manips.windows(2) {
20532053
let point_index = vector.point_domain.ids().len();
2054-
vector.point_domain.push(point_id.next_id(), manip_window[1].anchor);
2054+
vector.point_domain.push_unchecked(point_id.next_id(), manip_window[1].anchor);
20552055

20562056
let handles = handles_from_manips(manip_window[0].out_handle, manip_window[1].in_handle);
20572057
let seg_id = segment_id.next_id();
20582058
first_segment_id.get_or_insert(seg_id);
2059-
vector.segment_domain.push(seg_id, prev_point_index, point_index, handles, StrokeId::ZERO);
2059+
vector.segment_domain.push_unchecked(seg_id, prev_point_index, point_index, handles, StrokeId::ZERO);
20602060

20612061
prev_point_index = point_index;
20622062
}
@@ -2065,10 +2065,10 @@ async fn morph<I: IntoGraphicTable + 'n + Send + Clone>(
20652065
let handles = handles_from_manips(manips.last().unwrap().out_handle, manips[0].in_handle);
20662066
let closing_seg_id = segment_id.next_id();
20672067
first_segment_id.get_or_insert(closing_seg_id);
2068-
vector.segment_domain.push(closing_seg_id, prev_point_index, first_point_index, handles, StrokeId::ZERO);
2068+
vector.segment_domain.push_unchecked(closing_seg_id, prev_point_index, first_point_index, handles, StrokeId::ZERO);
20692069

20702070
let region_id = vector.region_domain.next_id();
2071-
vector.region_domain.push(region_id, first_segment_id.unwrap()..=closing_seg_id, FillId::ZERO);
2071+
vector.region_domain.push_unchecked(region_id, first_segment_id.unwrap()..=closing_seg_id, FillId::ZERO);
20722072
}
20732073
}
20742074

0 commit comments

Comments
 (0)