Skip to content

Commit e2c48ce

Browse files
committed
Error handling improvement
1 parent 0b2f4fd commit e2c48ce

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ fn match_two(p1: DVec2, q1: DVec2, p2: DVec2, q2: DVec2) -> DAffine2 {
4545
fn intersect(p1: DVec2, q1: DVec2, p2: DVec2, q2: DVec2) -> DVec2 {
4646
let d = (q2.y - p2.y) * (q1.x - p1.x) - (q2.x - p2.x) * (q1.y - p1.y);
4747
if d.abs() < 1e-12 {
48-
panic!("parallel lines in intersect");
48+
log::warn!("parallel lines in intersect");
49+
return p1;
4950
}
5051
let ua = ((q2.x - p2.x) * (p1.y - p2.y) - (q2.y - p2.y) * (p1.x - p2.x)) / d;
5152
p1 + ua * (q1 - p1)
@@ -93,16 +94,25 @@ impl MetaTile {
9394
let (xf, tile) = &self.children[n];
9495
let outline = match tile.as_ref() {
9596
TileType::Meta(m) => &m.outline,
96-
TileType::Hat(_) => unreachable!(),
97+
TileType::Hat(_) => {
98+
log::warn!("eval_child called on Hat leaf");
99+
return DVec2::ZERO;
100+
}
97101
};
102+
if outline.is_empty() {
103+
return DVec2::ZERO;
104+
}
98105
xf.transform_point2(outline[i % outline.len()])
99106
}
100107

101108
fn child_outline(&self, n: usize) -> (&DAffine2, &[DVec2]) {
102109
let (xf, tile) = &self.children[n];
103110
match tile.as_ref() {
104111
TileType::Meta(m) => (xf, &m.outline),
105-
TileType::Hat(_) => unreachable!(),
112+
TileType::Hat(_) => {
113+
log::warn!("child_outline called on Hat leaf");
114+
(xf, &[])
115+
}
106116
}
107117
}
108118

@@ -216,14 +226,20 @@ fn shape_for_label<'a>(h: &'a Rc<TileType>, t: &'a Rc<TileType>, p: &'a Rc<TileT
216226
3 => h,
217227
4 => f,
218228
5 => t,
219-
_ => unreachable!(),
229+
_ => {
230+
log::warn!("Unknown label {}", label);
231+
h // Default fallback
232+
}
220233
}
221234
}
222235

223236
fn construct_patch(h: &Rc<TileType>, t: &Rc<TileType>, p: &Rc<TileType>, f: &Rc<TileType>) -> MetaTile {
224237
let h_meta = match h.as_ref() {
225238
TileType::Meta(m) => m,
226-
_ => unreachable!(),
239+
_ => {
240+
log::warn!("Expected MetaTile for 'h' in construct_patch");
241+
return MetaTile::new(Vec::new(), 0.0); // Return empty patch
242+
}
227243
};
228244
let mut ret = MetaTile::new(Vec::new(), h_meta.width);
229245

@@ -236,9 +252,15 @@ fn construct_patch(h: &Rc<TileType>, t: &Rc<TileType>, p: &Rc<TileType>, f: &Rc<
236252
let nshp = shape_for_label(h, t, p, f, r[2]);
237253
let nshp_meta = match nshp.as_ref() {
238254
TileType::Meta(m) => m,
239-
_ => unreachable!(),
255+
_ => {
256+
log::warn!("Expected MetaTile in construct_patch rule");
257+
continue;
258+
}
240259
};
241260
let idx = r[3] as usize;
261+
if nshp_meta.outline.is_empty() {
262+
continue;
263+
}
242264
ret.push(match_two(nshp_meta.outline[idx], nshp_meta.outline[(idx + 1) % nshp_meta.outline.len()], p_pt, q_pt), Rc::clone(nshp));
243265
}
244266
_ => {
@@ -249,9 +271,15 @@ fn construct_patch(h: &Rc<TileType>, t: &Rc<TileType>, p: &Rc<TileType>, f: &Rc<
249271
let nshp = shape_for_label(h, t, p, f, r[4]);
250272
let nshp_meta = match nshp.as_ref() {
251273
TileType::Meta(m) => m,
252-
_ => unreachable!(),
274+
_ => {
275+
log::warn!("Expected MetaTile in construct_patch rule");
276+
continue;
277+
}
253278
};
254279
let idx = r[5] as usize;
280+
if nshp_meta.outline.is_empty() {
281+
continue;
282+
}
255283
ret.push(match_two(nshp_meta.outline[idx], nshp_meta.outline[(idx + 1) % nshp_meta.outline.len()], p_pt, q_pt), Rc::clone(nshp));
256284
}
257285
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,10 @@ fn aperiodic_tiling(
404404
#[default(false)]
405405
cull_viewport: bool,
406406
#[expose]
407-
#[default((0., 0.).into())]
407+
#[default(0., 0.)]
408408
culling_bound_min: DVec2,
409409
#[expose]
410-
#[default((100., 100.).into())]
410+
#[default(100., 100.)]
411411
culling_bound_max: DVec2,
412412
) -> Table<Vector> {
413413
let culling_bounds = if cull_viewport {

0 commit comments

Comments
 (0)