Skip to content

Commit af031b1

Browse files
committed
add corner‑case tests for vector simplify
1 parent 8e1b714 commit af031b1

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

iOverlay/src/vector/simplify.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,76 @@ mod tests {
258258
debug_assert!(result);
259259
debug_assert!(contour.len() == 4);
260260
}
261+
262+
#[test]
263+
fn test_duplicate_points() {
264+
#[rustfmt::skip]
265+
let mut contour = vec![
266+
VectorEdge::new(1, int_pnt!(-1, 3), int_pnt!(-1, 1)),
267+
VectorEdge::new(2, int_pnt!(-1, 3), int_pnt!(-1, 1)),
268+
VectorEdge::new(3, int_pnt!(-1, 1), int_pnt!(-3, 1)),
269+
VectorEdge::new(4, int_pnt!(-3, 1), int_pnt!(-3, -2)),
270+
VectorEdge::new(5, int_pnt!(-3, -2), int_pnt!(3, -2)),
271+
VectorEdge::new(6, int_pnt!(3, -2), int_pnt!(3, 1)),
272+
VectorEdge::new(7, int_pnt!(3, -2), int_pnt!(1, 1)),
273+
VectorEdge::new(8, int_pnt!(1, 1), int_pnt!(1, 3)),
274+
VectorEdge::new(9, int_pnt!(1, 3), int_pnt!(-1, 3)),
275+
VectorEdge::new(10, int_pnt!(-1, 3), int_pnt!(-1, -1)),
276+
];
277+
278+
let result = contour.simplify_contour();
279+
280+
debug_assert!(result);
281+
debug_assert!(contour.len() == 8);
282+
}
283+
284+
#[test]
285+
fn test_tiny_segments() {
286+
#[rustfmt::skip]
287+
let mut contour = vec![
288+
VectorEdge::new(1, int_pnt!(0, 1), int_pnt!(-1, 0)),
289+
VectorEdge::new(2, int_pnt!(-1, 0), int_pnt!(0, -1)),
290+
VectorEdge::new(3, int_pnt!(-1, 0), int_pnt!(0, -1)),
291+
VectorEdge::new(4, int_pnt!(0, -1), int_pnt!(1, 0)),
292+
VectorEdge::new(5, int_pnt!(1, 0), int_pnt!(0, 1)),
293+
VectorEdge::new(6, int_pnt!(1, 0), int_pnt!(0, 1)),
294+
];
295+
296+
let result = contour.simplify_contour();
297+
298+
debug_assert!(result);
299+
debug_assert!(contour.len() == 4);
300+
}
301+
302+
#[test]
303+
fn test_collinear_runs() {
304+
#[rustfmt::skip]
305+
let mut contour = vec![
306+
VectorEdge::new(1, int_pnt!(-3, 0), int_pnt!(3, 0)),
307+
VectorEdge::new(2, int_pnt!(-3, 0), int_pnt!(-1, 0)),
308+
VectorEdge::new(3, int_pnt!(-2, 0), int_pnt!(2, 0)),
309+
VectorEdge::new(4, int_pnt!(3, 0), int_pnt!(0, -3)),
310+
VectorEdge::new(5, int_pnt!(0, -3), int_pnt!(-3, 0)),
311+
];
312+
313+
let result = contour.simplify_contour();
314+
315+
debug_assert!(result);
316+
debug_assert!(contour.len() == 3);
317+
}
318+
319+
#[test]
320+
fn test_zero_area_path() {
321+
#[rustfmt::skip]
322+
let mut contour = vec![
323+
VectorEdge::new(1, int_pnt!(-3, 0), int_pnt!(3, 0)),
324+
VectorEdge::new(2, int_pnt!(-3, 0), int_pnt!(-1, 0)),
325+
VectorEdge::new(3, int_pnt!(-2, 0), int_pnt!(2, 0)),
326+
];
327+
328+
let result = contour.simplify_contour();
329+
330+
debug_assert!(result);
331+
debug_assert!(contour.is_empty());
332+
}
261333
}

0 commit comments

Comments
 (0)