Skip to content

Commit d8dd433

Browse files
Merge pull request #41 from mikhailofff/main
Add corner‑case tests for core overlay
2 parents 4da2af3 + 75fd225 commit d8dd433

1 file changed

Lines changed: 102 additions & 9 deletions

File tree

iOverlay/src/core/overlay.rs

Lines changed: 102 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,24 +419,24 @@ impl IntOverlayOptions {
419419

420420
#[cfg(test)]
421421
mod tests {
422-
extern crate std;
423-
424422
use alloc::vec;
425423
use i_float::int::point::IntPoint;
426424
use i_shape::int::area::Area;
425+
use i_shape::int::shape::IntContour;
427426
use crate::core::fill_rule::FillRule;
428427
use crate::core::overlay::Overlay;
429428
use crate::core::overlay_rule::OverlayRule;
430429

431430
#[test]
432431
fn test_0() {
433-
let subj = [[
434-
IntPoint::new(0, 0),
435-
IntPoint::new(10, 0),
436-
IntPoint::new(10, 10),
437-
IntPoint::new(0, 10),
438-
]
439-
.to_vec()];
432+
let subj = [
433+
vec![
434+
IntPoint::new(0, 0),
435+
IntPoint::new(10, 0),
436+
IntPoint::new(10, 10),
437+
IntPoint::new(0, 10),
438+
],
439+
];
440440

441441
let mut overlay = Overlay::with_contours(&subj, &[]);
442442
let result = overlay.overlay(OverlayRule::Subject, FillRule::EvenOdd);
@@ -753,4 +753,97 @@ mod tests {
753753
assert_eq!(result[0].len(), 1);
754754
assert_eq!(result.area(), -14);
755755
}
756+
757+
#[test]
758+
fn test_12() {
759+
let subj = [
760+
vec![
761+
IntPoint::new(2, 0),
762+
IntPoint::new(5, 0),
763+
IntPoint::new(5, 5),
764+
IntPoint::new(2, 5),
765+
],
766+
vec![
767+
IntPoint::new(0, 0),
768+
IntPoint::new(5, 0),
769+
IntPoint::new(5, 5),
770+
IntPoint::new(0, 5),
771+
],
772+
];
773+
774+
let mut overlay = Overlay::with_contours(&subj, &[]);
775+
let result = overlay.overlay(OverlayRule::Subject, FillRule::NonZero);
776+
777+
assert_eq!(result.len(), 1);
778+
assert_eq!(result[0].len(), 1);
779+
assert_eq!(result.area(), -25);
780+
}
781+
782+
#[test]
783+
fn test_13() {
784+
let subj = [
785+
vec![
786+
IntPoint::new(0, 0),
787+
IntPoint::new(5, 0),
788+
IntPoint::new(5, 5),
789+
IntPoint::new(0, 5),
790+
],
791+
vec![
792+
IntPoint::new(0, 0),
793+
IntPoint::new(5, 0),
794+
IntPoint::new(5, 5),
795+
IntPoint::new(0, 5),
796+
],
797+
];
798+
799+
let mut overlay = Overlay::with_contours(&subj, &[]);
800+
let result = overlay.overlay(OverlayRule::Subject, FillRule::NonZero);
801+
802+
assert_eq!(result.len(), 1);
803+
assert_eq!(result[0].len(), 1);
804+
assert_eq!(result.area(), -25);
805+
}
806+
807+
#[test]
808+
fn test_14() {
809+
let subj = [
810+
vec![
811+
IntPoint::new(0, 0),
812+
IntPoint::new(0, 2),
813+
IntPoint::new(2, 0),
814+
],
815+
vec![
816+
IntPoint::new(0, 0),
817+
IntPoint::new(2, 0),
818+
IntPoint::new(0, -2),
819+
],
820+
vec![
821+
IntPoint::new(0, 0),
822+
IntPoint::new(0, -2),
823+
IntPoint::new(-2, 0),
824+
],
825+
vec![
826+
IntPoint::new(0, 0),
827+
IntPoint::new(-2, 0),
828+
IntPoint::new(0, 2),
829+
],
830+
];
831+
832+
let mut overlay = Overlay::with_contours(&subj, &[]);
833+
let result = overlay.overlay(OverlayRule::Subject, FillRule::NonZero);
834+
835+
assert_eq!(result.len(), 1);
836+
assert_eq!(result[0].len(), 1);
837+
assert_eq!(result.area(), -8);
838+
}
839+
840+
#[test]
841+
fn test_empty_input() {
842+
let subj: &[IntContour] = &[];
843+
844+
let mut overlay = Overlay::with_contours(&subj, &[]);
845+
let result = overlay.overlay(OverlayRule::Subject, FillRule::NonZero);
846+
847+
assert_eq!(result.len(), 0);
848+
}
756849
}

0 commit comments

Comments
 (0)