use num::Float;
use ph_faces::{Polyhedron, center_indexed, divide_int};
use crate::icosahedron::Icosahedron;
#[derive(Debug)]
pub struct C60<F: Float> {
pub ph: Polyhedron<F>,
pub edges: Vec<(u16, [u16; 3])>
}
impl<F: Float> C60<F> {
pub fn new(r: F) -> Self {
let icosa_e = Icosahedron::<F>::new(r); let icosa = icosa_e.ph;
let iv = &icosa.vtx;
let vtx: Vec<_> = icosa_e.edges.iter().flat_map(|&(e, is)|
is.iter().map(move |&i|
divide_int(&iv[e as usize], &iv[i as usize], 1, 2)
).collect::<Vec<_>>()
).collect(); let edges = vec![];
let hx = vec![
[3, 14, 13, 9, 8, 4], [2, 16, 15, 10, 14, 3], [1, 22, 21, 17, 16, 2], [0, 25, 29, 23, 22, 1], [4, 8, 7, 26, 25, 0], [7, 6, 32, 31, 27, 26], [5, 35, 39, 33, 32, 6], [13, 12, 36, 35, 5, 9], [11, 42, 41, 37, 36, 12], [15, 19, 43, 42, 11, 10], [18, 49, 48, 44, 43, 19], [21, 20, 45, 49, 18, 17], [24, 53, 52, 46, 45, 20], [29, 28, 54, 53, 24, 23], [27, 31, 30, 50, 54, 28], [30, 34, 58, 57, 51, 50], [39, 38, 59, 58, 34, 33], [41, 40, 55, 59, 38, 37], [48, 47, 56, 55, 40, 44], [52, 51, 57, 56, 47, 46] ];
let mut tri: Vec<_> = (0..12).into_iter().map(|q: u16| {
let o = q * 5;
vec![[o, o + 1, o + 2], [o, o + 2, o + 3], [o, o + 3, o + 4]]
}).collect();
tri.extend(hx.iter().map(|&h| vec![
[h[0], h[1], h[2]], [h[0], h[2], h[3]],
[h[0], h[3], h[4]], [h[0], h[4], h[5]]
]));
let uv = vec![];
C60{ph: Polyhedron{vtx, tri, uv, center: false}, edges}
}
}
#[derive(Debug)]
pub struct C60Center<F: Float> {
pub ph: Polyhedron<F>,
pub edges: Vec<(u16, [u16; 3])>
}
impl<F: Float> C60Center<F> {
pub fn new(r: F) -> Self {
let icosa_e = Icosahedron::<F>::new(r); let icosa = icosa_e.ph;
let iv = &icosa.vtx;
let c60_e = C60::<F>::new(r); let c60 = c60_e.ph;
let cv = &c60.vtx;
let mut vtx: Vec<_> = cv.iter().map(|&p| p).collect(); vtx.extend(icosa_e.edges.iter().map(|&(e, is)|
divide_int(&iv[e as usize], ¢er_indexed(&is, &iv), 1, 2))); vtx.extend(icosa.tri.iter().map(|t| center_indexed(&t[0], iv))); let edges = vec![];
let mut tri: Vec<_> = (60..72).into_iter().map(|q: u16| {
let mut t = Vec::with_capacity(5); let o = q as usize - 60;
t.push([q, c60.tri[o][0][0], c60.tri[o][0][1]]);
let _: Vec<_> = (0..3).into_iter().map(|p| {
t.push([q, c60.tri[o][p][1], c60.tri[o][p][2]]);
}).collect();
t.push([q, c60.tri[o][2][2], c60.tri[o][2][0]]);
t
}).collect();
tri.extend((72..92).into_iter().map(|q: u16| {
let mut t = Vec::with_capacity(6); let o = q as usize - 72 + 12;
t.push([q, c60.tri[o][0][0], c60.tri[o][0][1]]);
let _: Vec<_> = (0..4).into_iter().map(|p| {
t.push([q, c60.tri[o][p][1], c60.tri[o][p][2]]);
}).collect();
t.push([q, c60.tri[o][3][2], c60.tri[o][3][0]]);
t
}));
let uv = vec![];
C60Center{ph: Polyhedron{vtx, tri, uv, center: true}, edges}
}
}