polygon-art/tests/test_geo_clipper.rs
Ingolf Wagner 81aea71162
initial commit
that hides all the nonsense I did.
2021-04-07 08:04:29 +02:00

52 lines
1.7 KiB
Rust

///! test library to verify if geo libraries
use geo::algorithm::intersects::Intersects;
use geo::polygon;
use geo_clipper::Clipper;
#[test]
fn test_intersection_dijoint() {
let p0 = polygon![(x: 1.0, y: 1.0), (x: 2.0, y:1.0), (x: 2.0, y: 2.0), (x :1.0, y : 2.0)];
let p1 =
polygon![(x: -1.0, y: -1.0), (x: -2.0, y:-1.0), (x: -2.0, y: -2.0), (x :-1.0, y : -2.0)];
assert!(!p0.intersects(&p1), "p0 and p0 should not intersetct");
let multi_polygon = p0.intersection(&p1, 1.0);
let mut count = 0;
for _ in multi_polygon.iter() {
assert!(false, "never happen");
count = count + 1;
}
assert_eq!(count, 0, "there should be no intersecting polygon");
}
#[test]
fn test_intersection_joint() {
let p0 = polygon![(x: 1.0, y: 1.0), (x: 2.0, y:1.0), (x: 2.0, y: 2.0), (x :1.0, y : 2.0)];
let p1 = polygon![(x: 0.0, y: 0.0), (x: 2.0, y:0.0), (x: 2.0, y: 1.5), (x :0.0, y : 1.5)];
assert!(p0.intersects(&p1), "p0 and p0 should be intersecting");
// p1 \cap p0
let multi_polygon = p1.intersection(&p0, 10.0);
let mut count = 0;
for _ in multi_polygon.iter() {
count = count + 1;
}
assert_eq!(count, 1, "there should be no intersecting polygon");
// p0 \cap p1
let multi_polygon = p0.intersection(&p1, 10.0);
let mut count = 0;
for _ in multi_polygon.iter() {
count = count + 1;
}
assert_eq!(count, 1, "there should be no intersecting polygon");
// verify if polygon is really the correct one
let x = multi_polygon.iter().next().unwrap();
let intersection_polygon = polygon![
(x:2.0, y:1.5),
(x:1.0, y:1.5),
(x:1.0, y:1.0),
(x:2.0, y:1.0),
];
assert_eq!(x, &intersection_polygon);
}