Make SVG coordinates positive
This commit is contained in:
parent
dfb2320877
commit
ab4fcd5af3
10
src/input.rs
10
src/input.rs
@ -69,6 +69,10 @@ fn read_stdin() -> InputData {
|
|||||||
fn read_svg(input: &str) -> Result<InputData, Box<Error>> {
|
fn read_svg(input: &str) -> Result<InputData, Box<Error>> {
|
||||||
let svg = Document::from_str(input)?;
|
let svg = Document::from_str(input)?;
|
||||||
let svg = svg.svg_element().unwrap();
|
let svg = svg.svg_element().unwrap();
|
||||||
|
let svg_height = match svg.attributes().get_value(AttributeId::Height).unwrap() {
|
||||||
|
AttributeValue::Length(l) => l.num as f32,
|
||||||
|
_ => -42.0
|
||||||
|
};
|
||||||
let mut house = None;
|
let mut house = None;
|
||||||
let mut polys = Vec::new();
|
let mut polys = Vec::new();
|
||||||
for (id, node) in svg.descendants().svg() {
|
for (id, node) in svg.descendants().svg() {
|
||||||
@ -85,13 +89,13 @@ fn read_svg(input: &str) -> Result<InputData, Box<Error>> {
|
|||||||
for p in &path.0 {
|
for p in &path.0 {
|
||||||
match p {
|
match p {
|
||||||
PathSegment::MoveTo { x, y, .. } => {
|
PathSegment::MoveTo { x, y, .. } => {
|
||||||
points.push(Point::new(*x as f32, -*y as f32));
|
points.push(Point::new(*x as f32, svg_height-*y as f32));
|
||||||
}
|
}
|
||||||
PathSegment::LineTo { x, y, .. } => {
|
PathSegment::LineTo { x, y, .. } => {
|
||||||
points.push(Point::new(*x as f32, -*y as f32));
|
points.push(Point::new(*x as f32, svg_height-*y as f32));
|
||||||
}
|
}
|
||||||
PathSegment::VerticalLineTo { y, .. } => {
|
PathSegment::VerticalLineTo { y, .. } => {
|
||||||
points.push(Point::new(points.last().unwrap().x(), -*y as f32));
|
points.push(Point::new(points.last().unwrap().x(), svg_height-*y as f32));
|
||||||
}
|
}
|
||||||
PathSegment::HorizontalLineTo { x, .. } => {
|
PathSegment::HorizontalLineTo { x, .. } => {
|
||||||
points.push(Point::new(*x as f32, points.last().unwrap().y()));
|
points.push(Point::new(*x as f32, points.last().unwrap().y()));
|
||||||
|
@ -234,7 +234,7 @@ fn main() {
|
|||||||
if opt.debug {
|
if opt.debug {
|
||||||
// Performanz-Schätzung anzeigen
|
// Performanz-Schätzung anzeigen
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"DEBUG: {}μs/Iteration mit {} Iterationen",
|
"DEBUG: {}us/Iteration mit {} Iterationen",
|
||||||
total_time.as_micros() / iterations,
|
total_time.as_micros() / iterations,
|
||||||
iterations
|
iterations
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user