-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c26b44
commit 37a29e2
Showing
17 changed files
with
598 additions
and
186 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::bones::Distance; | ||
use graphviz_rust::{ | ||
cmd::{CommandArg, Format}, | ||
exec, parse, | ||
printer::PrinterContext, | ||
}; | ||
|
||
impl Distance { | ||
pub fn graphviz(&self) -> String { | ||
let mut dot = format!("graph G{{\nlayout=neato\n"); | ||
let colors = vec!["red", "green", "blue"]; | ||
for v in self.vertices() { | ||
dot.push_str(&format!( | ||
"\tV{v} [color=\"{}\"];\n", | ||
colors[self.connections(v).len() % colors.len()] | ||
)); | ||
} | ||
|
||
for [v, u] in self.edges() { | ||
dot.push_str(&format!("\tV{v} -- V{u};\n")); | ||
} | ||
dot.push_str("}"); | ||
dot | ||
} | ||
|
||
pub fn render(&self, prefix: &str, filename: &str) { | ||
let Ok(graph) = parse(&self.graphviz()) else { | ||
log::warn!("failed to parse Graphviz"); | ||
return; | ||
}; | ||
match exec( | ||
graph, | ||
&mut PrinterContext::default(), | ||
vec![ | ||
Format::Svg.into(), | ||
CommandArg::Output(format!("{}{}", prefix, filename)), | ||
], | ||
) { | ||
Ok(_) => { | ||
log::info!("wrote graphviz svg for {filename}"); | ||
} | ||
Err(_) => { | ||
log::error!("failed to write graph to svg!"); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -10,4 +10,3 @@ pub use distance::*; | |
pub use polyhedron::*; | ||
pub use render::*; | ||
pub use shape::*; | ||
pub use vertex::*; |
Oops, something went wrong.