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

Provide &Handle<Surface> to approximation code #2296

Merged
merged 3 commits into from
Mar 26, 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
47 changes: 24 additions & 23 deletions crates/fj-core/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use crate::{
SurfacePath,
},
storage::Handle,
topology::Curve,
topology::{Curve, Surface},
Core,
};

use super::{Approx, ApproxPoint, Tolerance};

impl Approx for (&Handle<Curve>, &HalfEdgeGeometry, &SurfaceGeometry) {
impl Approx for (&Handle<Curve>, &HalfEdgeGeometry, &Handle<Surface>) {
type Approximation = CurveApprox;
type Cache = CurveApproxCache;

Expand All @@ -33,7 +33,7 @@ impl Approx for (&Handle<Curve>, &HalfEdgeGeometry, &SurfaceGeometry) {
None => {
let approx = approx_curve(
&half_edge.path,
surface,
&core.layers.geometry.of_surface(surface),
half_edge.boundary,
tolerance,
core,
Expand Down Expand Up @@ -183,12 +183,9 @@ mod tests {

use crate::{
algorithms::approx::{Approx, ApproxPoint},
geometry::{
CurveBoundary, GlobalPath, HalfEdgeGeometry, SurfaceGeometry,
SurfacePath,
},
operations::insert::Insert,
topology::Curve,
geometry::{CurveBoundary, GlobalPath, HalfEdgeGeometry, SurfacePath},
operations::{build::BuildSurface, insert::Insert},
topology::{Curve, Surface},
Core,
};

Expand All @@ -201,7 +198,7 @@ mod tests {
SurfacePath::line_from_points([[1., 1.], [2., 1.]]);
let boundary = CurveBoundary::from(boundary);
let half_edge = HalfEdgeGeometry { path, boundary };
let surface = core.layers.geometry.xz_plane();
let surface = core.layers.topology.surfaces.xz_plane();

let tolerance = 1.;
let approx =
Expand All @@ -219,10 +216,11 @@ mod tests {
SurfacePath::line_from_points([[1., 1.], [2., 1.]]);
let boundary = CurveBoundary::from(boundary);
let half_edge = HalfEdgeGeometry { path, boundary };
let surface = SurfaceGeometry {
u: GlobalPath::circle_from_radius(1.),
v: [0., 0., 1.].into(),
};
let surface = Surface::from_uv(
GlobalPath::circle_from_radius(1.),
[0., 0., 1.],
&mut core,
);

let tolerance = 1.;
let approx =
Expand All @@ -243,10 +241,7 @@ mod tests {
]);
let boundary = CurveBoundary::from([[0.], [TAU]]);
let half_edge = HalfEdgeGeometry { path, boundary };
let surface = SurfaceGeometry {
u: global_path,
v: [0., 0., 1.].into(),
};
let surface = Surface::from_uv(global_path, [0., 0., 1.], &mut core);

let tolerance = 1.;
let approx =
Expand All @@ -257,8 +252,11 @@ mod tests {
.into_iter()
.map(|(point_local, _)| {
let point_surface = path.point_from_path_coords(point_local);
let point_global =
surface.point_from_surface_coords(point_surface);
let point_global = core
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(point_surface);
ApproxPoint::new(point_local, point_global)
})
.collect::<Vec<_>>();
Expand All @@ -273,7 +271,7 @@ mod tests {
let path = SurfacePath::circle_from_center_and_radius([0., 0.], 1.);
let boundary = CurveBoundary::from([[0.], [TAU]]);
let half_edge = HalfEdgeGeometry { path, boundary };
let surface = core.layers.geometry.xz_plane();
let surface = core.layers.topology.surfaces.xz_plane();

let tolerance = 1.;
let approx =
Expand All @@ -284,8 +282,11 @@ mod tests {
.into_iter()
.map(|(point_local, _)| {
let point_surface = path.point_from_path_coords(point_local);
let point_global =
surface.point_from_surface_coords(point_surface);
let point_global = core
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(point_surface);
ApproxPoint::new(point_local, point_global)
})
.collect::<Vec<_>>();
Expand Down
8 changes: 6 additions & 2 deletions crates/fj-core/src/algorithms/approx/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

use fj_math::Segment;

use crate::{geometry::SurfaceGeometry, topology::Cycle, Core};
use crate::{
storage::Handle,
topology::{Cycle, Surface},
Core,
};

use super::{
edge::{HalfEdgeApprox, HalfEdgeApproxCache},
Approx, ApproxPoint, Tolerance,
};

impl Approx for (&Cycle, &SurfaceGeometry) {
impl Approx for (&Cycle, &Handle<Surface>) {
type Approximation = CycleApprox;
type Cache = HalfEdgeApproxCache;

Expand Down
11 changes: 8 additions & 3 deletions crates/fj-core/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
//! the caller doesn't have to deal with duplicate vertices.

use crate::{
geometry::SurfaceGeometry, storage::Handle, topology::HalfEdge, Core,
storage::Handle,
topology::{HalfEdge, Surface},
Core,
};

use super::{
curve::CurveApproxCache, vertex::VertexApproxCache, Approx, ApproxPoint,
Tolerance,
};

impl Approx for (&Handle<HalfEdge>, &SurfaceGeometry) {
impl Approx for (&Handle<HalfEdge>, &Handle<Surface>) {
type Approximation = HalfEdgeApprox;
type Cache = HalfEdgeApproxCache;

Expand All @@ -36,7 +38,10 @@ impl Approx for (&Handle<HalfEdge>, &SurfaceGeometry) {
match cache.start_position.get(half_edge.start_vertex()) {
Some(position) => position,
None => {
let position_global = surface
let position_global = core
.layers
.geometry
.of_surface(surface)
.point_from_surface_coords(start_position_surface);
cache.start_position.insert(
half_edge.start_vertex().clone(),
Expand Down
10 changes: 2 additions & 8 deletions crates/fj-core/src/algorithms/approx/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,12 @@ impl Approx for &Face {
// would need to provide its own approximation, as the edges that bound
// it have nothing to do with its curvature.

let exterior = (
self.region().exterior().deref(),
&core.layers.geometry.of_surface(self.surface()),
)
let exterior = (self.region().exterior().deref(), self.surface())
.approx_with_cache(tolerance, cache, core);

let mut interiors = BTreeSet::new();
for cycle in self.region().interiors() {
let cycle = (
cycle.deref(),
&core.layers.geometry.of_surface(self.surface()),
)
let cycle = (cycle.deref(), self.surface())
.approx_with_cache(tolerance, cache, core);
interiors.insert(cycle);
}
Expand Down