Skip to content

Commit

Permalink
Merge pull request #1795 from hannobraun/services
Browse files Browse the repository at this point in the history
Clean up in-kernel services API
  • Loading branch information
hannobraun authored Apr 26, 2023
2 parents d9d954a + 36e698d commit 1aa2509
Show file tree
Hide file tree
Showing 46 changed files with 312 additions and 417 deletions.
22 changes: 8 additions & 14 deletions crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,8 @@ mod tests {
let mut services = Services::new();

let surface = services.objects.surfaces.xz_plane();
let half_edge = HalfEdge::line_segment(
[[1., 1.], [2., 1.]],
None,
&mut services.objects,
);
let half_edge =
HalfEdge::line_segment([[1., 1.], [2., 1.]], None, &mut services);

let tolerance = 1.;
let approx = (&half_edge, surface.deref()).approx(tolerance);
Expand All @@ -293,12 +290,9 @@ mod tests {
u: GlobalPath::circle_from_radius(1.),
v: [0., 0., 1.].into(),
})
.insert(&mut services.objects);
let half_edge = HalfEdge::line_segment(
[[1., 1.], [2., 1.]],
None,
&mut services.objects,
);
.insert(&mut services);
let half_edge =
HalfEdge::line_segment([[1., 1.], [2., 1.]], None, &mut services);

let tolerance = 1.;
let approx = (&half_edge, surface.deref()).approx(tolerance);
Expand All @@ -317,11 +311,11 @@ mod tests {
u: path,
v: [0., 0., 1.].into(),
})
.insert(&mut services.objects);
.insert(&mut services);
let half_edge = HalfEdge::line_segment(
[[0., 1.], [TAU, 1.]],
Some(range.boundary),
&mut services.objects,
&mut services,
);

