Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue cleanup of PartialHalfEdge #1362

Merged
merged 4 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions crates/fj-kernel/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,16 @@ impl TransformObject for PartialHalfEdge {
objects: &Objects,
) -> Result<Self, ValidationError> {
let curve = self.curve.transform(transform, objects)?;
let vertices = self.vertices.try_map_ext(
|vertex| -> Result<_, ValidationError> {
let mut vertex =
vertex.into_partial().transform(transform, objects)?;
vertex.curve = curve.clone();
Ok(vertex)
},
)?;
let mut global_form = self
.global_form
.into_partial()
.transform(transform, objects)?;
global_form.curve = curve.global_form();
let vertices = self
.vertices
.try_map_ext(|vertex| vertex.transform(transform, objects))?;
let global_form = self.global_form.transform(transform, objects)?;

Ok(Self::default()
.with_curve(curve)
.with_vertices(vertices)
.with_global_form(global_form))
Ok(Self {
curve,
vertices,
global_form,
})
}
}

Expand Down
12 changes: 6 additions & 6 deletions crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use fj_math::Point;
use crate::{
objects::{HalfEdge, Surface, SurfaceVertex},
partial::{
HasPartial, MaybePartial, PartialCurve, PartialCycle,
HasPartial, MaybePartial, PartialCurve, PartialCycle, PartialHalfEdge,
PartialSurfaceVertex, PartialVertex,
},
storage::Handle,
Expand Down Expand Up @@ -82,11 +82,11 @@ impl CycleBuilder for PartialCycle {
},
);

half_edges.push(
HalfEdge::partial()
.with_curve(curve)
.with_vertices(vertices),
);
half_edges.push(PartialHalfEdge {
curve: curve.into(),
vertices: vertices.map(Into::into),
..Default::default()
});

continue;
}
Expand Down
38 changes: 27 additions & 11 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,26 @@ pub trait HalfEdgeBuilder: Sized {
}

impl HalfEdgeBuilder for PartialHalfEdge {
fn with_back_vertex(self, back: impl Into<MaybePartial<Vertex>>) -> Self {
fn with_back_vertex(
mut self,
back: impl Into<MaybePartial<Vertex>>,
) -> Self {
let [_, front] = self.vertices.clone();
self.with_vertices([back.into(), front])
self.vertices = [back.into(), front];
self
}

fn with_front_vertex(self, front: impl Into<MaybePartial<Vertex>>) -> Self {
fn with_front_vertex(
mut self,
front: impl Into<MaybePartial<Vertex>>,
) -> Self {
let [back, _] = self.vertices.clone();
self.with_vertices([back, front.into()])
self.vertices = [back, front.into()];
self
}

fn update_as_circle_from_radius(
self,
mut self,
radius: impl Into<Scalar>,
objects: &Objects,
) -> Result<Self, ValidationError> {
Expand Down Expand Up @@ -90,7 +98,10 @@ impl HalfEdgeBuilder for PartialHalfEdge {
surface_form: surface_vertex.clone().into(),
});

Ok(self.with_curve(curve).with_vertices([back, front]))
self.curve = curve.into();
self.vertices = [back, front].map(Into::into);

Ok(self)
}

fn update_as_line_segment_from_points(
Expand All @@ -112,10 +123,11 @@ impl HalfEdgeBuilder for PartialHalfEdge {
});

self.replace(surface);
self.with_vertices(vertices).update_as_line_segment()
self.vertices = vertices.map(Into::into);
self.update_as_line_segment()
}

fn update_as_line_segment(self) -> Self {
fn update_as_line_segment(mut self) -> Self {
let [from, to] = self.vertices.clone();
let [from_surface, to_surface] =
[&from, &to].map(|vertex| vertex.surface_form());
Expand Down Expand Up @@ -190,11 +202,15 @@ impl HalfEdgeBuilder for PartialHalfEdge {
})
};

self.with_curve(curve).with_vertices([back, front])
self.curve = curve.into();
self.vertices = [back, front];

self
}

fn infer_global_form(self) -> Self {
self.with_global_form(PartialGlobalEdge::default())
fn infer_global_form(mut self) -> Self {
self.global_form = PartialGlobalEdge::default().into();
self
}
}

