#![allow(dead_code)]
use polyclip::{Point, Polygon, PolygonSet, Ring};
pub fn load(name: &str) -> PolygonSet {
let path = format!("{}/testdata/{name}", env!("CARGO_MANIFEST_DIR"));
let data = std::fs::read(&path).unwrap_or_else(|e| panic!("{path}: {e}"));
assert!(data.starts_with(b"PCLP1\n"), "{path}: bad header");
let mut pos = 6;
let mut next = || -> i64 {
let (mut v, mut shift) = (0u64, 0);
loop {
let b = data[pos];
pos += 1;
v |= ((b & 0x7f) as u64) << shift;
if b & 0x80 == 0 {
break;
}
shift += 7;
}
((v >> 1) as i64) ^ -((v & 1) as i64)
};
let np = next() as usize;
(0..np)
.map(|_| {
let nr = next() as usize;
let mut rings: Vec<Ring> = (0..nr)
.map(|_| {
let n = next() as usize;
let (mut x, mut y) = (0i64, 0i64);
(0..n)
.map(|_| {
x += next();
y += next();
Point::new(x, y)
})
.collect()
})
.collect();
let outer = rings.remove(0);
Polygon::new(outer, rings)
})
.collect()
}