Simplify builder method

This commit is contained in:
Hanno Braun 2023-02-17 16:47:59 +01:00
parent 0817dd3c9a
commit a7365e670e
2 changed files with 71 additions and 96 deletions

View File

@ -183,7 +183,7 @@ impl CycleBuilder for PartialCycle {
{ {
edges.map(|other| { edges.map(|other| {
let mut this = self.add_half_edge(); let mut this = self.add_half_edge();
this.write().update_from_other_edge(&other, &Some(*surface)); this.write().update_from_other_edge(&other, surface);
this this
}) })
} }

View File

@ -58,7 +58,7 @@ pub trait HalfEdgeBuilder {
fn update_from_other_edge( fn update_from_other_edge(
&mut self, &mut self,
other: &Partial<HalfEdge>, other: &Partial<HalfEdge>,
surface: &Option<SurfaceGeometry>, surface: &SurfaceGeometry,
); );
} }
@ -222,7 +222,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
fn update_from_other_edge( fn update_from_other_edge(
&mut self, &mut self,
other: &Partial<HalfEdge>, other: &Partial<HalfEdge>,
surface: &Option<SurfaceGeometry>, surface: &SurfaceGeometry,
) { ) {
let global_curve = other.read().curve.read().global_form.clone(); let global_curve = other.read().curve.read().global_form.clone();
self.curve.write().global_form = global_curve.clone(); self.curve.write().global_form = global_curve.clone();
@ -230,103 +230,78 @@ impl HalfEdgeBuilder for PartialHalfEdge {
self.curve.write().path = self.curve.write().path =
other.read().curve.read().path.as_ref().and_then(|path| { other.read().curve.read().path.as_ref().and_then(|path| {
match surface { // We have information about the other edge's surface available.
Some(surface) => { // We need to use that to interpret what the other edge's curve
// We have information about the other edge's surface // path means for our curve path.
// available. We need to use that to interpret what the match surface.u {
// other edge's curve path means for our curve path. GlobalPath::Circle(circle) => {
match surface.u { // The other surface is curved. We're entering some
GlobalPath::Circle(circle) => { // dodgy territory here, as only some edge cases can be
// The other surface is curved. We're entering // represented using our current curve/surface
// some dodgy territory here, as only some edge // representation.
// cases can be represented using our current match path {
// curve/surface representation. MaybeSurfacePath::Defined(SurfacePath::Line(_))
match path { | MaybeSurfacePath::UndefinedLine => {
MaybeSurfacePath::Defined( // We're dealing with a line on a rounded
SurfacePath::Line(_), // surface.
) //
| MaybeSurfacePath::UndefinedLine => { // Based on the current uses of this method, we
// We're dealing with a line on a // can make some assumptions:
// rounded surface. //
// // 1. The line is parallel to the u-axis of the
// Based on the current uses of this // other surface.
// method, we can make some assumptions: // 2. The surface that *our* edge is in is a
// // plane that is parallel to the the plane of
// 1. The line is parallel to the u-axis // the circle that defines the curvature of
// of the other surface. // the other surface.
// 2. The surface that *our* edge is in //
// is a plane that is parallel to the // These assumptions are necessary preconditions
// the plane of the circle that // for the following code to work. But
// defines the curvature of the other // unfortunately, I see no way to check those
// surface. // preconditions here, as neither the other line
// // nor our surface is necessarily defined yet.
// These assumptions are necessary //
// preconditions for the following code // Handling this case anyway feels like a grave
// to work. But unfortunately, I see no // sin, but I don't know what else to do. If you
// way to check those preconditions // tracked some extremely subtle and annoying
// here, as neither the other line nor // bug back to this code, I apologize.
// our surface is necessarily defined //
// yet. // I hope that I'll come up with a better curve/
// // surface representation before this becomes a
// Handling this case anyway feels like // problem.
// a grave sin, but I don't know what Some(MaybeSurfacePath::UndefinedCircle {
// else to do. If you tracked some radius: circle.radius(),
// extremely subtle and annoying bug })
// back to this code, I apologize.
//
// I hope that I'll come up with a
// better curve/surface representation
// before this becomes a problem.
Some(
MaybeSurfacePath::UndefinedCircle {
radius: circle.radius(),
},
)
}
_ => {
// The other edge is a line segment in a
// curved surface. No idea how to deal
// with this.
todo!(
"Can't connect edge to circle on \
curved surface"
)
}
}
} }
GlobalPath::Line(_) => { _ => {
// The other edge is defined on a plane. // The other edge is a line segment in a curved
match path { // surface. No idea how to deal with this.
MaybeSurfacePath::Defined( todo!(
SurfacePath::Line(_), "Can't connect edge to circle on curved \
) surface"
| MaybeSurfacePath::UndefinedLine => { )
// The other edge is a line segment on
// a plane. That means our edge must be
// a line segment too.
Some(MaybeSurfacePath::UndefinedLine)
}
_ => {
// The other edge is a circle or arc on
// a plane. I'm actually not sure what
// that means for our edge. We might be
// able to represent it somehow, but
// let's leave that as an exercise for
// later.
todo!(
"Can't connect edge to circle on \
plane"
)
}
}
} }
} }
} }
None => { GlobalPath::Line(_) => {
// We know nothing about the surface the other edge is // The other edge is defined on a plane.
// on. This means we can't infer anything about our match path {
// curve from the other curve. MaybeSurfacePath::Defined(SurfacePath::Line(_))
None | MaybeSurfacePath::UndefinedLine => {
// The other edge is a line segment on a plane.
// That means our edge must be a line segment
// too.
Some(MaybeSurfacePath::UndefinedLine)
}
_ => {
// The other edge is a circle or arc on a plane.
// I'm actually not sure what that means for our
// edge. We might be able to represent it
// somehow, but let's leave that as an exercise
// for later.
todo!("Can't connect edge to circle on plane")
}
}
} }
} }
}); });