use fj_interop::Color;
use fj_math::Vector;
use crate::{
geometry::SurfaceGeometry,
objects::{Cycle, Face},
operations::{
build::BuildCycle, join::JoinCycle, sweep::half_edge::SweepHalfEdge,
},
Core,
};
use super::SweepCache;
pub trait SweepCycle {
fn sweep_cycle(
&self,
surface: &SurfaceGeometry,
color: Option<Color>,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
core: &mut Core,
) -> SweptCycle;
}
impl SweepCycle for Cycle {
fn sweep_cycle(
&self,
surface: &SurfaceGeometry,
color: Option<Color>,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
core: &mut Core,
) -> SweptCycle {
let path = path.into();
let mut faces = Vec::new();
let mut top_edges = Vec::new();
for bottom_half_edge_pair in self.half_edges().pairs() {
let (bottom_half_edge, bottom_half_edge_next) =
bottom_half_edge_pair;
let (side_face, top_edge) = bottom_half_edge.sweep_half_edge(
bottom_half_edge_next.start_vertex().clone(),
surface,
color,
path,
cache,
core,
);
faces.push(side_face);
top_edges.push((
top_edge,
core.layers.geometry.of_half_edge(bottom_half_edge).path,
bottom_half_edge.boundary(),
));
}
let top_cycle = Cycle::empty().add_joined_edges(top_edges, core);
SweptCycle { faces, top_cycle }
}
}
pub struct SweptCycle {
pub faces: Vec<Face>,
pub top_cycle: Cycle,
}