cabel-movement (#3)
Cable Movemnt is finished. grid is hard coded Reviewed-on: #3 Co-authored-by: Glaeder <niklas@vousten.dev> Co-committed-by: Glaeder <niklas@vousten.dev>
This commit is contained in:
parent
576b21d8b9
commit
5a4451d6a7
9 changed files with 377 additions and 25 deletions
69
src/activities/house/grid.rs
Normal file
69
src/activities/house/grid.rs
Normal file
|
@ -0,0 +1,69 @@
|
|||
use comfy::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Grid {
|
||||
pub nodes: Vec<Vec2>,
|
||||
pub connections: Vec<(usize, usize)>
|
||||
}
|
||||
|
||||
impl Default for Grid {
|
||||
fn default() -> Self {
|
||||
Grid::load() //Just for testing purposes
|
||||
}
|
||||
}
|
||||
|
||||
impl Grid {
|
||||
fn load() -> Self {
|
||||
let mut grid = Self {
|
||||
nodes: vec![
|
||||
vec2(10.0, 0.0),
|
||||
vec2(0.0, 0.0),
|
||||
vec2(0.0, 10.0),
|
||||
vec2(-10.0, 0.0),
|
||||
vec2(10.0, 10.0),
|
||||
],
|
||||
connections: vec![(0, 1), (1, 2), (1, 3), (0, 4), (0, 5), (5, 1), (6, 7)]
|
||||
};
|
||||
|
||||
grid.sanitize();
|
||||
|
||||
grid
|
||||
}
|
||||
|
||||
fn sanitize(&mut self) {
|
||||
let mut len = self.nodes.len();
|
||||
let connections = self
|
||||
.connections
|
||||
.iter()
|
||||
.filter(|(conn_i1, conn_i2)| {
|
||||
if conn_i1 >= &mut len || conn_i2 >= &mut len {
|
||||
error!("Connection in grid not possible {:?}", (conn_i1, conn_i2));
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
.map(|(conn_i1, conn_i2)| (*conn_i1, *conn_i2))
|
||||
.collect();
|
||||
|
||||
self.connections = connections;
|
||||
}
|
||||
|
||||
pub fn draw(&self) {
|
||||
//Draw Grid
|
||||
for node in &self.nodes {
|
||||
draw_circle(*node, 0.25, BLUE, 0);
|
||||
}
|
||||
for (conn_i1, conn_i2) in &self.connections {
|
||||
let node_1 = self.nodes.get(*conn_i1);
|
||||
let node_2 = self.nodes.get(*conn_i2);
|
||||
|
||||
if node_1.is_none() || node_2.is_none() {
|
||||
error!("Connection in grid not available {:?}", (conn_i1, conn_i2));
|
||||
continue;
|
||||
}
|
||||
|
||||
draw_line(*node_1.unwrap(), *node_2.unwrap(), 0.1, BLUE, 0);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue