Skip to content

Commit

Permalink
Single dimension (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
organizedgrime authored Dec 1, 2024
1 parent 36fc682 commit 3762a61
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 383 deletions.
2 changes: 1 addition & 1 deletion src/polyhedron/conway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Polyhedron {
log::info!(
"p: {}, d: {}",
self.render.positions.len(),
self.shape.len()
self.shape.order()
);
}

Expand Down
17 changes: 3 additions & 14 deletions src/polyhedron/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use render::*;
use shape::*;
pub use transaction::*;

// #[cfg(test)]
// mod test;
#[cfg(test)]
mod test;

use std::{
collections::HashMap,
Expand Down Expand Up @@ -156,7 +156,7 @@ impl Polyhedron {
]
}
};
self.render.new_capacity(self.shape.len());
self.render.new_capacity(self.shape.order());
self.transactions = [new_transactions, self.transactions.clone()].concat();
}
Name(c) => {
Expand Down Expand Up @@ -223,17 +223,6 @@ impl Polyhedron {
}
}

// pub fn preset(preset: &PresetMessage) -> Polyhedron {
// let shape = Shape::preset(preset);
// let render = Render::new(shape.len());
// Polyhedron {
// name: preset.to_string(),
// shape,
// render,
// transactions: vec![],
// }
// }

