I don't even know anymore
This commit is contained in:
parent
730bf3b77b
commit
5de64353c2
39
Cargo.lock
generated
39
Cargo.lock
generated
@ -2,7 +2,7 @@
|
||||
name = "aufgabe2"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"geo 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"geo 0.12.0",
|
||||
"svg 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -65,22 +65,20 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "geo"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
version = "0.12.0"
|
||||
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)",
|
||||
"geo-types 0.4.0",
|
||||
"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)",
|
||||
"rstar 0.2.0 (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"
|
||||
version = "0.4.0"
|
||||
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)",
|
||||
"rstar 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -93,6 +91,14 @@ name = "num-traits"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pdqselect"
|
||||
version = "0.1.0"
|
||||
@ -116,11 +122,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rstar"
|
||||
version = "0.1.1"
|
||||
version = "0.2.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)",
|
||||
"pdqselect 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -154,6 +161,14 @@ dependencies = [
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "threadpool"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.1.0"
|
||||
@ -186,18 +201,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"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 num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba"
|
||||
"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 rstar 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "120bfe4837befb82c5a637a5a8c490a27d25524ac19fffec5b4e555ca6e36ee8"
|
||||
"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 threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865"
|
||||
"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"
|
||||
|
@ -5,5 +5,5 @@ authors = ["Arne Keller <arne.keller01@yahoo.de>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
geo = "0.11.0"
|
||||
geo = { path = "../../../Code/Github/geo/geo" }
|
||||
svg = "0.5.12"
|
||||
|
61
src/main.rs
61
src/main.rs
@ -1,4 +1,5 @@
|
||||
use geo::{Coordinate, Triangle};
|
||||
use geo::prelude::*;
|
||||
|
||||
use std::cmp;
|
||||
use std::collections::BinaryHeap;
|
||||
@ -23,7 +24,7 @@ impl cmp::PartialEq for World {
|
||||
impl cmp::Eq for World {}
|
||||
impl cmp::Ord for World {
|
||||
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
||||
self.width.partial_cmp(&other.width).unwrap()
|
||||
self.width.partial_cmp(&other.width).unwrap().reverse()
|
||||
}
|
||||
}
|
||||
impl cmp::PartialOrd for World {
|
||||
@ -34,6 +35,7 @@ impl cmp::PartialOrd for World {
|
||||
|
||||
fn main() {
|
||||
let tris = input::read_input();
|
||||
let count_tris = tris.len();
|
||||
let tris = transformations(&tris);
|
||||
|
||||
let save_prefix = "tri_";
|
||||
@ -124,18 +126,17 @@ fn main() {
|
||||
worlds.push(world);
|
||||
}
|
||||
|
||||
let mut best_width = f64::MAX;
|
||||
//let mut best = vec![];
|
||||
let mut best = World { tris: vec![], width: f64::MAX };
|
||||
let save_prefix = "world_";
|
||||
let mut save_counter = 0;
|
||||
while worlds.peek().map(|x| x.width < best_width) == Some(true) {
|
||||
while worlds.peek().map(|x| x.width <= best.width) == Some(true) {
|
||||
let w = worlds.pop().unwrap();
|
||||
println!("s: {:?}", w);
|
||||
//println!("s: {:?}", w);
|
||||
|
||||
let mut new = vec![];
|
||||
for (next_idx, next_tri) in left_tris.iter()
|
||||
.filter(|(idx1, _tri)| w.tris.iter().all(|(idx2, _tri)| idx1 != idx2)) {
|
||||
println!("trying {:?}", next_idx);
|
||||
//println!("trying {:?}", next_idx);
|
||||
let (_, last_tri) = *w.tris.last().unwrap();
|
||||
let last_vertex = if last_tri.1.y > 0.01 && !(last_tri.2.y > 0.01 && last_tri.2.x > last_tri.1.x) {
|
||||
last_tri.1
|
||||
@ -143,7 +144,7 @@ fn main() {
|
||||
last_tri.2
|
||||
};
|
||||
let mut free_angle = angle_of(last_tri, last_vertex);
|
||||
println!("angle of {:?}: {:?}", last_vertex, free_angle);
|
||||
//println!("angle of {:?}: {:?}", last_vertex, free_angle);
|
||||
if last_vertex.x > 0.0 {
|
||||
free_angle = 0.5*PI - free_angle;
|
||||
} else {
|
||||
@ -165,31 +166,67 @@ fn main() {
|
||||
// easy: just rotate to fit and put it below the last triangle
|
||||
let mut w = w.clone();
|
||||
w.tris.push((*next_idx, rotate(*next_tri, free_angle - next_angle)));
|
||||
println!("new {:?} {:?} {:?}: {:?}", save_counter, free_angle, next_angle, w);
|
||||
//println!("new {:?} {:?} {:?}: {:?}", save_counter, free_angle, next_angle, w);
|
||||
w.normalize();
|
||||
w.calc_width();
|
||||
if save_counter < 100 {
|
||||
display::save_world(&format!("{}{}.svg", save_prefix, save_counter), &w);
|
||||
}
|
||||
if w.tris.len() == count_tris {
|
||||
if w.width < best.width {
|
||||
println!("new best: {}", w.width);
|
||||
best = w;
|
||||
}
|
||||
} else {
|
||||
new.push(w);
|
||||
}
|
||||
save_counter += 1;
|
||||
} else {
|
||||
// "hard": move it right till it fits
|
||||
println!("error: doesn't fit");
|
||||
print!("error: doesn't fit [S{} {}]", w.tris.len(), save_counter);
|
||||
assert!(last_tri.intersects(next_tri));
|
||||
let mut next_tri = *next_tri;
|
||||
while last_tri.intersects(&next_tri) {
|
||||
next_tri.0.x += 0.005;
|
||||
next_tri.1.x += 0.005;
|
||||
next_tri.2.x += 0.005;
|
||||
}
|
||||
let mut w = w.clone();
|
||||
w.tris.push((*next_idx, next_tri));
|
||||
w.normalize();
|
||||
w.calc_width();
|
||||
println!(" -> width = {}", w.width);
|
||||
if save_counter < 100 {
|
||||
display::save_world(&format!("{}{}.svg", save_prefix, save_counter), &w);
|
||||
}
|
||||
if w.tris.len() == count_tris {
|
||||
if w.width < best.width {
|
||||
println!("new best: {}", w.width);
|
||||
best = w;
|
||||
}
|
||||
} else {
|
||||
new.push(w);
|
||||
}
|
||||
save_counter += 1;
|
||||
}
|
||||
}
|
||||
worlds.extend(new);
|
||||
}
|
||||
println!("best width = {:?}", best.width);
|
||||
display::save_world("world_best.svg", &best);
|
||||
}
|
||||
|
||||
impl World {
|
||||
fn normalize(&mut self) {
|
||||
let mut maxx = 0.0;
|
||||
for (_, tri) in &self.tris {
|
||||
if tri.0.x > maxx {
|
||||
if tri.0.x > maxx && tri.0.y < 0.01 && tri.0.y > -0.01 {
|
||||
maxx = tri.0.x;
|
||||
}
|
||||
if tri.1.x > maxx {
|
||||
if tri.1.x > maxx && tri.1.y < 0.01 && tri.1.y > -0.01 {
|
||||
maxx = tri.1.x;
|
||||
}
|
||||
if tri.2.x > maxx {
|
||||
if tri.2.x > maxx && tri.2.y < 0.01 && tri.2.y > -0.01 {
|
||||
maxx = tri.2.x;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user