Prepare for follow-on change

This commit is contained in:
Hanno Braun 2024-08-07 20:31:34 +02:00
parent 64f0a6d757
commit 30f08d9f5b
10 changed files with 75 additions and 33 deletions

View File

@ -95,7 +95,8 @@ fn approx_circle_on_straight_surface(
// point available, so it needs to be computed later anyway, in
// the general case.
let point_global = surface.point_from_surface_coords(point_surface);
let point_global =
surface.point_from_surface_coords(point_surface, tolerance);
ApproxPoint::new(point_curve, point_global)
})
.collect()
@ -125,7 +126,8 @@ fn approx_line_on_any_surface(
for (u, _) in approx_u {
let t = (u.t - line.origin().u) / line.direction().u;
let point_surface = line.point_from_line_coords([t]);
let point_global = surface.point_from_surface_coords(point_surface);
let point_global =
surface.point_from_surface_coords(point_surface, tolerance);
points.push(ApproxPoint::new(u, point_global));
}
@ -262,7 +264,7 @@ mod tests {
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(point_surface);
.point_from_surface_coords(point_surface, tolerance);
ApproxPoint::new(point_local, point_global)
})
.collect::<Vec<_>>();
@ -290,7 +292,7 @@ mod tests {
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(point_surface);
.point_from_surface_coords(point_surface, tolerance);
ApproxPoint::new(point_local, point_global)
})
.collect::<Vec<_>>();

View File

@ -16,7 +16,7 @@ pub fn approx_vertex(
curve: &Handle<Curve>,
surface: &Handle<Surface>,
position_curve: Point<1>,
_: impl Into<Tolerance>,
tolerance: impl Into<Tolerance>,
cache: &mut VertexApproxCache,
geometry: &Geometry,
) -> ApproxPoint<1> {
@ -33,7 +33,7 @@ pub fn approx_vertex(
None => {
let position_global = geometry
.of_surface(surface)
.point_from_surface_coords(position_surface);
.point_from_surface_coords(position_surface, tolerance);
cache.insert(vertex, position_global)
}
};

View File

@ -1,8 +1,9 @@
use std::ops::Deref;
use fj_math::Aabb;
use fj_math::{Aabb, Vector};
use crate::{
algorithms::approx::Tolerance,
geometry::{Geometry, GlobalPath, SurfaceGeom},
topology::Face,
};
@ -29,10 +30,28 @@ impl super::BoundingVolume<3> for &Face {
aabb_bottom.merged(&aabb_top)
}
GlobalPath::Line(_) => Aabb {
min: surface.point_from_surface_coords(aabb2.min),
max: surface.point_from_surface_coords(aabb2.max),
},
GlobalPath::Line(_) => {
// A bounding volume must include the body it bounds,
// but does not need to match it precisely. So it's
// okay, if it's a bit larger.
//
// Let's just choose a reasonable tolerance value here,
// then make sure we enlarge the AABB accordingly, to
// make sure it fits.
let tolerance_f64 = 0.001;
let tolerance = Tolerance::from_scalar(tolerance_f64)
.expect("Tolerance provided is larger than zero");
let offset = Vector::from([tolerance_f64; 3]);
Aabb {
min: surface.point_from_surface_coords(
aabb2.min, tolerance,
) - offset,
max: surface.point_from_surface_coords(
aabb2.max, tolerance,
) + offset,
}
}
}
})
}

View File

