52 lines
1.8 KiB
Rust
52 lines
1.8 KiB
Rust
use super::*;
|
|
|
|
use std::io;
|
|
use std::io::prelude::*;
|
|
|
|
pub(crate) struct InputData {
|
|
pub start: Point,
|
|
pub polys: Vec<Polygon>
|
|
}
|
|
|
|
pub(crate) fn read_input() -> InputData {
|
|
//custom_input()
|
|
read_stdin()
|
|
}
|
|
|
|
fn read_stdin() -> InputData {
|
|
let stdin = io::stdin();
|
|
let stdin = stdin.lock();
|
|
|
|
let mut lines = stdin.lines().map(Result::unwrap);
|
|
let polygon_count = lines.next().unwrap().parse().unwrap();
|
|
let mut polygons = Vec::with_capacity(polygon_count);
|
|
|
|
for _ in 0..polygon_count {
|
|
let line = lines.next().unwrap();
|
|
let numbers = line.trim().split(' ').map(|x| x.parse::<usize>().unwrap()).collect::<Vec<_>>();
|
|
let corner_count = numbers[0];
|
|
polygons.push(Polygon::new((0..corner_count).map(|idx| ((numbers[idx*2+1] as f32).into(), (numbers[idx*2+2] as f32).into())).collect::<Vec<_>>().into(), vec![]));
|
|
}
|
|
|
|
let home = lines.next().unwrap().trim().split(' ').map(|x| x.parse::<f32>().unwrap().into()).collect::<Vec<_>>();
|
|
|
|
InputData {
|
|
start: Point::new(home[0], home[1]),
|
|
polys: polygons
|
|
}
|
|
}
|
|
|
|
fn custom_input() -> InputData {
|
|
let mut polys = vec![];
|
|
polys.push(Polygon::new(vec![[2.0.into(), 0.0.into()], [6.0.into(), 0.0.into()], [6.0.into(), 6.0.into()], [2.0.into(), 5.0.into()]].into(), vec![]));
|
|
polys.push(Polygon::new(vec![[1.0.into(), 20.0.into()], [2.0.into(), 20.0.into()], [2.0.into(), 23.0.into()], [1.0.into(), 23.0.into()]].into(), vec![]));
|
|
polys.push(Polygon::new(vec![[1.0.into(), 25.0.into()], [2.0.into(), 25.0.into()], [2.0.into(), 28.0.into()], [1.0.into(), 28.0.into()]].into(), vec![]));
|
|
let mut stick = Polygon::new(vec![[1.0.into(), 115.0.into()], [2.0.into(), 115.0.into()], [2.0.into(), 130.0.into()], [1.0.into(), 130.0.into()]].into(), vec![]);
|
|
polys.push(stick.clone());
|
|
stick = stick.translate(35.0.into(), (-20.0).into());
|
|
polys.push(stick);
|
|
InputData {
|
|
start: Point::new(45.0.into(), 95.0.into()),
|
|
polys
|
|
}
|
|
} |