mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-29 03:19:22 +00:00
Make struct field type more flexible
This commit is contained in:
parent
67d351cea0
commit
41317b13be
@ -111,11 +111,7 @@ impl MaybePartial<HalfEdge> {
|
||||
Self::Full(full) => {
|
||||
full.vertices().clone().map(|vertex| Some(vertex.into()))
|
||||
}
|
||||
Self::Partial(partial) => partial
|
||||
.vertices
|
||||
.clone()
|
||||
.map(|vertices| vertices.map(Some))
|
||||
.unwrap_or([None, None]),
|
||||
Self::Partial(partial) => partial.vertices.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ pub struct PartialHalfEdge {
|
||||
pub curve: Option<MaybePartial<Handle<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`]
|
||||
///
|
||||
@ -66,8 +66,8 @@ impl PartialHalfEdge {
|
||||
vertices: Option<[impl Into<MaybePartial<Vertex>>; 2]>,
|
||||
) -> Self {
|
||||
let vertices = vertices.map(|vertices| vertices.map(Into::into));
|
||||
if let Some(vertices) = vertices {
|
||||
self.vertices = Some(vertices);
|
||||
if let Some([a, b]) = vertices {
|
||||
self.vertices = [Some(a), Some(b)];
|
||||
}
|
||||
self
|
||||
}
|
||||
@ -90,7 +90,7 @@ impl PartialHalfEdge {
|
||||
.with_surface(self.surface.clone())
|
||||
.as_circle_from_radius(radius);
|
||||
|
||||
let vertices = {
|
||||
let [a, b] = {
|
||||
let [a_curve, b_curve] =
|
||||
[Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord]));
|
||||
|
||||
@ -112,7 +112,7 @@ impl PartialHalfEdge {
|
||||
};
|
||||
|
||||
self.curve = Some(curve.into());
|
||||
self.vertices = Some(vertices);
|
||||
self.vertices = [Some(a), Some(b)];
|
||||
|
||||
self
|
||||
}
|
||||
@ -135,10 +135,9 @@ impl PartialHalfEdge {
|
||||
|
||||
/// Update partial half-edge as a line segment, reusing existing vertices
|
||||
pub fn as_line_segment(mut self) -> Self {
|
||||
let [from, to] = self
|
||||
.vertices
|
||||
.clone()
|
||||
.expect("Can't infer line segment without vertices");
|
||||
let [from, to] = self.vertices.clone().map(|vertex| {
|
||||
vertex.expect("Can't infer line segment without vertices")
|
||||
});
|
||||
let [from_surface, to_surface] = [&from, &to].map(|vertex| {
|
||||
vertex
|
||||
.surface_form()
|
||||
@ -163,7 +162,7 @@ impl PartialHalfEdge {
|
||||
.with_surface(Some(surface))
|
||||
.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
|
||||
.with_position(Some([position]))
|
||||
@ -172,7 +171,7 @@ impl PartialHalfEdge {
|
||||
});
|
||||
|
||||
self.curve = Some(curve.into());
|
||||
self.vertices = Some(vertices);
|
||||
self.vertices = [Some(a), Some(b)];
|
||||
|
||||
self
|
||||
}
|
||||
@ -185,16 +184,12 @@ impl PartialHalfEdge {
|
||||
.expect("Can't build `HalfEdge` without curve")
|
||||
.update_partial(|curve| curve.with_surface(surface))
|
||||
.into_full(objects);
|
||||
let vertices = self
|
||||
.vertices
|
||||
.expect("Can't build `HalfEdge` without vertices")
|
||||
.map(|vertex| {
|
||||
vertex
|
||||
.update_partial(|vertex| {
|
||||
vertex.with_curve(Some(curve.clone()))
|
||||
})
|
||||
.into_full(objects)
|
||||
});
|
||||
let vertices = self.vertices.map(|vertex| {
|
||||
vertex
|
||||
.expect("Can't build `HalfEdge` without vertices")
|
||||
.update_partial(|vertex| vertex.with_curve(Some(curve.clone())))
|
||||
.into_full(objects)
|
||||
});
|
||||
|
||||
let global_form = self
|
||||
.global_form
|
||||
@ -210,10 +205,12 @@ impl PartialHalfEdge {
|
||||
|
||||
impl From<&HalfEdge> for PartialHalfEdge {
|
||||
fn from(half_edge: &HalfEdge) -> Self {
|
||||
let [a, b] = half_edge.vertices().clone().map(Into::into);
|
||||
|
||||
Self {
|
||||
surface: Some(half_edge.curve().surface().clone()),
|
||||
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()),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user