mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-30 03:45:55 +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) => {
|
Self::Full(full) => {
|
||||||
full.vertices().clone().map(|vertex| Some(vertex.into()))
|
full.vertices().clone().map(|vertex| Some(vertex.into()))
|
||||||
}
|
}
|
||||||
Self::Partial(partial) => partial
|
Self::Partial(partial) => partial.vertices.clone(),
|
||||||
.vertices
|
|
||||||
.clone()
|
|
||||||
.map(|vertices| vertices.map(Some))
|
|
||||||
.unwrap_or([None, None]),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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`]
|
||||||
///
|
///
|
||||||
@ -66,8 +66,8 @@ impl PartialHalfEdge {
|
|||||||
vertices: Option<[impl Into<MaybePartial<Vertex>>; 2]>,
|
vertices: Option<[impl Into<MaybePartial<Vertex>>; 2]>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let vertices = vertices.map(|vertices| vertices.map(Into::into));
|
let vertices = vertices.map(|vertices| vertices.map(Into::into));
|
||||||
if let Some(vertices) = vertices {
|
if let Some([a, b]) = vertices {
|
||||||
self.vertices = Some(vertices);
|
self.vertices = [Some(a), Some(b)];
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -90,7 +90,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]));
|
||||||
|
|
||||||
@ -112,7 +112,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
|
||||||
}
|
}
|
||||||
@ -135,10 +135,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()
|
||||||
@ -163,7 +162,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]))
|
||||||
@ -172,7 +171,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
|
||||||
}
|
}
|
||||||
@ -185,16 +184,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
|
||||||
@ -210,10 +205,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