let tolerance = 1.;
Expand All @@ -346,7 +340,7 @@ mod tests {
let mut services = Services::new();

let surface = services.objects.surfaces.xz_plane();
let half_edge = HalfEdge::circle(1., &mut services.objects);
let half_edge = HalfEdge::circle(1., &mut services);

let tolerance = 1.;
let approx = (&half_edge, surface.deref()).approx(tolerance);
Expand Down
18 changes: 6 additions & 12 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,8 @@ mod tests {
let mut services = Services::new();

let curve = Curve::u_axis();
let half_edge = HalfEdge::line_segment(
[[1., -1.], [1., 1.]],
None,
&mut services.objects,
);
let half_edge =
HalfEdge::line_segment([[1., -1.], [1., 1.]], None, &mut services);

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);

Expand All @@ -107,7 +104,7 @@ mod tests {
let half_edge = HalfEdge::line_segment(
[[-1., -1.], [-1., 1.]],
None,
&mut services.objects,
&mut services,
);

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);
Expand All @@ -128,7 +125,7 @@ mod tests {
let half_edge = HalfEdge::line_segment(
[[-1., -1.], [1., -1.]],
None,
&mut services.objects,
&mut services,
);

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);
Expand All @@ -141,11 +138,8 @@ mod tests {
let mut services = Services::new();

let curve = Curve::u_axis();
let half_edge = HalfEdge::line_segment(
[[-1., 0.], [1., 0.]],
None,
&mut services.objects,
);
let half_edge =
HalfEdge::line_segment([[-1., 0.], [1., 0.]], None, &mut services);

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);

Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
exterior_points,
&mut services.objects,
&mut services,
))
.with_interior(CycleBuilder::polygon(
interior_points,
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
.build(&mut services);

let expected =
CurveFaceIntersection::from_intervals([[[1.], [2.]], [[4.], [5.]]]);
Expand Down
14 changes: 4 additions & 10 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ mod tests {
]
.map(|surface| {
FaceBuilder::new(surface)
.with_exterior(CycleBuilder::polygon(
points,
&mut services.objects,
))
.build(&mut services.objects)
.with_exterior(CycleBuilder::polygon(points, &mut services))
.build(&mut services)
});

let intersection = FaceFaceIntersection::compute([&a, &b]);
Expand All @@ -115,11 +112,8 @@ mod tests {
];
let [a, b] = surfaces.clone().map(|surface| {
FaceBuilder::new(surface)
.with_exterior(CycleBuilder::polygon(
points,
&mut services.objects,
))
.build(&mut services.objects)
.with_exterior(CycleBuilder::polygon(points, &mut services))
.build(&mut services)
});

let intersection = FaceFaceIntersection::compute([&a, &b]);
Expand Down
32 changes: 16 additions & 16 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [1., 1.], [0., 2.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
.build(&mut services);
let point = Point::from([2., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -165,9 +165,9 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [2., 1.], [0., 2.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
.build(&mut services);
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -184,9 +184,9 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[4., 2.], [0., 4.], [0., 0.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
.build(&mut services);
let point = Point::from([1., 2.]);

let intersection = (&face, &point).intersect();
Expand All @@ -203,9 +203,9 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [2., 1.], [3., 0.], [3., 4.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
.build(&mut services);
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -222,9 +222,9 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [2., 1.], [3., 1.], [0., 2.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
.build(&mut services);
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -241,9 +241,9 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [2., 1.], [3., 1.], [4., 0.], [4., 5.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
.build(&mut services);
let point = Point::from([1., 1.]);

let intersection = (&face, &point).intersect();
Expand All @@ -260,9 +260,9 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [2., 0.], [0., 1.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
.build(&mut services);
let point = Point::from([1., 0.]);

let intersection = (&face, &point).intersect();
Expand All @@ -285,9 +285,9 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[0., 0.], [1., 0.], [0., 1.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
.build(&mut services);
let point = Point::from([1., 0.]);

let intersection = (&face, &point).intersect();
Expand Down
40 changes: 20 additions & 20 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.yz_plane())
.with_exterior(CycleBuilder::polygon(
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
let face = face.translate([-1., 0., 0.], &mut services.objects);
.build(&mut services);
let face = face.translate([-1., 0., 0.], &mut services);

assert_eq!((&ray, &face).intersect(), None);
}
Expand All @@ -182,10 +182,10 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.yz_plane())
.with_exterior(CycleBuilder::polygon(
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
let face = face.translate([1., 0., 0.], &mut services.objects);
.build(&mut services);
let face = face.translate([1., 0., 0.], &mut services);

assert_eq!(
(&ray, &face).intersect(),
Expand All @@ -202,10 +202,10 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.yz_plane())
.with_exterior(CycleBuilder::polygon(
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
let face = face.translate([0., 0., 2.], &mut services.objects);
.build(&mut services);
let face = face.translate([0., 0., 2.], &mut services);

assert_eq!((&ray, &face).intersect(), None);
}
Expand All @@ -219,10 +219,10 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.yz_plane())
.with_exterior(CycleBuilder::polygon(
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
let face = face.translate([1., 1., 0.], &mut services.objects);
.build(&mut services);
let face = face.translate([1., 1., 0.], &mut services);

let edge = face
.exterior()
Expand All @@ -244,10 +244,10 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.yz_plane())
.with_exterior(CycleBuilder::polygon(
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
let face = face.translate([1., 1., 1.], &mut services.objects);
.build(&mut services);
let face = face.translate([1., 1., 1.], &mut services);

let vertex = face
.exterior()
Expand All @@ -272,9 +272,9 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
.build(&mut services);

assert_eq!(
(&ray, &face).intersect(),
Expand All @@ -291,10 +291,10 @@ mod tests {
let face = FaceBuilder::new(services.objects.surfaces.xy_plane())
.with_exterior(CycleBuilder::polygon(
[[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]],
&mut services.objects,
&mut services,
))
.build(&mut services.objects);
let face = face.translate([0., 0., 1.], &mut services.objects);
.build(&mut services);
let face = face.translate([0., 0., 1.], &mut services);

assert_eq!((&ray, &face).intersect(), None);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod tests {
xy.clone(),
xy.clone().transform(
&Transform::translation([0., 0., 1.],),
&mut services.objects
&mut services
)
],),
None,
Expand Down
10 changes: 5 additions & 5 deletions crates/fj-kernel/src/algorithms/reverse/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use itertools::Itertools;

use crate::{
objects::{Cycle, HalfEdge, Objects},
objects::{Cycle, HalfEdge},
operations::Insert,
services::Service,
services::Services,
storage::Handle,
};

use super::Reverse;

impl Reverse for Handle<Cycle> {
fn reverse(self, objects: &mut Service<Objects>) -> Self {
fn reverse(self, services: &mut Services) -> Self {
let mut edges = self
.half_edges()
.cloned()
Expand All @@ -27,12 +27,12 @@ impl Reverse for Handle<Cycle> {
next.start_vertex().clone(),
current.global_form().clone(),
)
.insert(objects)
.insert(services)
})
.collect::<Vec<_>>();

edges.reverse();

Cycle::new(edges).insert(objects)
Cycle::new(edges).insert(services)
}
}
Loading

0 comments on commit 1aa2509

Please sign in to comment.