Skip to content

Commit

Permalink
updating stuff!
Browse files Browse the repository at this point in the history
  • Loading branch information
organizedgrime committed Nov 4, 2024
1 parent 4c26b44 commit 37a29e2
Show file tree
Hide file tree
Showing 17 changed files with 598 additions and 186 deletions.
431 changes: 343 additions & 88 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ serde = { version = "^1.0.0", features = ["derive"] }
ron = { version = "0.8" }
#ckmeans = { version = "1.0.6" }
webbrowser = { version = "1.0.2" }
iced_winit = { version = "0.13" }
iced_winit = { version = "0.13", default-features = false, features = ["x11"] }
iced_widget = { version = "0.13", features = ["wgpu"] }
iced_wgpu = { version = "0.13", features = ["webgl"] }
log = { version = "0.4.22" }
rustc-hash = { version = "2.0.0" }
graphviz-rust = { version = "0.9.3" }

[dev-dependencies]
test-case = { version = "^3.3.0" }
graphviz-rust = { version = "0.9.3" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
iced = { version = "0.13", features = ["debug", "advanced", "svg"] }
Expand Down
173 changes: 173 additions & 0 deletions current.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 8 additions & 9 deletions src/bones/polyhedron/cycles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Cycles {
impl Cycles {
pub fn new(cycles: Vec<Vec<VertexId>>) -> Self {
Self {
cycles: cycles.into_iter().map(|cycle| Cycle(cycle)).collect(),
cycles: cycles.into_iter().map(Cycle).collect(),
}
}

Expand Down Expand Up @@ -54,24 +54,23 @@ impl Cycle {
}

pub fn delete(&mut self, v: VertexId) {
(*self).0 = self
self.0 = self
.0
.clone()
.into_iter()
.filter_map(|u| {
if v == u {
None
} else if u > v {
Some(u - 1)
} else {
Some(u)
use std::cmp::Ordering::*;
match v.cmp(&u) {
Equal => None,
Less => Some(u - 1),
Greater => Some(u),
}
})
.collect::<Vec<_>>();
}

pub fn replace(&mut self, old: VertexId, new: VertexId) {
(*self).0 = self
self.0 = self
.0
.clone()
.into_iter()
Expand Down
6 changes: 2 additions & 4 deletions src/bones/polyhedron/distance/conway.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
use std::collections::VecDeque;
use ultraviolet::Vec3;
use rustc_hash::FxHashSet as HashSet;

use crate::bones::*;

Expand Down Expand Up @@ -72,7 +70,7 @@ impl Distance {
// Remove the vertex
let new_face: Vec<(usize, usize)> = vec![v]
.into_iter()
.chain((1..connections.len()).into_iter().map(|_| self.insert()))
.chain((1..connections.len()).map(|_| self.insert()))
.zip(connections.clone())
.collect();

Expand Down
5 changes: 2 additions & 3 deletions src/bones/polyhedron/distance/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod conway;
mod platonic;
mod svg;
#[cfg(test)]
mod test;

Expand Down Expand Up @@ -31,7 +32,6 @@ impl Distance {
pub fn new(n: usize) -> Self {
Distance {
distance: (0..n)
.into_iter()
.map(|m| [vec![usize::MAX; m], vec![0]].concat())
.collect(),
}
Expand Down Expand Up @@ -80,8 +80,7 @@ impl Distance {

/// All possible compbinations of vertices
pub fn vertex_pairs(&self) -> impl Iterator<Item = [VertexId; 2]> {
self.vertices()
.flat_map(|v| (0..v).into_iter().map(move |u| [v, u]))
self.vertices().flat_map(|v| (0..v).map(move |u| [v, u]))
}

/// All actual edges of the graph (D_{ij} = 1)
Expand Down
47 changes: 47 additions & 0 deletions src/bones/polyhedron/distance/svg.rs
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!");
}
}
}
}
44 changes: 0 additions & 44 deletions src/bones/polyhedron/distance/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ use std::fs::create_dir_all;

use super::*;
use crate::render::message::PresetMessage::*;
use graphviz_rust::{
cmd::{CommandArg, Format},
exec, parse,
printer::PrinterContext,
};
use test_case::test_case;

impl Distance {
Expand Down Expand Up @@ -42,45 +37,6 @@ impl Distance {
tetra[[2, 3]] = 1;
tetra
}

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!");
}
}
}
}

#[test_case(Distance::preset(&Pyramid(3)); "T")]
Expand Down
1 change: 0 additions & 1 deletion src/bones/polyhedron/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ pub use distance::*;
pub use polyhedron::*;
pub use render::*;
pub use shape::*;
pub use vertex::*;
Loading

0 comments on commit 37a29e2

Please sign in to comment.