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

Use Instance in even more places #2198

Merged
merged 5 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/fj-core/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mod tests {
})
.insert(&mut core.services)
});
let face = face.translate([-1., 0., 0.], &mut core.services);
let face = face.translate([-1., 0., 0.], &mut core);

assert_eq!((&ray, &face).intersect(), None);
}
Expand All @@ -201,7 +201,7 @@ mod tests {
})
.insert(&mut core.services)
});
let face = face.translate([1., 0., 0.], &mut core.services);
let face = face.translate([1., 0., 0.], &mut core);

assert_eq!(
(&ray, &face).intersect(),
Expand All @@ -228,7 +228,7 @@ mod tests {
})
.insert(&mut core.services)
});
let face = face.translate([0., 0., 2.], &mut core.services);
let face = face.translate([0., 0., 2.], &mut core);

assert_eq!((&ray, &face).intersect(), None);
}
Expand All @@ -252,7 +252,7 @@ mod tests {
})
.insert(&mut core.services)
});
let face = face.translate([1., 1., 0.], &mut core.services);
let face = face.translate([1., 1., 0.], &mut core);

let edge = face
.region()
Expand Down Expand Up @@ -286,7 +286,7 @@ mod tests {
})
.insert(&mut core.services)
});
let face = face.translate([1., 1., 1.], &mut core.services);
let face = face.translate([1., 1., 1.], &mut core);

