mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-16 13:16:09 +00:00
Merge pull request #1212 from hannobraun/partial
Make `PartialHalfEdge` more flexible
This commit is contained in:
commit
d6ea26a0be
@ -106,9 +106,11 @@ impl MaybePartial<GlobalEdge> {
|
|||||||
|
|
||||||
impl MaybePartial<HalfEdge> {
|
impl MaybePartial<HalfEdge> {
|
||||||
/// Access the vertices
|
/// Access the vertices
|
||||||
pub fn vertices(&self) -> Option<[MaybePartial<Vertex>; 2]> {
|
pub fn vertices(&self) -> [Option<MaybePartial<Vertex>>; 2] {
|
||||||
match self {
|
match self {
|
||||||
Self::Full(full) => Some(full.vertices().clone().map(Into::into)),
|
Self::Full(full) => {
|
||||||
|
full.vertices().clone().map(|vertex| Some(vertex.into()))
|
||||||
|
}
|
||||||
Self::Partial(partial) => partial.vertices.clone(),
|
Self::Partial(partial) => partial.vertices.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,17 +48,17 @@ impl PartialCycle {
|
|||||||
.half_edges
|
.half_edges
|
||||||
.last()
|
.last()
|
||||||
.map(|half_edge| {
|
.map(|half_edge| {
|
||||||
let [_, last] = half_edge.vertices().expect(
|
let [_, last] = half_edge.vertices().map(|vertex| {
|
||||||
"Need half-edge vertices to extend cycle with poly-chain",
|
vertex.expect("Need half-edge vertices to extend cycle")
|
||||||
);
|
});
|
||||||
let last = last.surface_form().expect(
|
let last = last
|
||||||
"Need surface vertex to extend cycle with poly-chain",
|
.surface_form()
|
||||||
);
|
.expect("Need surface vertex to extend cycle");
|
||||||
|
|
||||||
let vertex = last.clone();
|
let vertex = last.clone();
|
||||||
let position = last.position().expect(
|
let position = last
|
||||||
"Need surface position to extend cycle with poly-chain",
|
.position()
|
||||||
);
|
.expect("Need surface position to extend cycle");
|
||||||
|
|
||||||
(position, Some(vertex))
|
(position, Some(vertex))
|
||||||
})
|
})
|
||||||
@ -129,7 +129,9 @@ impl PartialCycle {
|
|||||||
|
|
||||||
let vertices = [first, last].map(|option| {
|
let vertices = [first, last].map(|option| {
|
||||||
option.map(|half_edge| {
|
option.map(|half_edge| {
|
||||||
half_edge.vertices().expect("Need vertices to close cycle")
|
half_edge
|
||||||
|
.vertices()
|
||||||
|
.map(|vertex| vertex.expect("Need vertices to close cycle"))
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ pub struct PartialHalfEdge {
|
|||||||
pub curve: Option<MaybePartial<Handle<Curve>>>,
|
pub curve: Option<MaybePartial<Handle<Curve>>>,
|
||||||
|
|
||||||
/// The vertices that bound this [`HalfEdge`] in the [`Curve`]
|
/// The vertices that bound this [`HalfEdge`] in the [`Curve`]
|
||||||
pub vertices: Option<[MaybePartial<Vertex>; 2]>,
|
pub vertices: [Option<MaybePartial<Vertex>>; 2],
|
||||||
|
|
||||||
/// The global form of the [`HalfEdge`]
|
/// The global form of the [`HalfEdge`]
|
||||||
///
|
///
|
||||||
@ -60,13 +60,38 @@ impl PartialHalfEdge {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update the partial half-edge with the given from vertex
|
||||||
|
pub fn with_from_vertex(
|
||||||
|
mut self,
|
||||||
|
vertex: Option<impl Into<MaybePartial<Vertex>>>,
|
||||||
|
) -> Self {
|
||||||
|
if let Some(vertex) = vertex {
|
||||||
|
let [from, _] = &mut self.vertices;
|
||||||
|
*from = Some(vertex.into());
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the partial half-edge with the given from vertex
|
||||||
|
pub fn with_to_vertex(
|
||||||
|
mut self,
|
||||||
|
vertex: Option<impl Into<MaybePartial<Vertex>>>,
|
||||||
|
) -> Self {
|
||||||
|
if let Some(vertex) = vertex {
|
||||||
|
let [_, to] = &mut self.vertices;
|
||||||
|
*to = Some(vertex.into());
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Update the partial half-edge with the given vertices
|
/// Update the partial half-edge with the given vertices
|
||||||
pub fn with_vertices(
|
pub fn with_vertices(
|
||||||
mut self,
|
mut self,
|
||||||
vertices: Option<[impl Into<MaybePartial<Vertex>>; 2]>,
|
vertices: Option<[impl Into<MaybePartial<Vertex>>; 2]>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
if let Some(vertices) = vertices {
|
let vertices = vertices.map(|vertices| vertices.map(Into::into));
|
||||||
self.vertices = Some(vertices.map(Into::into));
|
if let Some([a, b]) = vertices {
|
||||||
|
self.vertices = [Some(a), Some(b)];
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -89,7 +114,7 @@ impl PartialHalfEdge {
|
|||||||
.with_surface(self.surface.clone())
|
.with_surface(self.surface.clone())
|
||||||
.as_circle_from_radius(radius);
|
.as_circle_from_radius(radius);
|
||||||
|
|
||||||
let vertices = {
|
let [a, b] = {
|
||||||
let [a_curve, b_curve] =
|
let [a_curve, b_curve] =
|
||||||
[Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord]));
|
[Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord]));
|
||||||
|
|
||||||
@ -106,11 +131,12 @@ impl PartialHalfEdge {
|
|||||||
.with_position(Some(point_curve))
|
.with_position(Some(point_curve))
|
||||||
.with_curve(Some(curve.clone()))
|
.with_curve(Some(curve.clone()))
|
||||||
.with_surface_form(Some(surface_form.clone()))
|
.with_surface_form(Some(surface_form.clone()))
|
||||||
|
.into()
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
self.curve = Some(curve.into());
|
self.curve = Some(curve.into());
|
||||||
self.vertices = Some(vertices.map(Into::into));
|
self.vertices = [Some(a), Some(b)];
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -133,10 +159,9 @@ impl PartialHalfEdge {
|
|||||||
|
|
||||||
/// Update partial half-edge as a line segment, reusing existing vertices
|
/// Update partial half-edge as a line segment, reusing existing vertices
|
||||||
pub fn as_line_segment(mut self) -> Self {
|
pub fn as_line_segment(mut self) -> Self {
|
||||||
let [from, to] = self
|
let [from, to] = self.vertices.clone().map(|vertex| {
|
||||||
.vertices
|
vertex.expect("Can't infer line segment without vertices")
|
||||||
.clone()
|
});
|
||||||
.expect("Can't infer line segment without vertices");
|
|
||||||
let [from_surface, to_surface] = [&from, &to].map(|vertex| {
|
let [from_surface, to_surface] = [&from, &to].map(|vertex| {
|
||||||
vertex
|
vertex
|
||||||
.surface_form()
|
.surface_form()
|
||||||
@ -161,7 +186,7 @@ impl PartialHalfEdge {
|
|||||||
.with_surface(Some(surface))
|
.with_surface(Some(surface))
|
||||||
.as_line_from_points(points);
|
.as_line_from_points(points);
|
||||||
|
|
||||||
let vertices = [(from, 0.), (to, 1.)].map(|(vertex, position)| {
|
let [a, b] = [(from, 0.), (to, 1.)].map(|(vertex, position)| {
|
||||||
vertex.update_partial(|vertex| {
|
vertex.update_partial(|vertex| {
|
||||||
vertex
|
vertex
|
||||||
.with_position(Some([position]))
|
.with_position(Some([position]))
|
||||||
@ -170,7 +195,7 @@ impl PartialHalfEdge {
|
|||||||
});
|
});
|
||||||
|
|
||||||
self.curve = Some(curve.into());
|
self.curve = Some(curve.into());
|
||||||
self.vertices = Some(vertices);
|
self.vertices = [Some(a), Some(b)];
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -183,16 +208,12 @@ impl PartialHalfEdge {
|
|||||||
.expect("Can't build `HalfEdge` without curve")
|
.expect("Can't build `HalfEdge` without curve")
|
||||||
.update_partial(|curve| curve.with_surface(surface))
|
.update_partial(|curve| curve.with_surface(surface))
|
||||||
.into_full(objects);
|
.into_full(objects);
|
||||||
let vertices = self
|
let vertices = self.vertices.map(|vertex| {
|
||||||
.vertices
|
vertex
|
||||||
.expect("Can't build `HalfEdge` without vertices")
|
.expect("Can't build `HalfEdge` without vertices")
|
||||||
.map(|vertex| {
|
.update_partial(|vertex| vertex.with_curve(Some(curve.clone())))
|
||||||
vertex
|
.into_full(objects)
|
||||||
.update_partial(|vertex| {
|
});
|
||||||
vertex.with_curve(Some(curve.clone()))
|
|
||||||
})
|
|
||||||
.into_full(objects)
|
|
||||||
});
|
|
||||||
|
|
||||||
let global_form = self
|
let global_form = self
|
||||||
.global_form
|
.global_form
|
||||||
@ -208,10 +229,12 @@ impl PartialHalfEdge {
|
|||||||
|
|
||||||
impl From<&HalfEdge> for PartialHalfEdge {
|
impl From<&HalfEdge> for PartialHalfEdge {
|
||||||
fn from(half_edge: &HalfEdge) -> Self {
|
fn from(half_edge: &HalfEdge) -> Self {
|
||||||
|
let [a, b] = half_edge.vertices().clone().map(Into::into);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
surface: Some(half_edge.curve().surface().clone()),
|
surface: Some(half_edge.curve().surface().clone()),
|
||||||
curve: Some(half_edge.curve().clone().into()),
|
curve: Some(half_edge.curve().clone().into()),
|
||||||
vertices: Some(half_edge.vertices().clone().map(Into::into)),
|
vertices: [Some(a), Some(b)],
|
||||||
global_form: Some(half_edge.global_form().clone().into()),
|
global_form: Some(half_edge.global_form().clone().into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user