Expand Down
102 changes: 57 additions & 45 deletions crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crate::{
algorithms::transform::TransformObject,
builder::{FaceBuilder, HalfEdgeBuilder, SurfaceBuilder},
insert::Insert,
objects::{Cycle, Face, FaceSet, HalfEdge, Objects, Shell},
objects::{Cycle, Face, FaceSet, Objects, Shell},
partial::{
HasPartial, PartialCurve, PartialSurface, PartialSurfaceVertex,
PartialVertex,
HasPartial, PartialCurve, PartialHalfEdge, PartialSurface,
PartialSurfaceVertex, PartialVertex,
},
storage::Handle,
};
Expand Down Expand Up @@ -94,16 +94,18 @@ impl<'a> ShellBuilder<'a> {
.half_edges()
.zip(&surfaces)
.map(|(half_edge, surface)| {
HalfEdge::partial()
.with_global_form(half_edge.global_form().clone())
.update_as_line_segment_from_points(
surface.clone(),
[[Z, Z], [edge_length, Z]],
)
.build(self.objects)
.unwrap()
.insert(self.objects)
.unwrap()
PartialHalfEdge {
global_form: half_edge.global_form().clone().into(),
..Default::default()
}
.update_as_line_segment_from_points(
surface.clone(),
[[Z, Z], [edge_length, Z]],
)
.build(self.objects)
.unwrap()
.insert(self.objects)
.unwrap()
})
.collect::<Vec<_>>();

Expand All @@ -121,8 +123,8 @@ impl<'a> ShellBuilder<'a> {
..Default::default()
};

HalfEdge::partial()
.with_vertices([
PartialHalfEdge {
vertices: [
PartialVertex {
surface_form: from.into(),
..Default::default()
Expand All @@ -131,12 +133,15 @@ impl<'a> ShellBuilder<'a> {
surface_form: to.into(),
..Default::default()
},
])
.update_as_line_segment()
.build(self.objects)
.unwrap()
.insert(self.objects)
.unwrap()
]
.map(Into::into),
..Default::default()
}
.update_as_line_segment()
.build(self.objects)
.unwrap()
.insert(self.objects)
.unwrap()
})
.collect::<Vec<_>>();

Expand Down Expand Up @@ -169,9 +174,9 @@ impl<'a> ShellBuilder<'a> {
..Default::default()
};

HalfEdge::partial()
.with_curve(curve)
.with_vertices([
PartialHalfEdge {
curve: curve.into(),
vertices: [
PartialVertex {
surface_form: from.into(),
..Default::default()
Expand All @@ -180,12 +185,15 @@ impl<'a> ShellBuilder<'a> {
surface_form: to.into(),
..Default::default()
},
])
.update_as_line_segment()
.build(self.objects)
.unwrap()
.insert(self.objects)
.unwrap()
]
.map(Into::into),
..Default::default()
}
.update_as_line_segment()
.build(self.objects)
.unwrap()
.insert(self.objects)
.unwrap()
})
.collect::<Vec<_>>()
};
Expand All @@ -210,13 +218,15 @@ impl<'a> ShellBuilder<'a> {
..Default::default()
};

HalfEdge::partial()
.with_vertices([from, to])
.update_as_line_segment()
.build(self.objects)
.unwrap()
.insert(self.objects)
.unwrap()
PartialHalfEdge {
vertices: [from, to].map(Into::into),
..Default::default()
}
.update_as_line_segment()
.build(self.objects)
.unwrap()
.insert(self.objects)
.unwrap()
})
.collect::<Vec<_>>();

Expand Down Expand Up @@ -301,14 +311,16 @@ impl<'a> ShellBuilder<'a> {
});

edges.push(
HalfEdge::partial()
.with_vertices(vertices)
.with_global_form(edge.global_form().clone())
.update_as_line_segment()
.build(self.objects)
.unwrap()
.insert(self.objects)
.unwrap(),
PartialHalfEdge {
vertices: vertices.map(Into::into),
global_form: edge.global_form().clone().into(),
..Default::default()
}
.update_as_line_segment()
.build(self.objects)
.unwrap()
.insert(self.objects)
.unwrap(),
);
}

Expand Down
10 changes: 6 additions & 4 deletions crates/fj-kernel/src/partial/objects/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ impl PartialCycle {
let front_vertex =
half_edge.front().surface_form().into_full(objects)?;

*half_edge = half_edge.clone().merge_with(
PartialHalfEdge::default().with_vertices([
*half_edge = half_edge.clone().merge_with(PartialHalfEdge {
vertices: [
PartialVertex {
surface_form: back_vertex,
..Default::default()
Expand All @@ -108,8 +108,10 @@ impl PartialCycle {
surface_form: front_vertex.clone().into(),
..Default::default()
},
]),
);
]
.map(Into::into),
..Default::default()
});

previous_vertex = Some(MaybePartial::from(front_vertex));
}
Expand Down
26 changes: 0 additions & 26 deletions crates/fj-kernel/src/partial/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,6 @@ pub struct PartialHalfEdge {
}

impl PartialHalfEdge {
/// Update the partial half-edge with the given curve
pub fn with_curve(mut self, curve: impl Into<MaybePartial<Curve>>) -> Self {
self.curve = curve.into();

self
}

/// Update the partial half-edge with the given vertices
pub fn with_vertices(
mut self,
vertices: [impl Into<MaybePartial<Vertex>>; 2],
) -> Self {
self.vertices = vertices.map(Into::into);
self
}

/// Update the partial half-edge with the given global form
pub fn with_global_form(
mut self,
global_form: impl Into<MaybePartial<GlobalEdge>>,
) -> Self {
self.global_form = global_form.into();

self
}

/// Build a full [`HalfEdge`] from the partial half-edge
pub fn build(
mut self,
Expand Down