let vertex = face
.region()
Expand Down Expand Up @@ -347,7 +347,7 @@ mod tests {
})
.insert(&mut core.services)
});
let face = face.translate([0., 0., 1.], &mut core.services);
let face = face.translate([0., 0., 1.], &mut core);

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 core.services
&mut core
)
],),
None,
Expand Down
36 changes: 12 additions & 24 deletions crates/fj-core/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,8 @@ pub trait BuildShell {
.update_half_edge(
cycle.half_edges().nth_circular(0),
|edge| {
edge.reverse_curve_coordinate_systems(
&mut core.services,
)
.insert(&mut core.services)
edge.reverse_curve_coordinate_systems(core)
.insert(&mut core.services)
},
)
.join_to(
Expand All @@ -175,10 +173,8 @@ pub trait BuildShell {
.update_half_edge(
cycle.half_edges().nth_circular(1),
|edge| {
edge.reverse_curve_coordinate_systems(
&mut core.services,
)
.insert(&mut core.services)
edge.reverse_curve_coordinate_systems(core)
.insert(&mut core.services)
},
)
.join_to(
Expand All @@ -190,10 +186,8 @@ pub trait BuildShell {
.update_half_edge(
cycle.half_edges().nth_circular(0),
|edge| {
edge.reverse_curve_coordinate_systems(
&mut core.services,
)
.insert(&mut core.services)
edge.reverse_curve_coordinate_systems(core)
.insert(&mut core.services)
},
)
.join_to(
Expand All @@ -213,28 +207,22 @@ pub trait BuildShell {
.update_half_edge(
cycle.half_edges().nth_circular(0),
|edge| {
edge.reverse_curve_coordinate_systems(
&mut core.services,
)
.insert(&mut core.services)
edge.reverse_curve_coordinate_systems(core)
.insert(&mut core.services)
},
)
.update_half_edge(
cycle.half_edges().nth_circular(1),
|edge| {
edge.reverse_curve_coordinate_systems(
&mut core.services,
)
.insert(&mut core.services)
edge.reverse_curve_coordinate_systems(core)
.insert(&mut core.services)
},
)
.update_half_edge(
cycle.half_edges().nth_circular(2),
|edge| {
edge.reverse_curve_coordinate_systems(
&mut core.services,
)
.insert(&mut core.services)
edge.reverse_curve_coordinate_systems(core)
.insert(&mut core.services)
},
)
.join_to(
Expand Down
10 changes: 3 additions & 7 deletions crates/fj-core/src/operations/reverse/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
objects::{Cycle, HalfEdge},
operations::insert::Insert,
services::Services,
Instance,
};

Expand Down Expand Up @@ -30,13 +29,10 @@ impl Reverse for Cycle {
}

impl ReverseCurveCoordinateSystems for Cycle {
fn reverse_curve_coordinate_systems(
&self,
services: &mut Services,
) -> Self {
fn reverse_curve_coordinate_systems(&self, core: &mut Instance) -> Self {
let edges = self.half_edges().iter().map(|edge| {
edge.reverse_curve_coordinate_systems(services)
.insert(services)
edge.reverse_curve_coordinate_systems(core)
.insert(&mut core.services)
});

Cycle::new(edges)
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/reverse/edge.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{objects::HalfEdge, services::Services};
use crate::{objects::HalfEdge, Instance};

use super::ReverseCurveCoordinateSystems;

impl ReverseCurveCoordinateSystems for HalfEdge {
fn reverse_curve_coordinate_systems(&self, _: &mut Services) -> Self {
fn reverse_curve_coordinate_systems(&self, _: &mut Instance) -> Self {
let path = self.path().reverse();
let boundary = self.boundary().reverse();

Expand Down
29 changes: 8 additions & 21 deletions crates/fj-core/src/operations/reverse/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
build::Polygon,
insert::{Insert, IsInsertedNo, IsInsertedYes},
},
services::Services,
Instance,
};

Expand Down Expand Up @@ -36,44 +35,32 @@ impl<const D: usize> Reverse for Polygon<D, IsInsertedYes> {
}

impl ReverseCurveCoordinateSystems for Face {
fn reverse_curve_coordinate_systems(
&self,
services: &mut Services,
) -> Self {
fn reverse_curve_coordinate_systems(&self, core: &mut Instance) -> Self {
let region = self
.region()
.reverse_curve_coordinate_systems(services)
.insert(services);
.reverse_curve_coordinate_systems(core)
.insert(&mut core.services);
Face::new(self.surface().clone(), region)
}
}

impl<const D: usize> ReverseCurveCoordinateSystems
for Polygon<D, IsInsertedNo>
{
fn reverse_curve_coordinate_systems(
&self,
services: &mut Services,
) -> Self {
let face = self
.face
.borrow()
.reverse_curve_coordinate_systems(services);
fn reverse_curve_coordinate_systems(&self, core: &mut Instance) -> Self {
let face = self.face.borrow().reverse_curve_coordinate_systems(core);
self.replace_face(face)
}
}

impl<const D: usize> ReverseCurveCoordinateSystems
for Polygon<D, IsInsertedYes>
{
fn reverse_curve_coordinate_systems(
&self,
services: &mut Services,
) -> Self {
fn reverse_curve_coordinate_systems(&self, core: &mut Instance) -> Self {
let face: &Face = self.face.borrow();
let face = face
.reverse_curve_coordinate_systems(services)
.insert(services);
.reverse_curve_coordinate_systems(core)
.insert(&mut core.services);

self.replace_face(face)
}
Expand Down
5 changes: 2 additions & 3 deletions crates/fj-core/src/operations/reverse/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Reverse the direction/orientation of objects

use crate::{services::Services, Instance};
use crate::Instance;

mod cycle;
mod edge;
Expand All @@ -20,6 +20,5 @@ pub trait ReverseCurveCoordinateSystems {
///
/// This will not have any effect on object positions in global coordinates.
#[must_use]
fn reverse_curve_coordinate_systems(&self, services: &mut Services)
-> Self;
fn reverse_curve_coordinate_systems(&self, core: &mut Instance) -> Self;
}
17 changes: 6 additions & 11 deletions crates/fj-core/src/operations/reverse/region.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::{
objects::Region, operations::insert::Insert, services::Services, Instance,
};
use crate::{objects::Region, operations::insert::Insert, Instance};

use super::{Reverse, ReverseCurveCoordinateSystems};

Expand All @@ -17,18 +15,15 @@ impl Reverse for Region {
}

impl ReverseCurveCoordinateSystems for Region {
fn reverse_curve_coordinate_systems(
&self,
services: &mut Services,
) -> Self {
fn reverse_curve_coordinate_systems(&self, core: &mut Instance) -> Self {
let exterior = self
.exterior()
.reverse_curve_coordinate_systems(services)
.insert(services);
.reverse_curve_coordinate_systems(core)
.insert(&mut core.services);
let interiors = self.interiors().iter().map(|cycle| {
cycle
.reverse_curve_coordinate_systems(services)
.insert(services)
.reverse_curve_coordinate_systems(core)
.insert(&mut core.services)
});

Region::new(exterior, interiors, self.color())
Expand Down
5 changes: 2 additions & 3 deletions crates/fj-core/src/operations/sweep/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ impl SweepRegion for Region {
.collect::<Vec<_>>();

let top_face = {
let top_surface = surface
.translate(path, &mut core.services)
.insert(&mut core.services);
let top_surface =
surface.translate(path, core).insert(&mut core.services);
let top_region =
Region::new(top_exterior, top_interiors, self.color())
.insert(&mut core.services);
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/transform/curve.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use fj_math::Transform;

use crate::{objects::Curve, services::Services};
use crate::{objects::Curve, Instance};

use super::{TransformCache, TransformObject};

impl TransformObject for Curve {
fn transform_with_cache(
&self,
_: &Transform,
_: &mut Services,
_: &mut Instance,
_: &mut TransformCache,
) -> Self {
// There's nothing to actually transform here, as `Curve` holds no data.
Expand Down
7 changes: 3 additions & 4 deletions crates/fj-core/src/operations/transform/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use fj_math::Transform;

use crate::{objects::Cycle, services::Services};
use crate::{objects::Cycle, Instance};

use super::{TransformCache, TransformObject};

impl TransformObject for Cycle {
fn transform_with_cache(
&self,
transform: &Transform,
services: &mut Services,
core: &mut Instance,
cache: &mut TransformCache,
) -> Self {
let edges = self.half_edges().iter().map(|edge| {
edge.clone()
.transform_with_cache(transform, services, cache)
edge.clone().transform_with_cache(transform, core, cache)
});

Self::new(edges)
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-core/src/operations/transform/edge.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use fj_math::Transform;

use crate::{objects::HalfEdge, services::Services};
use crate::{objects::HalfEdge, Instance};

use super::{TransformCache, TransformObject};

impl TransformObject for HalfEdge {
fn transform_with_cache(
&self,
transform: &Transform,
services: &mut Services,
core: &mut Instance,
cache: &mut TransformCache,
) -> Self {
// Don't need to transform the path, as that's defined in surface
Expand All @@ -18,11 +18,11 @@ impl TransformObject for HalfEdge {
let curve = self
.curve()
.clone()
.transform_with_cache(transform, services, cache);
.transform_with_cache(transform, core, cache);
let start_vertex = self
.start_vertex()
.clone()
.transform_with_cache(transform, services, cache);
.transform_with_cache(transform, core, cache);

Self::new(path, boundary, curve, start_vertex)
}
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-core/src/operations/transform/face.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use fj_math::Transform;

use crate::{objects::Face, services::Services};
use crate::{objects::Face, Instance};

use super::{TransformCache, TransformObject};

impl TransformObject for Face {
fn transform_with_cache(
&self,
transform: &Transform,
services: &mut Services,
core: &mut Instance,
cache: &mut TransformCache,
) -> Self {
let surface = self
.surface()
.clone()
.transform_with_cache(transform, services, cache);
.transform_with_cache(transform, core, cache);
let region = self
.region()
.clone()
.transform_with_cache(transform, services, cache);
.transform_with_cache(transform, core, cache);

Self::new(surface, region)
}
Expand Down
Loading