Skip to content

Commit

Permalink
Return HalfEdge from HalfEdgeBuilder::build
Browse files Browse the repository at this point in the history
This is less convenient right now, but it makes `HalfEdgeBuilder` more
composable and future-proof.
  • Loading branch information
hannobraun committed Mar 10, 2023
1 parent 5c2fdde commit 92da422
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
8 changes: 5 additions & 3 deletions crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ mod tests {
[[0., 1.], [TAU, 1.]],
Some(range.boundary),
)
.build(&mut services.objects);
.build(&mut services.objects)
.insert(&mut services.objects);

let tolerance = 1.;
let approx = (&half_edge, surface.deref()).approx(tolerance);
Expand All @@ -360,8 +361,9 @@ mod tests {
let mut services = Services::new();

let surface = services.objects.surfaces.xz_plane();
let half_edge =
HalfEdgeBuilder::circle(1.).build(&mut services.objects);
let half_edge = HalfEdgeBuilder::circle(1.)
.build(&mut services.objects)
.insert(&mut services.objects);

let tolerance = 1.;
let approx = (&half_edge, surface.deref()).approx(tolerance);
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Sweep for (Handle<HalfEdge>, &Handle<Vertex>, &Surface, Color) {
builder
};

builder.build(objects)
builder.build(objects).insert(objects)
};

face.exterior.write().add_half_edge(half_edge.clone());
Expand Down
7 changes: 5 additions & 2 deletions crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use fj_math::Point;

use crate::{
geometry::curve::Curve,
insert::Insert,
objects::{HalfEdge, Objects},
partial::PartialCycle,
services::Service,
Expand Down Expand Up @@ -64,7 +65,8 @@ impl CycleBuilder for PartialCycle {
{
points.map_with_next(|start, end| {
let half_edge = HalfEdgeBuilder::line_segment([start, end], None)
.build(objects);
.build(objects)
.insert(objects);

self.add_half_edge(half_edge.clone());

Expand All @@ -83,7 +85,8 @@ impl CycleBuilder for PartialCycle {
edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| {
let half_edge = HalfEdgeBuilder::new(curve, boundary)
.with_start_vertex(prev.start_vertex().clone())
.build(objects);
.build(objects)
.insert(objects);

self.add_half_edge(half_edge.clone());

Expand Down
3 changes: 1 addition & 2 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl HalfEdgeBuilder {
}

/// Create a half-edge
pub fn build(self, objects: &mut Service<Objects>) -> Handle<HalfEdge> {
pub fn build(self, objects: &mut Service<Objects>) -> HalfEdge {
HalfEdge::new(
self.curve,
self.boundary,
Expand All @@ -98,6 +98,5 @@ impl HalfEdgeBuilder {
self.global_form
.unwrap_or_else(|| GlobalEdge::new().insert(objects)),
)
.insert(objects)
}
}
8 changes: 5 additions & 3 deletions crates/fj-operations/src/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ impl Shape for fj::Sketch {

let face = match self.chain() {
fj::Chain::Circle(circle) => {
let half_edge =
HalfEdgeBuilder::circle(circle.radius()).build(objects);
let half_edge = HalfEdgeBuilder::circle(circle.radius())
.build(objects)
.insert(objects);
let exterior = {
let mut cycle = PartialCycle::new(objects);
cycle.half_edges.push(half_edge);
Expand Down Expand Up @@ -74,7 +75,8 @@ impl Shape for fj::Sketch {
}
};

let half_edge = half_edge.build(objects);
let half_edge =
half_edge.build(objects).insert(objects);
cycle.add_half_edge(half_edge);
}

Expand Down

0 comments on commit 92da422

Please sign in to comment.