Skip to content

Commit

Permalink
Merge pull request #1390 from hannobraun/store
Browse files Browse the repository at this point in the history
Take `&mut self` in `Store::insert`
  • Loading branch information
hannobraun authored Nov 24, 2022
2 parents 96e38a8 + bbe795a commit aa54496
Show file tree
Hide file tree
Showing 49 changed files with 304 additions and 289 deletions.
24 changes: 12 additions & 12 deletions crates/fj-kernel/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,18 @@ mod tests {

#[test]
fn approx_line_on_flat_surface() -> anyhow::Result<()> {
let objects = Objects::new();
let mut objects = Objects::new();

let surface =
PartialSurface::from_axes(GlobalPath::x_axis(), [0., 0., 1.])
.build(&objects)?
.insert(&objects)?;
.insert(&mut objects)?;
let mut curve = PartialCurve {
surface: Some(surface),
..Default::default()
};
curve.update_as_line_from_points([[1., 1.], [2., 1.]]);
let curve = curve.build(&objects)?.insert(&objects)?;
let curve = curve.build(&mut objects)?.insert(&mut objects)?;
let range = RangeOnPath::from([[0.], [1.]]);

let approx = (&curve, range).approx(1.);
Expand All @@ -234,20 +234,20 @@ mod tests {
#[test]
fn approx_line_on_curved_surface_but_not_along_curve() -> anyhow::Result<()>
{
let objects = Objects::new();
let mut objects = Objects::new();

let surface = PartialSurface::from_axes(
GlobalPath::circle_from_radius(1.),
[0., 0., 1.],
)
.build(&objects)?
.insert(&objects)?;
.insert(&mut objects)?;
let mut curve = PartialCurve {
surface: Some(surface),
..Default::default()
};
curve.update_as_line_from_points([[1., 1.], [1., 2.]]);
let curve = curve.build(&objects)?.insert(&objects)?;
let curve = curve.build(&mut objects)?.insert(&mut objects)?;
let range = RangeOnPath::from([[0.], [1.]]);

let approx = (&curve, range).approx(1.);
Expand All @@ -258,18 +258,18 @@ mod tests {

#[test]
fn approx_line_on_curved_surface_along_curve() -> anyhow::Result<()> {
let objects = Objects::new();
let mut objects = Objects::new();

let path = GlobalPath::circle_from_radius(1.);
let surface = PartialSurface::from_axes(path, [0., 0., 1.])
.build(&objects)?
.insert(&objects)?;
.insert(&mut objects)?;
let mut curve = PartialCurve {
surface: Some(surface.clone()),
..Default::default()
};
curve.update_as_line_from_points([[0., 1.], [1., 1.]]);
let curve = curve.build(&objects)?.insert(&objects)?;
let curve = curve.build(&mut objects)?.insert(&mut objects)?;

let range = RangeOnPath::from([[0.], [TAU]]);
let tolerance = 1.;
Expand All @@ -293,18 +293,18 @@ mod tests {

#[test]
fn approx_circle_on_flat_surface() -> anyhow::Result<()> {
let objects = Objects::new();
let mut objects = Objects::new();

let surface =
PartialSurface::from_axes(GlobalPath::x_axis(), [0., 0., 1.])
.build(&objects)?
.insert(&objects)?;
.insert(&mut objects)?;
let mut curve = PartialCurve {
surface: Some(surface),
..Default::default()
};
curve.update_as_circle_from_radius(1.);
let curve = curve.build(&objects)?.insert(&objects)?;
let curve = curve.build(&mut objects)?.insert(&mut objects)?;

let range = RangeOnPath::from([[0.], [TAU]]);
let tolerance = 1.;
Expand Down
24 changes: 12 additions & 12 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ mod tests {

#[test]
fn compute_edge_in_front_of_curve_origin() -> anyhow::Result<()> {
let objects = Objects::new();
let mut objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let mut curve = PartialCurve {
surface: Some(surface.clone()),
..Default::default()
};
curve.update_as_u_axis();
let curve = curve.build(&objects)?;
let curve = curve.build(&mut objects)?;
let half_edge = HalfEdge::partial()
.update_as_line_segment_from_points(surface, [[1., -1.], [1., 1.]])
.build(&objects)?;
.build(&mut objects)?;

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

Expand All @@ -110,21 +110,21 @@ mod tests {

#[test]
fn compute_edge_behind_curve_origin() -> anyhow::Result<()> {
let objects = Objects::new();
let mut objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let mut curve = PartialCurve {
surface: Some(surface.clone()),
..Default::default()
};
curve.update_as_u_axis();
let curve = curve.build(&objects)?;
let curve = curve.build(&mut objects)?;
let half_edge = HalfEdge::partial()
.update_as_line_segment_from_points(
surface,
[[-1., -1.], [-1., 1.]],
)
.build(&objects)?;
.build(&mut objects)?;

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

Expand All @@ -139,21 +139,21 @@ mod tests {

#[test]
fn compute_edge_parallel_to_curve() -> anyhow::Result<()> {
let objects = Objects::new();
let mut objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let mut curve = PartialCurve {
surface: Some(surface.clone()),
..Default::default()
};
curve.update_as_u_axis();
let curve = curve.build(&objects)?;
let curve = curve.build(&mut objects)?;
let half_edge = HalfEdge::partial()
.update_as_line_segment_from_points(
surface,
[[-1., -1.], [1., -1.]],
)
.build(&objects)?;
.build(&mut objects)?;

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

Expand All @@ -163,18 +163,18 @@ mod tests {

#[test]
fn compute_edge_on_curve() -> anyhow::Result<()> {
let objects = Objects::new();
let mut objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let mut curve = PartialCurve {
surface: Some(surface.clone()),
..Default::default()
};
curve.update_as_u_axis();
let curve = curve.build(&objects)?;
let curve = curve.build(&mut objects)?;
let half_edge = HalfEdge::partial()
.update_as_line_segment_from_points(surface, [[-1., 0.], [1., 0.]])
.build(&objects)?;
.build(&mut objects)?;

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 @@ -159,7 +159,7 @@ mod tests {

#[test]
fn compute() -> anyhow::Result<()> {
let objects = Objects::new();
let mut objects = Objects::new();

let surface = objects.surfaces.xy_plane();

Expand All @@ -168,7 +168,7 @@ mod tests {
..Default::default()
};
curve.update_as_line_from_points([[-3., 0.], [-2., 0.]]);
let curve = curve.build(&objects)?;
let curve = curve.build(&mut objects)?;

#[rustfmt::skip]
let exterior = [
Expand All @@ -189,7 +189,7 @@ mod tests {
.with_surface(surface)
.with_exterior_polygon_from_points(exterior)
.with_interior_polygon_from_points(interior)
.build(&objects)?;
.build(&mut objects)?;

let expected =
CurveFaceIntersection::from_intervals([[[1.], [2.]], [[4.], [5.]]]);
Expand Down
18 changes: 10 additions & 8 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl FaceFaceIntersection {
/// Compute the intersections between two faces
pub fn compute(
faces: [&Face; 2],
objects: &Objects,
objects: &mut Objects,
) -> Result<Option<Self>, ValidationError> {
let surfaces = faces.map(|face| face.surface().clone());

Expand Down Expand Up @@ -81,7 +81,7 @@ mod tests {

#[test]
fn compute_no_intersection() -> anyhow::Result<()> {
let objects = Objects::new();
let mut objects = Objects::new();

#[rustfmt::skip]
let points = [
Expand All @@ -95,10 +95,11 @@ mod tests {
Face::partial()
.with_surface(surface)
.with_exterior_polygon_from_points(points)
.build(&objects)
.build(&mut objects)
})?;

let intersection = FaceFaceIntersection::compute([&a, &b], &objects)?;
let intersection =
FaceFaceIntersection::compute([&a, &b], &mut objects)?;

assert!(intersection.is_none());

Expand All @@ -107,7 +108,7 @@ mod tests {

#[test]
fn compute_one_intersection() -> anyhow::Result<()> {
let objects = Objects::new();
let mut objects = Objects::new();

#[rustfmt::skip]
let points = [
Expand All @@ -122,10 +123,11 @@ mod tests {
Face::partial()
.with_surface(surface)
.with_exterior_polygon_from_points(points)
.build(&objects)
.build(&mut objects)
})?;

let intersection = FaceFaceIntersection::compute([&a, &b], &objects)?;
let intersection =
FaceFaceIntersection::compute([&a, &b], &mut objects)?;

let expected_curves =
surfaces.try_map_ext(|surface| -> Result<_, ValidationError> {
Expand All @@ -134,7 +136,7 @@ mod tests {
..Default::default()
};
curve.update_as_line_from_points([[0., 0.], [1., 0.]]);
Ok(curve.build(&objects)?.insert(&objects)?)
Ok(curve.build(&mut objects)?.insert(&mut objects)?)
})?;
let expected_intervals =
CurveFaceIntersection::from_intervals([[[-1.], [1.]]]);
Expand Down
Loading

0 comments on commit aa54496

Please sign in to comment.