@ -180,32 +180,32 @@ mod tests {
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(a);
.point_from_surface_coords(a, core.tolerance());
let b = core
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(b);
.point_from_surface_coords(b, core.tolerance());
let e = core
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(e);
.point_from_surface_coords(e, core.tolerance());
let f = core
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(f);
.point_from_surface_coords(f, core.tolerance());
let g = core
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(g);
.point_from_surface_coords(g, core.tolerance());
let h = core
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(h);
.point_from_surface_coords(h, core.tolerance());
// Let's test that some correct triangles are present. We don't need to
// test them all.
@ -275,27 +275,27 @@ mod tests {
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(a);
.point_from_surface_coords(a, core.tolerance());
let b = core
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(b);
.point_from_surface_coords(b, core.tolerance());
let c = core
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(c);
.point_from_surface_coords(c, core.tolerance());
let d = core
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(d);
.point_from_surface_coords(d, core.tolerance());
let e = core
.layers
.geometry
.of_surface(&surface)
.point_from_surface_coords(e);
.point_from_surface_coords(e, core.tolerance());
assert!(triangles.contains_triangle([a, b, d]));
assert!(triangles.contains_triangle([a, d, e]));

View File

@ -118,6 +118,7 @@ impl SurfaceGeom {
pub fn point_from_surface_coords(
&self,
point: impl Into<Point<2>>,
_: impl Into<Tolerance>,
) -> Point<3> {
let point = point.into();
let Self::Basic { u, .. } = self;
@ -157,7 +158,10 @@ mod tests {
use fj_math::{Line, Point, Vector};
use pretty_assertions::assert_eq;
use crate::geometry::{GlobalPath, SurfaceGeom};
use crate::{
algorithms::approx::Tolerance,
geometry::{GlobalPath, SurfaceGeom},
};
#[test]
fn point_from_surface_coords() {
@ -169,8 +173,11 @@ mod tests {
v: Vector::from([0., 0., 2.]),
};
// Value doesn't matter; we're dealing with a plane.
let tolerance = Tolerance::from_scalar(1.).unwrap();
assert_eq!(
surface.point_from_surface_coords([2., 4.]),
surface.point_from_surface_coords([2., 4.], tolerance),
Point::from([1., 5., 9.]),
);
}

View File

@ -93,7 +93,10 @@ impl AddHole for Shell {
core.layers
.geometry
.of_surface(location.face.surface())
.point_from_surface_coords(location.position)
.point_from_surface_coords(
location.position,
core.tolerance(),
)
};
let entry_point = point(&entry_location);

View File

@ -66,7 +66,10 @@ impl SweepSurfacePath for SurfacePath {
let u = match self {
SurfacePath::Circle(circle) => {
let center = surface.point_from_surface_coords(circle.center());
let center = surface.point_from_surface_coords(
circle.center(),
core.tolerance(),
);
let a = surface.vector_from_surface_coords(circle.a());
let b = surface.vector_from_surface_coords(circle.b());
@ -75,7 +78,8 @@ impl SweepSurfacePath for SurfacePath {
GlobalPath::Circle(circle)
}
SurfacePath::Line(line) => {
let origin = surface.point_from_surface_coords(line.origin());
let origin = surface
.point_from_surface_coords(line.origin(), core.tolerance());
let direction =
surface.vector_from_surface_coords(line.direction());

View File

@ -125,6 +125,7 @@ impl SolidValidationError {
.unwrap()
.position,
),
config.tolerance,
),
h.start_vertex().clone(),
))

View File

@ -203,7 +203,7 @@ fn distances(
half_edge: &Handle<HalfEdge>,
end_vertex: &Handle<Vertex>,
surface: &Handle<Surface>,
_: Tolerance,
tolerance: Tolerance,
geometry: &Geometry,
) -> Option<Point<3>> {
let [start, end] = [
@ -229,7 +229,7 @@ fn distances(
Some(
geometry
.of_surface(surface)
.point_from_surface_coords(surface_coords),
.point_from_surface_coords(surface_coords, tolerance),
)
}

View File

@ -162,10 +162,16 @@ impl ValidationCheck<Shell> for CurveGeometryMismatch {
.path
.point_from_path_coords(point_curve);
let a_global =
surface_geom_a.point_from_surface_coords(a_surface);
let b_global =
surface_geom_b.point_from_surface_coords(b_surface);
let a_global = surface_geom_a
.point_from_surface_coords(
a_surface,
config.tolerance,
);
let b_global = surface_geom_b
.point_from_surface_coords(
b_surface,
config.tolerance,
);
let distance = (a_global - b_global).magnitude();