Move point conversion out of Polygon

It doesn't need to know about any of that. That it does, only makes
testing it more complicated.
This commit is contained in:
Hanno Braun 2022-04-09 15:02:02 +02:00
parent 6d3e738b65
commit 02643a735f
2 changed files with 23 additions and 17 deletions

View File

@ -35,13 +35,23 @@ pub fn triangulate(
})
.collect();
let face_as_polygon = Polygon::new(surface)
.with_exterior(approx.exterior.points)
.with_interiors(
approx
.interiors
.into_iter()
.map(|interior| interior.points),
);
.with_exterior(approx.exterior.points.into_iter().map(
|point| {
// Can't panic, unless the approximation wrongfully
// generates points that are not in the surface.
surface.point_model_to_surface(point).native()
},
))
.with_interiors(approx.interiors.into_iter().map(
|interior| {
interior.points.into_iter().map(|point| {
// Can't panic, unless the approximation
// wrongfully generates points that are not in
// the surface.
surface.point_model_to_surface(point).native()
})
},
));
let mut triangles = delaunay(points);
triangles.retain(|triangle| {

View File

@ -22,13 +22,13 @@ impl Polygon {
}
}
pub fn with_exterior(self, exterior: impl Into<PolyChain<3>>) -> Self {
pub fn with_exterior(self, exterior: impl Into<PolyChain<2>>) -> Self {
self.with_approx(exterior)
}
pub fn with_interiors(
mut self,
interiors: impl IntoIterator<Item = impl Into<PolyChain<3>>>,
interiors: impl IntoIterator<Item = impl Into<PolyChain<2>>>,
) -> Self {
for interior in interiors {
self = self.with_approx(interior);
@ -37,18 +37,14 @@ impl Polygon {
self
}
fn with_approx(mut self, approx: impl Into<PolyChain<3>>) -> Self {
fn with_approx(mut self, approx: impl Into<PolyChain<2>>) -> Self {
for segment in approx.into().segments() {
let segment = segment.points().map(|point| {
// Can't panic, unless the approximation wrongfully generates
// points that are not in the surface.
let point = self.surface.point_model_to_surface(point);
if point.native() > self.max {
self.max = point.native();
if point > self.max {
self.max = point;
}
point.native()
point
});
let edge = Segment::from(segment);