commit d12cef3a4fb8f07cda39dbeb363fdcd2e0b9f3be Author: Arne Keller Date: Tue Feb 5 22:29:23 2019 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84851a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +**/*.rs.bk +tri*.svg diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6604bf7 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,204 @@ +[[package]] +name = "aufgabe2" +version = "0.1.0" +dependencies = [ + "geo 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "svg 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "autocfg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "backtrace" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cc" +version = "1.0.29" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cfg-if" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "failure" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "failure_derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "geo" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "geo-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rstar 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "geo-types" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rstar 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libc" +version = "0.2.48" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num-traits" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "pdqselect" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "proc-macro2" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rstar" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "pdqselect 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "svg" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "syn" +version = "0.15.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "synstructure" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" +"checksum backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b493b66e03090ebc4343eb02f94ff944e0cbc9ac6571491d170ba026741eb5" +"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" +"checksum cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)" = "4390a3b5f4f6bce9c1d0c00128379df433e53777fdd30e92f16a529332baec4e" +"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" +"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" +"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" +"checksum geo 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8bbea85edcd145704d6d4a72b7bd667caee822d3511f9eb94b21008043f1ebe6" +"checksum geo-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05350aaba2e842c89fc8e1b2e74eefded6f2abe6ce5e0f5b9037c4b71c9b3598" +"checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047" +"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" +"checksum pdqselect 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ec91767ecc0a0bbe558ce8c9da33c068066c57ecc8bb8477ef8c1ad3ef77c27" +"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" +"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" +"checksum rstar 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "64ffe043929ee67d46694af1a4851f6bbe571b52a55677ba1686222dc35fd449" +"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" +"checksum svg 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)" = "a863ec1f8e7cfd4ea449f77445cca06aac240b9a677ccf12b0f65ef020db52c7" +"checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9" +"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" +"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f2c92a5 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aufgabe2" +version = "0.1.0" +authors = ["Arne Keller "] +edition = "2018" + +[dependencies] +geo = "0.11.0" +svg = "0.5.12" diff --git a/dreiecke1.txt b/dreiecke1.txt new file mode 100644 index 0000000..ea0fc92 --- /dev/null +++ b/dreiecke1.txt @@ -0,0 +1,6 @@ +5 +3 0 0 138 37 37 138 +3 135 0 273 37 172 138 +3 270 0 408 37 307 138 +3 405 0 543 37 442 138 +3 540 0 678 37 577 138 \ No newline at end of file diff --git a/dreiecke2.txt b/dreiecke2.txt new file mode 100644 index 0000000..e83fc75 --- /dev/null +++ b/dreiecke2.txt @@ -0,0 +1,6 @@ +5 +3 40 458 170 0 20 0 +3 190 558 320 0 170 0 +3 395 278 470 0 320 0 +3 600 516 620 0 470 0 +3 750 501 770 0 620 0 \ No newline at end of file diff --git a/dreiecke3.txt b/dreiecke3.txt new file mode 100644 index 0000000..792cb68 --- /dev/null +++ b/dreiecke3.txt @@ -0,0 +1,13 @@ +12 +3 0 0 64 0 0 190 +3 34 110 189 0 51 220 +3 215 0 214 160 159 172 +3 277 266 232 0 329 211 +3 270 0 335 190 335 0 +3 341 118 538 159 499 225 +3 451 0 377 112 483 56 +3 479 14 541 0 554 68 +3 580 0 586 155 656 240 +3 673 102 591 11 655 0 +3 680 0 745 0 679 207 +3 776 294 791 0 727 190 \ No newline at end of file diff --git a/dreiecke4.txt b/dreiecke4.txt new file mode 100644 index 0000000..d2e02ba --- /dev/null +++ b/dreiecke4.txt @@ -0,0 +1,24 @@ +23 +3 11 206 46 171 111 171 +3 111 171 81 206 11 206 +3 10 38 46 171 11 206 +3 10 38 46 0 46 171 +3 46 171 111 171 111 106 +3 146 36 146 71 46 171 +3 111 0 146 36 46 171 +3 46 0 111 0 46 171 +3 177 196 211 0 217 59 +3 211 0 231 190 260 0 +3 260 0 292 196 252 59 +3 352 195 352 0 397 195 +3 397 195 397 0 352 0 +3 466 196 496 0 466 31 +3 496 166 496 0 466 196 +3 596 66 496 66 496 166 +3 650 196 685 0 650 36 +3 650 196 685 166 685 0 +3 780 166 650 196 685 166 +3 685 114 780 84 685 84 +3 561 196 561 101 596 66 +3 561 196 596 161 596 66 +3 596 66 596 0 526 66 \ No newline at end of file diff --git a/dreiecke5.txt b/dreiecke5.txt new file mode 100644 index 0000000..6d7ec7a --- /dev/null +++ b/dreiecke5.txt @@ -0,0 +1,38 @@ +37 +3 450 172 465 64 476 121 +3 0 160 39 61 76 124 +3 122 155 153 71 169 150 +3 574 277 636 281 622 383 +3 364 106 411 97 441 155 +3 605 172 654 139 615 229 +3 708 64 749 91 717 175 +3 274 313 285 295 302 346 +3 6 221 60 250 7 296 +3 374 217 398 172 407 277 +3 676 289 657 373 640 322 +3 333 59 365 128 312 148 +3 497 285 522 211 558 289 +3 100 0 170 20 120 70 +3 337 151 373 140 348 214 +3 96 61 104 154 80 165 +3 271 142 297 209 279 236 +3 48 307 33 406 6 340 +3 504 115 530 154 489 205 +3 668 46 666 131 605 122 +3 276 259 336 253 370 321 +3 224 295 158 313 171 232 +3 699 271 743 323 703 376 +3 93 223 136 331 86 334 +3 753 251 770 273 767 332 +3 298 114 335 24 260 42 +3 792 178 766 213 750 191 +3 243 244 254 273 240 303 +3 439 273 467 204 467 316 +3 68 201 97 163 80 232 +3 549 148 584 151 552 225 +3 564 131 544 63 621 79 +3 464 366 403 377 418 313 +3 240 212 213 10 249 89 +3 729 192 714 240 663 184 +3 171 172 188 213 116 223 +3 57 334 70 288 69 408 \ No newline at end of file diff --git a/src/display.rs b/src/display.rs new file mode 100644 index 0000000..bc11e19 --- /dev/null +++ b/src/display.rs @@ -0,0 +1,122 @@ +use svg::node::element::path::Data; +use svg::node::element::Path; +use svg::node::element::{AnimateMotion, Circle, MotionPath}; +use svg::Document; +use svg::Node; + +use std::fs; + +use super::*; + +/* +pub(crate) fn dump_latex_code(route: &[RunState], polys: &[Polygon]) { + const SCALE: f64 = 70.0; + let mut xmax = 0.0; + let mut ymax = 0.0; + for poly in polys { + for point in poly.exterior.points_iter() { + let x = point.x() / SCALE; + let y = point.y() / SCALE; + if x > xmax { + xmax = x; + } + if y > ymax { + ymax = y; + } + } + } + if route[route.len() - 1].pos.y() / SCALE > ymax { + ymax = route[route.len() - 1].pos.y() / SCALE; + } + println!("\\begin{{tikzpicture}}"); + println!("\\tkzInit[xmax={},ymax={}]", xmax + 0.3, ymax + 0.3); + println!("\\tkzAxeXY"); + println!("\\tkzGrid"); + for (idx, poly) in polys.iter().enumerate() { + print!("\\tkzDefPoints{{"); + for (poly_idx, point) in poly.exterior.points_iter().enumerate() { + let x = point.x() / SCALE; + let y = point.y() / SCALE; + print!("{}/{}/P{}_{}", x, y, idx, poly_idx); + if poly_idx != poly.exterior.0.len() - 1 { + print!(","); + } + if x > xmax { + xmax = x; + } + if y > ymax { + ymax = y; + } + } + println!("}}"); + print!("\\tkzDrawPolygon[fill=black,line width=1pt,opacity=0.5]("); + for (poly_idx, _) in poly.exterior.points_iter().enumerate() { + print!("P{}_{}", idx, poly_idx); + if poly_idx != poly.exterior.0.len() - 1 { + print!(","); + } + } + println!(")"); + } + for (idx, s) in route.iter().enumerate() { + println!( + "\\tkzDefPoint({},{}){{R{}}}", + s.pos.x() / SCALE, + s.pos.y() / SCALE, + idx + ); + } + for idx in 1..route.len() { + println!("\\tkzDrawSegment(R{},R{})", idx - 1, idx); + } + for idx in 0..route.len() { + println!("\\tkzDrawPoint[fill=red,color=black,size=13](R{})", idx); + } + println!("\\end{{tikzpicture}}"); +} +*/ + +/* +pub(crate) fn dump_route(house: Point, polys: &[Polygon], route: &Vec) { + let (points, lines, route1, route2_start) = gen_params(house, route); + print!( + "{}", + generate_svg(&points, &lines, polys, &route1, route2_start) + ); +} +*/ + +pub(crate) fn save_tri(filename: &str, tri: Triangle) { + fs::write( + filename, + generate_svg(&[tri]), + ) + .unwrap(); +} + +pub(crate) fn generate_svg(tris: &[Triangle]) -> String { + let mut document = Document::new() + // view box at (x,y), (w,h) + .set( + "viewBox", + (-500.0, -500.0, 1000.0, 1000.0), + ) + .set("transform", (1.0, -1.0)) + .set("xmlns:xlink", "http://www.w3.org/1999/xlink"); + + for tri in tris { + let data = Data::new() + .move_to((tri.0.x, tri.0.y)) + .line_to((tri.1.x, tri.1.y)) + .line_to((tri.2.x, tri.2.y)) + .close(); + document.append(Path::new() + .set("fill", "none") + .set("stroke", "black") + .set("stroke-width", 10.0) + .set("d", data)); + + } + + document.to_string() +} diff --git a/src/input.rs b/src/input.rs new file mode 100644 index 0000000..a38b234 --- /dev/null +++ b/src/input.rs @@ -0,0 +1,30 @@ +use super::*; + +use std::io; +use std::io::prelude::*; + +pub(crate) fn read_input() -> Vec> { + read_stdin() +} + +fn read_stdin() -> Vec> { + let stdin = io::stdin(); + let stdin = stdin.lock(); + + let mut lines = stdin.lines().map(Result::unwrap); + let tri_count = lines.next().unwrap().parse().unwrap(); + let mut tris = Vec::with_capacity(tri_count); + + for _ in 0..tri_count { + let line = lines.next().unwrap(); + let n = line + .trim() + .split(' ') + .skip(1) + .map(|x| x.parse::().unwrap()) + .collect::>(); + tris.push([[n[0],n[1]],[n[2],n[3]],[n[4],n[5]]].into()); + } + + tris +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..c297819 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,71 @@ +use geo::Triangle; + +use std::cmp; +use std::collections::BinaryHeap; + +mod display; +mod input; + +#[derive(Debug, Clone)] +struct World { + /// Dreiecksgrundstücke + tris: Vec>, + /// Gesamtabstand + width: f64, +} +impl cmp::PartialEq for World { + fn eq(&self, _other: &Self) -> bool { + unimplemented!() + } +} +impl cmp::Eq for World {} +impl cmp::Ord for World { + fn cmp(&self, other: &Self) -> cmp::Ordering { + self.width.partial_cmp(&other.width).unwrap() + } +} +impl cmp::PartialOrd for World { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +fn main() { + let tris = input::read_input(); + let tris = transformations(&tris); + + /* + let save_prefix = "tri_"; + let mut save_counter = 0; + for t in tris { + display::save_tri(&format!("{}{}.svg", save_prefix, save_counter), t); + save_counter += 1; + } + */ + + let mut worlds = BinaryHeap::new(); + worlds.push(World { tris: vec![], width: 0.0 }); + + let mut best_width = f64::consts::MAX; + let mut best = vec![]; + +} + +fn transformations(tris: &[Triangle]) -> Vec> { + let mut new = Vec::with_capacity(tris.len() * 6); + for t in tris { + let n = Triangle((0.0, 0.0).into(), (t.1.x - t.0.x, t.1.y - t.0.y).into(), (t.2.x - t.0.x, t.2.y - t.0.y).into()); + new.push(n); + let n = [[-n.0.x, n.0.y], [-n.1.x, n.1.y], [-n.2.x, n.2.y]].into(); + new.push(n); + let n = Triangle((0.0, 0.0).into(), (t.0.x - t.1.x, t.0.y - t.1.y).into(), (t.2.x - t.1.x, t.2.y - t.1.y).into()); + new.push(n); + let n = [[-n.0.x, n.0.y], [-n.1.x, n.1.y], [-n.2.x, n.2.y]].into(); + new.push(n); + let n = Triangle((0.0, 0.0).into(), (t.0.x - t.2.x, t.0.y - t.2.y).into(), (t.1.x - t.2.x, t.1.y - t.2.y).into()); + new.push(n); + let n = [[-n.0.x, n.0.y], [-n.1.x, n.1.y], [-n.2.x, n.2.y]].into(); + new.push(n); + } + new +}