-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(clippy): apply auto fix and manual fixes
- Loading branch information
Showing
2 changed files
with
48 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,62 @@ | ||
pub mod universe { | ||
use bevy::prelude::{debug, Res}; | ||
use petgraph::prelude::*; | ||
use bevy::prelude::{debug, Res}; | ||
use petgraph::prelude::*; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct Galaxy(Vec<u32>); | ||
#[derive(Debug, Default)] | ||
pub struct Galaxy(Vec<u32>); | ||
|
||
impl Galaxy { | ||
pub fn new() -> Self { | ||
Galaxy::default() | ||
} | ||
|
||
pub fn from_file(_file_path: &str) -> Self { | ||
println!("TODO: Load Galaxy from file"); | ||
let graph = random_graph(5, EdgeProbability(0.9)); | ||
println!("Random graph generated: {:?}", graph); | ||
Galaxy::new() | ||
} | ||
impl Galaxy { | ||
pub fn new() -> Self { | ||
Galaxy::default() | ||
} | ||
|
||
#[allow(dead_code)] | ||
#[derive(Debug, Default)] | ||
pub struct SolarSystem { | ||
star: String, | ||
planets: Vec<Planet>, | ||
pub fn from_file(_file_path: &str) -> Self { | ||
println!("TODO: Load Galaxy from file"); | ||
let graph = random_graph(5, EdgeProbability(0.9)); | ||
println!("Random graph generated: {:?}", graph); | ||
Galaxy::new() | ||
} | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
struct Planet((String, Option<Vec<Station>>)); | ||
#[allow(dead_code)] | ||
#[derive(Debug, Default)] | ||
pub struct SolarSystem { | ||
star: String, | ||
planets: Vec<Planet>, | ||
} | ||
|
||
#[derive(Debug, Default)] | ||
struct Station(String); | ||
#[derive(Debug, Default)] | ||
struct Planet((String, Option<Vec<Station>>)); | ||
|
||
#[derive(Debug, Default)] | ||
struct EdgeProbability(f32); | ||
#[derive(Debug, Default)] | ||
struct Station(String); | ||
|
||
#[allow(dead_code)] | ||
impl EdgeProbability { | ||
fn new(p: f32) -> Self { | ||
EdgeProbability(p.clamp(0., 1.)) | ||
} | ||
#[derive(Debug, Default)] | ||
struct EdgeProbability(f32); | ||
|
||
fn get(&self) -> f32 { | ||
self.0 | ||
} | ||
#[allow(dead_code)] | ||
impl EdgeProbability { | ||
fn new(p: f32) -> Self { | ||
EdgeProbability(p.clamp(0., 1.)) | ||
} | ||
|
||
pub fn debug_universe(universe: Res<Galaxy>) { | ||
debug!("Debug Universe {:?}", universe); | ||
fn get(&self) -> f32 { | ||
self.0 | ||
} | ||
} | ||
|
||
pub fn debug_universe(universe: Res<Galaxy>) { | ||
debug!("Debug Universe {:?}", universe); | ||
} | ||
|
||
fn random_graph(order: u32, probability: EdgeProbability) -> UnGraph<u32, ()> { | ||
let mut edges = Vec::<(u32, u32)>::new(); | ||
for i in 0..=order { | ||
for j in i..=order { | ||
if i != j { | ||
if rand::random::<f32>() < probability.get() { | ||
edges.push((i, j)); | ||
} | ||
} | ||
fn random_graph(order: u32, probability: EdgeProbability) -> UnGraph<u32, ()> { | ||
let mut edges = Vec::<(u32, u32)>::new(); | ||
for i in 0..=order { | ||
for j in i..=order { | ||
if i != j && rand::random::<f32>() < probability.get() { | ||
edges.push((i, j)); | ||
} | ||
} | ||
|
||
UnGraph::from_edges(edges) | ||
} | ||
|
||
UnGraph::from_edges(edges) | ||
} |