Skip to content

Commit

Permalink
Merge pull request #1312 from hannobraun/partial
Browse files Browse the repository at this point in the history
Continue cleanup of partial object API
  • Loading branch information
hannobraun authored Nov 5, 2022
2 parents d4c2e43 + 9ba8e98 commit 19f802b
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 216 deletions.
98 changes: 48 additions & 50 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,58 +208,56 @@ mod tests {
let face =
(half_edge, Color::default()).sweep([0., 0., 1.], &objects)?;

let expected_face = {
let surface = objects.surfaces.xz_plane();

let bottom = HalfEdge::partial()
.update_as_line_segment_from_points(
surface.clone(),
[[0., 0.], [1., 0.]],
)
.build(&objects)?;
let side_up = HalfEdge::partial()
.with_surface(Some(surface.clone()))
.with_back_vertex(Some(Vertex::partial().with_surface_form(
Some(bottom.front().surface_form().clone()),
)))
.with_front_vertex(Some(Vertex::partial().with_surface_form(
Some(
let expected_face =
{
let surface = objects.surfaces.xz_plane();

let bottom = HalfEdge::partial()
.update_as_line_segment_from_points(
surface.clone(),
[[0., 0.], [1., 0.]],
)
.build(&objects)?;
let side_up = HalfEdge::partial()
.with_surface(surface.clone())
.with_back_vertex(Vertex::partial().with_surface_form(
bottom.front().surface_form().clone(),
))
.with_front_vertex(Vertex::partial().with_surface_form(
SurfaceVertex::partial().with_position(Some([1., 1.])),
),
)))
.update_as_line_segment()
.build(&objects)?;
let top = HalfEdge::partial()
.with_surface(Some(surface.clone()))
.with_back_vertex(Some(Vertex::partial().with_surface_form(
Some(
))
.update_as_line_segment()
.build(&objects)?;
let top = HalfEdge::partial()
.with_surface(surface.clone())
.with_back_vertex(Vertex::partial().with_surface_form(
SurfaceVertex::partial().with_position(Some([0., 1.])),
),
)))
.with_front_vertex(Some(Vertex::partial().with_surface_form(
Some(side_up.front().surface_form().clone()),
)))
.update_as_line_segment()
.build(&objects)?
.reverse(&objects)?;
let side_down = HalfEdge::partial()
.with_surface(Some(surface))
.with_back_vertex(Some(Vertex::partial().with_surface_form(
Some(bottom.back().surface_form().clone()),
)))
.with_front_vertex(Some(Vertex::partial().with_surface_form(
Some(top.front().surface_form().clone()),
)))
.update_as_line_segment()
.build(&objects)?
.reverse(&objects)?;

let cycle = objects
.cycles
.insert(Cycle::new([bottom, side_up, top, side_down]))?;

Face::builder(&objects).with_exterior(cycle).build()
};
))
.with_front_vertex(Vertex::partial().with_surface_form(
side_up.front().surface_form().clone(),
))
.update_as_line_segment()
.build(&objects)?
.reverse(&objects)?;
let side_down =
HalfEdge::partial()
.with_surface(surface)
.with_back_vertex(Vertex::partial().with_surface_form(
bottom.back().surface_form().clone(),
))
.with_front_vertex(Vertex::partial().with_surface_form(
top.front().surface_form().clone(),
))
.update_as_line_segment()
.build(&objects)?
.reverse(&objects)?;

let cycle = objects
.cycles
.insert(Cycle::new([bottom, side_up, top, side_down]))?;

Face::builder(&objects).with_exterior(cycle).build()
};

assert_eq!(face, expected_face);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ mod tests {
.build(&objects)?;
let vertex = Vertex::partial()
.with_position(Some([0.]))
.with_curve(Some(curve))
.with_curve(curve)
.build(&objects)?;

let half_edge =
Expand Down
9 changes: 4 additions & 5 deletions crates/fj-kernel/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@ impl TransformObject for PartialHalfEdge {
Ok(vertex
.into_partial()
.transform(transform, objects)?
.with_curve(Some(curve.clone())))
.with_curve(curve.clone()))
},
)?;
let global_form = self
.global_form()
.into_partial()
.transform(transform, objects)?
.with_curve(curve.global_form())
.into();
.with_curve(curve.global_form());

