Struct fj_kernel::algorithms::approx::cycle::CycleApprox
source · pub struct CycleApprox {
pub half_edges: Vec<HalfEdgeApprox>,
}Expand description
An approximation of a Cycle
Fields§
§half_edges: Vec<HalfEdgeApprox>The approximated edges that make up the approximated cycle
Implementations§
source§impl CycleApprox
impl CycleApprox
sourcepub fn points(&self) -> Vec<ApproxPoint<2>>
pub fn points(&self) -> Vec<ApproxPoint<2>>
Compute the points that approximate the cycle
Examples found in repository?
More examples
src/algorithms/approx/cycle.rs (line 60)
57 58 59 60 61 62 63 64 65 66 67 68 69 70
pub fn segments(&self) -> Vec<Segment<3>> {
let mut segments = Vec::new();
for segment in self.points().windows(2) {
// This can't panic, as we passed `2` to `windows`. Can be cleaned
// up, once `array_windows` is stable.
let segment = [&segment[0], &segment[1]];
segments
.push(Segment::from(segment.map(|point| point.global_form)));
}
segments
}src/algorithms/triangulate/mod.rs (line 50)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
fn triangulate_into_mesh(self, mesh: &mut Mesh<Point<3>>) {
let face_as_polygon = Polygon::new()
.with_exterior(
self.exterior
.points()
.into_iter()
.map(|point| point.local_form),
)
.with_interiors(self.interiors.iter().map(|interior| {
interior.points().into_iter().map(|point| point.local_form)
}));
let cycles = [self.exterior].into_iter().chain(self.interiors);
let mut triangles =
delaunay::triangulate(cycles, self.coord_handedness);
triangles.retain(|triangle| {
face_as_polygon
.contains_triangle(triangle.map(|point| point.point_surface))
});
for triangle in triangles {
let points = triangle.map(|point| point.point_global);
mesh.push_triangle(points, self.color);
}
}src/algorithms/triangulate/delaunay.rs (line 22)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
pub fn triangulate(
cycles: impl IntoIterator<Item = CycleApprox>,
coord_handedness: Handedness,
) -> Vec<[TriangulationPoint; 3]> {
use spade::Triangulation as _;
let mut triangulation = spade::ConstrainedDelaunayTriangulation::<_>::new();
let mut points = BTreeMap::new();
for cycle_approx in cycles {
let mut handle_prev = None;
for point in cycle_approx.points() {
let handle = match points.get(&point) {
Some(handle) => *handle,
None => {
let handle = triangulation
.insert(TriangulationPoint {
point_surface: point.local_form,
point_global: point.global_form,
})
.expect("Inserted invalid point into triangulation");
points.insert(point, handle);
handle
}
};
if let Some(handle_prev) = handle_prev {
triangulation.add_constraint(handle_prev, handle);
}
handle_prev = Some(handle);
}
}
let mut triangles = Vec::new();
for triangle in triangulation.inner_faces() {
let [v0, v1, v2] = triangle.vertices().map(|vertex| *vertex.data());
let triangle_winding = Triangle::<2>::from_points([
v0.point_surface,
v1.point_surface,
v2.point_surface,
])
.expect("invalid triangle")
.winding();
let required_winding = match coord_handedness {
Handedness::LeftHanded => Winding::Cw,
Handedness::RightHanded => Winding::Ccw,
};
let triangle = if triangle_winding == required_winding {
[v0, v1, v2]
} else {
[v0, v2, v1]
};
triangles.push(triangle);
}
triangles
}Trait Implementations§
source§impl Debug for CycleApprox
impl Debug for CycleApprox
source§impl Hash for CycleApprox
impl Hash for CycleApprox
source§impl Ord for CycleApprox
impl Ord for CycleApprox
source§fn cmp(&self, other: &CycleApprox) -> Ordering
fn cmp(&self, other: &CycleApprox) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<CycleApprox> for CycleApprox
impl PartialEq<CycleApprox> for CycleApprox
source§fn eq(&self, other: &CycleApprox) -> bool
fn eq(&self, other: &CycleApprox) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl PartialOrd<CycleApprox> for CycleApprox
impl PartialOrd<CycleApprox> for CycleApprox
source§fn partial_cmp(&self, other: &CycleApprox) -> Option<Ordering>
fn partial_cmp(&self, other: &CycleApprox) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl Eq for CycleApprox
impl StructuralEq for CycleApprox
impl StructuralPartialEq for CycleApprox
Auto Trait Implementations§
impl !RefUnwindSafe for CycleApprox
impl !Send for CycleApprox
impl !Sync for CycleApprox
impl Unpin for CycleApprox
impl !UnwindSafe for CycleApprox
Blanket Implementations§
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.