extern crate arrayvec;
extern crate decorum;
extern crate nalgebra;
extern crate plexus;
use decorum::R64;
use nalgebra::Point2;
use plexus::geometry::alias::VertexPosition;
use plexus::geometry::compose::EdgeMidpoint;
use plexus::geometry::convert::AsPosition;
use plexus::geometry::Geometry;
use plexus::graph::{FaceView, MeshGraph};
use plexus::prelude::*;
use plexus::primitive::Triangle;
use smallvec::SmallVec;
pub fn circumscribe<G>(face: FaceView<&mut MeshGraph<G>, G>) -> FaceView<&mut MeshGraph<G>, G>
where
G: EdgeMidpoint<Midpoint = VertexPosition<G>> + Geometry,
G::Vertex: AsPosition,
{
let arity = face.arity();
let mut arc = face.into_arc();
let mut splits = SmallVec::<[_; 4]>::with_capacity(arity);
for _ in 0..arity {
let vertex = arc.split_at_midpoint();
splits.push(vertex.key());
arc = vertex.into_outgoing_arc().into_next_arc();
}
let mut face = arc.into_face().unwrap();
for (a, b) in splits.into_iter().perimeter() {
face = face.split(ByKey(a), ByKey(b)).unwrap().into_face().unwrap();
}
face
}
fn main() {
let mut graph = MeshGraph::<Point2<R64>>::from_raw_buffers(
vec![Triangle::new(0usize, 1, 2)],
vec![(0.0, 0.0), (1.0, 0.0), (0.0, 1.0)],
)
.unwrap();
let key = graph.faces().nth(0).unwrap().key();
let _ = circumscribe(graph.face_mut(key).unwrap());
}