Skip to content

Commit

Permalink
Merge pull request #1467 from hannobraun/builder
Browse files Browse the repository at this point in the history
Simplify `CycleBuilder` and `FaceBuilder`
  • Loading branch information
hannobraun authored Dec 20, 2022
2 parents b2bac62 + 649e313 commit d4b4c9f
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 175 deletions.
9 changes: 5 additions & 4 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ mod tests {
fn compute() {
let mut services = Services::new();

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

let mut curve = PartialCurve {
surface: Partial::from(surface.clone()),
surface: surface.clone(),
..Default::default()
};
curve.update_as_line_from_points([[-3., 0.], [-2., 0.]]);
Expand All @@ -187,8 +187,9 @@ mod tests {

let face = {
let mut face = PartialFace::default();
face.update_exterior_as_polygon(surface.clone(), exterior);
face.add_interior_polygon(surface, interior);
face.exterior.write().surface = surface;
face.update_exterior_as_polygon(exterior);
face.add_interior_polygon(interior);

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

face.build(&mut services.objects)
});
Expand Down Expand Up @@ -122,7 +123,8 @@ mod tests {
];
let [a, b] = surfaces.clone().map(|surface| {
let mut face = PartialFace::default();
face.update_exterior_as_polygon(surface, points);
face.exterior.write().surface = Partial::from(surface);
face.update_exterior_as_polygon(points);

face.build(&mut services.objects)
});
Expand Down
82 changes: 41 additions & 41 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,18 @@ mod tests {
builder::FaceBuilder,
insert::Insert,
iter::ObjectIters,
partial::{PartialFace, PartialObject},
partial::{Partial, PartialFace, PartialObject},
services::Services,
};

#[test]
fn point_is_outside_face() {
let mut services = Services::new();

let surface = services.objects.surfaces.xy_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[0., 0.], [1., 1.], [0., 2.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
face.update_exterior_as_polygon([[0., 0.], [1., 1.], [0., 2.]]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects);
Expand All @@ -166,12 +164,10 @@ mod tests {
fn ray_hits_vertex_while_passing_outside() {
let mut services = Services::new();

let surface = services.objects.surfaces.xy_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[0., 0.], [2., 1.], [0., 2.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
face.update_exterior_as_polygon([[0., 0.], [2., 1.], [0., 2.]]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects);
Expand All @@ -188,12 +184,10 @@ mod tests {
fn ray_hits_vertex_at_cycle_seam() {
let mut services = Services::new();

let surface = services.objects.surfaces.xy_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[4., 2.], [0., 4.], [0., 0.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
face.update_exterior_as_polygon([[4., 2.], [0., 4.], [0., 0.]]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects);
Expand All @@ -210,12 +204,15 @@ mod tests {
fn ray_hits_vertex_while_staying_inside() {
let mut services = Services::new();

let surface = services.objects.surfaces.xy_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[0., 0.], [2., 1.], [3., 0.], [3., 4.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
face.update_exterior_as_polygon([
[0., 0.],
[2., 1.],
[3., 0.],
[3., 4.],
]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects);
Expand All @@ -232,12 +229,15 @@ mod tests {
fn ray_hits_parallel_edge_and_leaves_face_at_vertex() {
let mut services = Services::new();

let surface = services.objects.surfaces.xy_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[0., 0.], [2., 1.], [3., 1.], [0., 2.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
face.update_exterior_as_polygon([
[0., 0.],
[2., 1.],
[3., 1.],
[0., 2.],
]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects);
Expand All @@ -254,12 +254,16 @@ mod tests {
fn ray_hits_parallel_edge_and_does_not_leave_face_there() {
let mut services = Services::new();

let surface = services.objects.surfaces.xy_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[0., 0.], [2., 1.], [3., 1.], [4., 0.], [4., 5.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
face.update_exterior_as_polygon([
[0., 0.],
[2., 1.],
[3., 1.],
[4., 0.],
[4., 5.],
]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects);
Expand All @@ -276,12 +280,10 @@ mod tests {
fn point_is_coincident_with_edge() {
let mut services = Services::new();

let surface = services.objects.surfaces.xy_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[0., 0.], [2., 0.], [0., 1.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
face.update_exterior_as_polygon([[0., 0.], [2., 0.], [0., 1.]]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects);
Expand All @@ -307,12 +309,10 @@ mod tests {
fn point_is_coincident_with_vertex() {
let mut services = Services::new();

let surface = services.objects.surfaces.xy_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[0., 0.], [1., 0.], [0., 1.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
face.update_exterior_as_polygon([[0., 0.], [1., 0.], [0., 1.]]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects);
Expand Down
93 changes: 57 additions & 36 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ mod tests {
builder::FaceBuilder,
insert::Insert,
iter::ObjectIters,
partial::{PartialFace, PartialObject},
partial::{Partial, PartialFace, PartialObject},
services::Services,
};

Expand All @@ -165,12 +165,15 @@ mod tests {

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

let surface = services.objects.surfaces.yz_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.yz_plane());
face.update_exterior_as_polygon([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects)
Expand All @@ -185,12 +188,15 @@ mod tests {

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

let surface = services.objects.surfaces.yz_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.yz_plane());
face.update_exterior_as_polygon([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects)
Expand All @@ -208,12 +214,15 @@ mod tests {

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

let surface = services.objects.surfaces.yz_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.yz_plane());
face.update_exterior_as_polygon([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects)
Expand All @@ -228,12 +237,15 @@ mod tests {

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

let surface = services.objects.surfaces.yz_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.yz_plane());
face.update_exterior_as_polygon([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects)
Expand All @@ -259,12 +271,15 @@ mod tests {

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

let surface = services.objects.surfaces.yz_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.yz_plane());
face.update_exterior_as_polygon([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects)
Expand All @@ -288,12 +303,15 @@ mod tests {

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

let surface = services.objects.surfaces.xy_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
face.update_exterior_as_polygon([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects);
Expand All @@ -310,12 +328,15 @@ mod tests {

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

let surface = services.objects.surfaces.xy_plane();
let mut face = PartialFace::default();
face.update_exterior_as_polygon(
surface,
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
);
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
face.update_exterior_as_polygon([
[-1., -1.],
[1., -1.],
[1., 1.],
[-1., 1.],
]);
let face = face
.build(&mut services.objects)
.insert(&mut services.objects)
Expand Down
Loading

0 comments on commit d4b4c9f

Please sign in to comment.