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

Simplify CycleBuilder and FaceBuilder #1467

Merged
merged 12 commits into from
Dec 20, 2022
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