pub fn face_centroid(&self, face_index: usize) -> Vec3 {
// All vertices associated with this face
self.shape.cycles[face_index]
Expand Down
47 changes: 21 additions & 26 deletions src/polyhedron/platonic.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use super::*;
use PresetMessage::*;

impl Polyhedron {
pub fn preset(preset: &PresetMessage) -> Polyhedron {
use PresetMessage::*;
let mut poly = match preset {
Octahedron => Self::octahedron(),
Dodecahedron => Self::dodecahedron(),
Icosahedron => todo!(),
Dodecahedron => todo!(),
Icosahedron => Self::icosahedron(),
_ => {
let shape = match preset {
Prism(n) => Shape::prism(*n),
Expand All @@ -15,7 +16,7 @@ impl Polyhedron {
_ => todo!(),
};

let render = Render::new(shape.len());
let render = Render::new(shape.order());

Polyhedron {
name: preset.to_string(),
Expand All @@ -30,32 +31,26 @@ impl Polyhedron {
}

fn octahedron() -> Polyhedron {
let mut polyhedron = Polyhedron::preset(&PresetMessage::Pyramid(3));
let mut polyhedron = Polyhedron::preset(&Pyramid(3));
polyhedron.ambo_contract();
polyhedron
}

fn dodecahedron() -> Polyhedron {
// polyhedron.ambo_contract();
// let edges = polyhedron.truncate(0);
//polyhedron.contract(edges);
// polyhedron.truncate(5);
Polyhedron::preset(&PresetMessage::AntiPrism(5))
}
/* pub fn dodecahedron() -> Polyhedron {
let mut p = Polyhedron::preset(&AntiPrism(5));
let edges = p.expand(false);
p.contract_edges(edges);
p.truncate(Some(5));
p.pst();
p.springs();
p.name = "D".into();
p
} */

//
// pub fn icosahedron() -> Distance {
// let mut graph = Distance::anti_prism(5);
// graph.kis(Some(5));
// graph
// }
//
// pub fn icosahedron() -> Distance {
// let dodecahedron = Self::dodecahedron();
// //let edges = dodecahedron.ambo();
// //dodecahedron.contract_edges(edges);
// #[cfg(test)]
// dodecahedron.render("tests/", "icosahedron.svg");
// dodecahedron
// }
pub fn icosahedron() -> Polyhedron {
let mut graph = Polyhedron::preset(&AntiPrism(5));
graph.shape.kis(Some(5));
graph.render.new_capacity(graph.shape.order());
graph
}
}
29 changes: 19 additions & 10 deletions src/polyhedron/shape/conway.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Cycles, Shape};
use super::{Cycle, Cycles, Shape};
use crate::polyhedron::VertexId;

impl Shape {
Expand All @@ -11,20 +11,29 @@ impl Shape {

pub fn contract_edges(&mut self, edges: Vec<[VertexId; 2]>) {
self.distance.contract_edges(edges);
// Delete a
// for
// for i in 0..self.cycles.len() {
// self.cycles[i].replace(v, u);
// }
self.recompute();
}

#[allow(dead_code)]
pub fn kis(&mut self, degree: Option<usize>) -> Vec<[VertexId; 2]> {
let edges = self.distance.edges().collect();
// let mut cycles = self.cycles.clone();
if let Some(degree) = degree {
self.cycles
.iter()
.collect::<Vec<_>>()
.retain(|c| c.len() == degree);
}
for cycle in self.cycles.iter() {
let cycles: Vec<&Cycle> = self
.cycles
.iter()
.filter(move |cycle| {
if let Some(degree) = degree {
cycle.len() == degree
} else {
true
}
})
.collect();

for cycle in cycles {
let v = self.distance.insert();
// let mut vpos = Vec3::zero();

Expand Down
54 changes: 6 additions & 48 deletions src/polyhedron/shape/cycles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,79 +139,37 @@ impl From<&Distance> for Cycles {
fn from(distance: &Distance) -> Self {
let mut triplets: Vec<Vec<_>> = Default::default();
let mut cycles: HashSet<Vec<_>> = Default::default();
// let mut edge_incidents: Distance = distance.clone();
// for [v, u] in edge_incidents.vertex_pairs() {
// if edge_incidents[[v, u]] == 1 {
// edge_incidents[[v, u]] = 0;
// } else {
// edge_incidents[[v, u]] = usize::MAX;
// }
// }
// println!("distance:\n{distance}");
// println!("edge_incidents_starting:\n{edge_incidents}");

// find all the triplets
for u in 0..distance.len() {
for x in (u + 1)..distance.len() {
for y in (x + 1)..distance.len() {
for u in 0..distance.order() {
for x in (u + 1)..distance.order() {
for y in (x + 1)..distance.order() {
if distance[[u, x]] == 1 && distance[[u, y]] == 1 {
if distance[[x, y]] == 1 {
cycles.insert(vec![x, u, y]);
// edge_incidents[[x, u]] += 1;
// edge_incidents[[u, y]] += 1;
// edge_incidents[[y, x]] += 1;
} else {
triplets.push(vec![x, u, y]);
}
}
}
}
}
// find all the triplets
// for u in distance.vertices() {
// let adj: Vec<VertexId> = distance.connections(u);
// for &x in adj.iter() {
// for &y in adj.iter() {
// if u < x && x < y {
// let new_face = vec![x, u, y];
// if distance[[x, y]] == 1 {
// cycles.insert(new_face);
// } else {
// triplets.push(new_face);
// }
// }
// }
// }
// }
// println!("triplets:\n{triplets:?}");
// println!("cycles:\n{cycles:?}");

// while there are unparsed triplets
while !triplets.is_empty() && (cycles.len() as i64) < distance.face_count() {
let p = triplets.remove(0);

// for each v adjacent to u_t
for v in distance.connections(p[p.len() - 1]) {
for v in distance.neighbors(p[p.len() - 1]) {
if v > p[1] {
let adj_v = distance.connections(v);
let adj_v = distance.neighbors(v);
// if v is not a neighbor of u_2..u_t-1
if !p[1..p.len() - 1].iter().any(|i| adj_v.contains(i)) {
// let mut new_face = p.clone();
// new_face.push(v);
let new = [p.clone(), vec![v]].concat();
if distance.connections(p[0]).contains(&v) {
// if edge_incidents[[p[0], v]] >= 2 {
// log::info!("i was about to send {new:?} but [{}, {}] is already greater than 2", p[0], v)
// } else {
// for i in 0..new.len() {
// edge_incidents[[new[i], new[(i + 1) % new.len()]]] += 1;
// }
if distance.neighbors(p[0]).contains(&v) {
if distance.cycle_is_face(new.clone()) {
cycles.insert(new);
} else {
// println!("i was going to insert {new:?} but it's not a valid face");
}
// }
} else {
triplets.push(new);
}
Expand Down
74 changes: 1 addition & 73 deletions src/polyhedron/shape/distance/conway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,25 @@ use crate::polyhedron::VertexId;
impl Distance {
pub(super) fn contract_edge(&mut self, [v, u]: [VertexId; 2]) {
// Give u all the same connections as v
for w in self.connections(v).into_iter() {
for w in self.neighbors(v).into_iter() {
self.connect([w, u]);
self.disconnect([w, v]);
}

// // Delete a
// for cycle in self.cycles.iter_mut() {
// cycle.replace(v, u);
// }

// Delete v
self.delete(v);
}

pub fn contract_edges(&mut self, mut edges: Vec<[VertexId; 2]>) {
// let mut transformed = HashSet::default();
while !edges.is_empty() {
// Pop an edge
let [w, x] = edges.remove(0);
let v = w.max(x);
let u = w.min(x);

// // If this is not a redundant edge
// if !(transformed.contains(&v) && transformed.contains(&u)) {

// Contract [v, u], deleting v
self.contract_edge([v, u]);

// // Mark that this vertex has been transformed
// transformed.insert(v);

// Decrement the value of every vertex
for [x, w] in &mut edges {
if *x > v {
Expand All @@ -48,19 +36,6 @@ impl Distance {
}
}

// pub fn contract_edges(&mut self, mut edges: Vec<[VertexId; 2]>) {
// let mut map = HashMap::<VertexId, VertexId>::default();
// for [v, u] in edges.into_iter() {
// let u = *map.get(&u).unwrap_or(&u);
// let v = *map.get(&v).unwrap_or(&v);
// if v != u {
// //self.contract_edge([v, u]);
// map.insert(v, u);
// }
// }
// println!("map: {map:?}");
// }

pub fn split_vertex(&mut self, v: VertexId, connections: Vec<VertexId>) -> Vec<[VertexId; 2]> {
// Remove the vertex
let new_cycle: Cycle = Cycle::from(
Expand Down Expand Up @@ -89,53 +64,6 @@ impl Distance {
new_edges
}

pub fn cycle_is_face(&self, mut cycle: Vec<VertexId>) -> bool {
let mut dupe = self.clone();
while !cycle.is_empty() {
let v = cycle.remove(0);
dupe.delete(v);
for u in &mut cycle {
if *u > v {
*u -= 1;
}
}
}
dupe.is_connected()
}

// //
// pub fn ordered_face_indices(&self, v: VertexId) -> Vec<usize> {
// let relevant = (0..self.cycles.len())
// .filter(|&i| self.cycles[i].containz(&v))
// .collect::<Vec<usize>>();
//
// let mut edges = HashMap::default();
//
// for &i in relevant.iter() {
// let ui = self.cycles[i].iter().position(|&x| x == v).unwrap();
// let flen = self.cycles[i].len();
// // Find the values that came before and after in the face
// let a = self.cycles[i][(ui + flen - 1) % flen];
// let b = self.cycles[i][(ui + 1) % flen];
// edges.insert((a, b).into(), i);
// }
//
// let f: Cycle = edges.keys().cloned().collect::<Vec<_>>().into();
//
// let mut ordered_face_indices = vec![];
// for i in 0..f.len() {
// let ev = f[i];
// let eu = f[(i + 1) % f.len()];
// let fi = edges
// .get(&[ev, eu])
// .unwrap_or(edges.get(&[eu, ev]).unwrap());
// ordered_face_indices.push(*fi);
// }
//
// ordered_face_indices
// }
// //

// /// `e` = `aa`

//
Expand Down
Loading

0 comments on commit 3762a61

Please sign in to comment.