Skip to content

Commit

Permalink
Merge pull request #1604 from hannobraun/surface
Browse files Browse the repository at this point in the history
Consolidate redundant references to `Surface`
  • Loading branch information
hannobraun authored Feb 20, 2023
2 parents 8744c82 + 04bbd4d commit f4bb6f4
Show file tree
Hide file tree
Showing 17 changed files with 230 additions and 325 deletions.
5 changes: 1 addition & 4 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ mod tests {
fn compute() {
let mut services = Services::new();

let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut curve = PartialCurve::default();
curve.update_as_line_from_points([[-3., 0.], [-2., 0.]]);
let curve = curve.build(&mut services.objects);
Expand All @@ -184,10 +182,9 @@ mod tests {

let face = {
let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.xy_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior
.write()
.update_as_polygon_from_points(exterior);
Expand Down
6 changes: 2 additions & 4 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ mod tests {
]
.map(|surface| {
let mut face = PartialFace {
surface: Partial::from(surface.clone()),
surface: Partial::from(surface),
..Default::default()
};
face.exterior.write().surface = Partial::from(surface);
face.exterior.write().update_as_polygon_from_points(points);

face.build(&mut services.objects)
Expand Down Expand Up @@ -126,10 +125,9 @@ mod tests {
];
let [a, b] = surfaces.clone().map(|surface| {
let mut face = PartialFace {
surface: Partial::from(surface.clone()),
surface: Partial::from(surface),
..Default::default()
};
face.exterior.write().surface = Partial::from(surface);
face.exterior.write().update_as_polygon_from_points(points);

face.build(&mut services.objects)
Expand Down
40 changes: 8 additions & 32 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,10 @@ mod tests {
fn point_is_outside_face() {
let mut services = Services::new();

let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.xy_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[1., 1.],
Expand All @@ -173,13 +170,10 @@ mod tests {
fn ray_hits_vertex_while_passing_outside() {
let mut services = Services::new();

let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.xy_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[2., 1.],
Expand All @@ -201,13 +195,10 @@ mod tests {
fn ray_hits_vertex_at_cycle_seam() {
let mut services = Services::new();

let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.xy_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[4., 2.],
[0., 4.],
Expand All @@ -229,13 +220,10 @@ mod tests {
fn ray_hits_vertex_while_staying_inside() {
let mut services = Services::new();

let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.xy_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[2., 1.],
Expand All @@ -258,13 +246,10 @@ mod tests {
fn ray_hits_parallel_edge_and_leaves_face_at_vertex() {
let mut services = Services::new();

let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.xy_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[2., 1.],
Expand All @@ -287,13 +272,10 @@ mod tests {
fn ray_hits_parallel_edge_and_does_not_leave_face_there() {
let mut services = Services::new();

let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.xy_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[2., 1.],
Expand All @@ -317,13 +299,10 @@ mod tests {
fn point_is_coincident_with_edge() {
let mut services = Services::new();

let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.xy_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[2., 0.],
Expand Down Expand Up @@ -354,13 +333,10 @@ mod tests {
fn point_is_coincident_with_vertex() {
let mut services = Services::new();

let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.xy_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[1., 0.],
Expand Down
35 changes: 7 additions & 28 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,10 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = Partial::from(services.objects.surfaces.yz_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.yz_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand All @@ -190,13 +187,10 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = Partial::from(services.objects.surfaces.yz_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.yz_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand All @@ -220,13 +214,10 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = Partial::from(services.objects.surfaces.yz_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.yz_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand All @@ -247,13 +238,10 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = Partial::from(services.objects.surfaces.yz_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.yz_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand Down Expand Up @@ -285,13 +273,10 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = Partial::from(services.objects.surfaces.yz_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.yz_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand Down Expand Up @@ -323,13 +308,10 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.xy_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand All @@ -352,13 +334,10 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
surface: Partial::from(services.objects.surfaces.xy_plane()),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/reverse/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ impl Reverse for Handle<Cycle> {

edges.reverse();

Cycle::new(self.surface().clone(), edges).insert(objects)
Cycle::new(edges).insert(objects)
}
}
8 changes: 2 additions & 6 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ impl Sweep for (Handle<HalfEdge>, &Surface, Color) {
(edge.curve().clone(), surface)
.sweep_with_cache(path, cache, objects),
);
face.surface = surface.clone();
face.exterior.write().surface = surface;
face.surface = surface;
}

// Now we're ready to create the edges.
Expand Down Expand Up @@ -269,10 +268,7 @@ mod tests {
.clone()
};

let mut cycle = PartialCycle {
surface: Partial::from(surface.clone()),
..Default::default()
};
let mut cycle = PartialCycle::default();
cycle.half_edges.extend(
[bottom, side_up, top, side_down].map(Partial::from_partial),
);
Expand Down
14 changes: 2 additions & 12 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ impl Sweep for Handle<Face> {
top_edges.push(Partial::from(top_edge));
}

top_cycle.write().surface = Partial::from(top_surface.clone());

top_cycle
.write()
.connect_to_closed_edges(top_edges, &top_surface.geometry());
Expand Down Expand Up @@ -165,8 +163,6 @@ mod tests {

let mut face = sketch.add_face();
face.write().surface = Partial::from(surface.clone());
face.write().exterior.write().surface =
Partial::from(surface.clone());
face.write()
.exterior
.write()
Expand All @@ -185,7 +181,6 @@ mod tests {
..Default::default()
};

bottom.exterior.write().surface = Partial::from(surface.clone());
bottom
.exterior
.write()
Expand All @@ -200,11 +195,10 @@ mod tests {
let surface = surface.clone().translate(UP, &mut services.objects);

let mut top = PartialFace {
surface: Partial::from(surface.clone()),
surface: Partial::from(surface),
..Default::default()
};

top.exterior.write().surface = Partial::from(surface);
top.exterior.write().update_as_polygon_from_points(TRIANGLE);

top.build(&mut services.objects)
Expand Down Expand Up @@ -246,8 +240,6 @@ mod tests {

let mut face = sketch.add_face();
face.write().surface = Partial::from(surface.clone());
face.write().exterior.write().surface =
Partial::from(surface.clone());
face.write()
.exterior
.write()
Expand All @@ -265,11 +257,10 @@ mod tests {
surface.clone().translate(DOWN, &mut services.objects);

let mut bottom = PartialFace {
surface: Partial::from(surface.clone()),
surface: Partial::from(surface),
..Default::default()
};

bottom.exterior.write().surface = Partial::from(surface);
bottom
.exterior
.write()
Expand All @@ -286,7 +277,6 @@ mod tests {
..Default::default()
};

top.exterior.write().surface = Partial::from(surface.clone());
top.exterior.write().update_as_polygon_from_points(TRIANGLE);

top.build(&mut services.objects)
Expand Down
6 changes: 1 addition & 5 deletions crates/fj-kernel/src/algorithms/transform/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ impl TransformObject for Cycle {
objects: &mut Service<Objects>,
cache: &mut TransformCache,
) -> Self {
let surface = self
.surface()
.clone()
.transform_with_cache(transform, objects, cache);
let half_edges = self.half_edges().map(|half_edge| {
half_edge
.clone()
.transform_with_cache(transform, objects, cache)
});

Self::new(surface, half_edges)
Self::new(half_edges)
}
}
Loading

0 comments on commit f4bb6f4

Please sign in to comment.