Skip to content

Commit 2ae38dd

Browse files
Merge pull request #38 from mikhailofff/main
Add corner‑case tests for vector simplify
2 parents 8e1b714 + 7a68a1f commit 2ae38dd

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

iOverlay/src/vector/simplify.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,79 @@ 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, 1), 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, 1), int_pnt!(3, 1)),
273+
VectorEdge::new(8, int_pnt!(3, 1), int_pnt!(1, 1)),
274+
VectorEdge::new(9, int_pnt!(1, 1), int_pnt!(1, 3)),
275+
VectorEdge::new(10, int_pnt!(1, 3), int_pnt!(-1, 3)),
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, 2), int_pnt!(-1, 1)),
289+
VectorEdge::new(2, int_pnt!(-1, 1), int_pnt!(-2, 0)),
290+
VectorEdge::new(3, int_pnt!(-2, 0), int_pnt!(0, -1)),
291+
VectorEdge::new(4, int_pnt!(0, -1), int_pnt!(2, 0)),
292+
VectorEdge::new(5, int_pnt!(2, 0), int_pnt!(1, 1)),
293+
VectorEdge::new(6, int_pnt!(1, 1), int_pnt!(0, 2)),
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!(-2, -2), int_pnt!(0, -2)),
307+
VectorEdge::new(2, int_pnt!(0, -2), int_pnt!(2, -2)),
308+
VectorEdge::new(3, int_pnt!(2, -2), int_pnt!(2, 0)),
309+
VectorEdge::new(4, int_pnt!(2, 0), int_pnt!(2, 2)),
310+
VectorEdge::new(5, int_pnt!(2, 2), int_pnt!(0, 2)),
311+
VectorEdge::new(6, int_pnt!(0, 2), int_pnt!(-2, 2)),
312+
VectorEdge::new(7, int_pnt!(-2, 2), int_pnt!(-2, 0)),
313+
VectorEdge::new(8, int_pnt!(-2, 0), int_pnt!(-2, -2)),
314+
];
315+
316+
let result = contour.simplify_contour();
317+
318+
debug_assert!(result);
319+
debug_assert!(contour.len() == 4);
320+
}
321+
322+
#[test]
323+
fn test_zero_area_path() {
324+
#[rustfmt::skip]
325+
let mut contour = vec![
326+
VectorEdge::new(1, int_pnt!(-3, 0), int_pnt!(0, 0)),
327+
VectorEdge::new(2, int_pnt!(0, 0), int_pnt!(3, 0)),
328+
VectorEdge::new(3, int_pnt!(3, 0), int_pnt!(-3, 0)),
329+
];
330+
331+
let result = contour.simplify_contour();
332+
333+
debug_assert!(result);
334+
debug_assert!(contour.is_empty());
335+
}
261336
}

0 commit comments

Comments
 (0)