Ok(Self::default()
.with_curve(Some(curve))
.with_vertices(Some(vertices))
.with_curve(curve)
.with_vertices(vertices)
.with_global_form(global_form))
}
}
Expand Down
5 changes: 2 additions & 3 deletions crates/fj-kernel/src/algorithms/transform/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ impl TransformObject for PartialVertex {
let surface_form = self
.surface_form()
.into_partial()
.transform(transform, objects)?
.into();
.transform(transform, objects)?;

// Don't need to transform `self.position`, as that is in curve
// coordinates and thus transforming the curve takes care of it.
Ok(Self::default()
.with_position(self.position())
.with_curve(Some(curve))
.with_curve(curve)
.with_surface_form(surface_form))
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ impl CycleBuilder for PartialCycle {
let [from, to] =
[(0., from), (1., to)].map(|(position, surface_form)| {
Vertex::partial()
.with_curve(Some(curve.clone()))
.with_curve(curve.clone())
.with_position(Some([position]))
.with_surface_form(Some(surface_form))
.with_surface_form(surface_form)
});

half_edges.push(
HalfEdge::partial()
.with_curve(Some(curve))
.with_vertices(Some([from, to])),
.with_curve(curve)
.with_vertices([from, to]),
);

continue;
Expand Down
23 changes: 10 additions & 13 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,11 @@ impl HalfEdgeBuilder for PartialHalfEdge {
let [back, front] = [a_curve, b_curve].map(|point_curve| {
Vertex::partial()
.with_position(Some(point_curve))
.with_curve(Some(curve.clone()))
.with_surface_form(Some(surface_vertex.clone()))
.with_curve(curve.clone())
.with_surface_form(surface_vertex.clone())
});

Ok(self
.with_curve(Some(curve))
.with_vertices(Some([back, front])))
Ok(self.with_curve(curve).with_vertices([back, front]))
}

fn update_as_line_segment_from_points(
Expand All @@ -94,11 +92,11 @@ impl HalfEdgeBuilder for PartialHalfEdge {
.with_surface(Some(surface.clone()))
.with_position(Some(point));

Vertex::partial().with_surface_form(Some(surface_form))
Vertex::partial().with_surface_form(surface_form)
});

self.with_surface(Some(surface))
.with_vertices(Some(vertices))
self.with_surface(surface)
.with_vertices(vertices)
.update_as_line_segment()
}

Expand Down Expand Up @@ -129,7 +127,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
vertex.update_partial(|vertex| {
vertex
.with_position(Some([position]))
.with_curve(Some(curve.clone()))
.with_curve(curve.clone())
})
});

Expand Down Expand Up @@ -170,19 +168,18 @@ impl HalfEdgeBuilder for PartialHalfEdge {

vertices.zip_ext(global_forms).map(|(vertex, global_form)| {
vertex.update_partial(|vertex| {
vertex.clone().with_surface_form(Some(
vertex.clone().with_surface_form(
vertex.surface_form().update_partial(
|surface_vertex| {
surface_vertex.with_global_form(global_form)
},
),
))
)
})
})
};

self.with_curve(Some(curve))
.with_vertices(Some([back, front]))
self.with_curve(curve).with_vertices([back, front])
}
}

Expand Down
32 changes: 16 additions & 16 deletions crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<'a> ShellBuilder<'a> {
.zip(&surfaces)
.map(|(half_edge, surface)| {
HalfEdge::partial()
.with_global_form(Some(half_edge.global_form().clone()))
.with_global_form(half_edge.global_form().clone())
.update_as_line_segment_from_points(
surface.clone(),
[[Z, Z], [edge_length, Z]],
Expand All @@ -112,10 +112,10 @@ impl<'a> ShellBuilder<'a> {
.with_surface(Some(surface.clone()));

HalfEdge::partial()
.with_vertices(Some([
Vertex::partial().with_surface_form(Some(from)),
Vertex::partial().with_surface_form(Some(to)),
]))
.with_vertices([
Vertex::partial().with_surface_form(from),
Vertex::partial().with_surface_form(to),
])
.update_as_line_segment()
.build(self.objects)
.unwrap()
Expand Down Expand Up @@ -148,11 +148,11 @@ impl<'a> ShellBuilder<'a> {
));

HalfEdge::partial()
.with_curve(Some(curve))
.with_vertices(Some([
Vertex::partial().with_surface_form(Some(from)),
Vertex::partial().with_surface_form(Some(to)),
]))
.with_curve(curve)
.with_vertices([
Vertex::partial().with_surface_form(from),
Vertex::partial().with_surface_form(to),
])
.update_as_line_segment()
.build(self.objects)
.unwrap()
Expand All @@ -171,11 +171,11 @@ impl<'a> ShellBuilder<'a> {
let from = from.surface_form().clone();
let to = to.surface_form().clone();

let from = Vertex::partial().with_surface_form(Some(from));
let to = Vertex::partial().with_surface_form(Some(to));
let from = Vertex::partial().with_surface_form(from);
let to = Vertex::partial().with_surface_form(to);

HalfEdge::partial()
.with_vertices(Some([from, to]))
.with_vertices([from, to])
.update_as_line_segment()
.build(self.objects)
.unwrap()
Expand Down Expand Up @@ -246,13 +246,13 @@ impl<'a> ShellBuilder<'a> {
.map(|(vertex, surface_form)| {
Vertex::partial()
.with_position(Some(vertex.position()))
.with_surface_form(Some(surface_form))
.with_surface_form(surface_form)
});

edges.push(
HalfEdge::partial()
.with_vertices(Some(vertices))
.with_global_form(Some(edge.global_form().clone()))
.with_vertices(vertices)
.with_global_form(edge.global_form().clone())
.update_as_line_segment()
.build(self.objects)
.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/builder/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub trait VertexBuilder {

impl VertexBuilder for PartialVertex {
fn infer_surface_form(self) -> Self {
self.with_surface_form(Some(PartialSurfaceVertex::default()))
self.with_surface_form(PartialSurfaceVertex::default())
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/partial/maybe_partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ impl<T: HasPartial> MaybePartial<T> {
}

/// Merge this `MaybePartial` with another of the same type
pub fn merge_with(self, other: Self) -> Self {
match (self, other) {
pub fn merge_with(self, other: impl Into<Self>) -> Self {
match (self, other.into()) {
(Self::Full(_), Self::Full(_)) => {
panic!("Can't merge two full objects")
}
Expand Down
Loading

0 comments on commit 19f802b

Please sign in to comment.