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

View File

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

View File

@ -1,8 +1,9 @@
use std::ops::Deref; use std::ops::Deref;
use fj_math::Aabb; use fj_math::{Aabb, Vector};
use crate::{ use crate::{
algorithms::approx::Tolerance,
geometry::{Geometry, GlobalPath, SurfaceGeom}, geometry::{Geometry, GlobalPath, SurfaceGeom},
topology::Face, topology::Face,
}; };
@ -29,10 +30,28 @@ impl super::BoundingVolume<3> for &Face {
aabb_bottom.merged(&aabb_top) aabb_bottom.merged(&aabb_top)
} }
GlobalPath::Line(_) => Aabb { GlobalPath::Line(_) => {
min: surface.point_from_surface_coords(aabb2.min), // A bounding volume must include the body it bounds,
max: surface.point_from_surface_coords(aabb2.max), // 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 .layers
.geometry .geometry
.of_surface(&surface) .of_surface(&surface)
.point_from_surface_coords(a); .point_from_surface_coords(a, core.tolerance());
let b = core let b = core
.layers .layers
.geometry .geometry
.of_surface(&surface) .of_surface(&surface)
.point_from_surface_coords(b); .point_from_surface_coords(b, core.tolerance());
let e = core let e = core
.layers .layers
.geometry .geometry
.of_surface(&surface) .of_surface(&surface)
.point_from_surface_coords(e); .point_from_surface_coords(e, core.tolerance());
let f = core let f = core
.layers .layers
.geometry .geometry
.of_surface(&surface) .of_surface(&surface)
.point_from_surface_coords(f); .point_from_surface_coords(f, core.tolerance());
let g = core let g = core
.layers .layers
.geometry .geometry
.of_surface(&surface) .of_surface(&surface)
.point_from_surface_coords(g); .point_from_surface_coords(g, core.tolerance());
let h = core let h = core
.layers .layers
.geometry .geometry
.of_surface(&surface) .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 // Let's test that some correct triangles are present. We don't need to
// test them all. // test them all.
@ -275,27 +275,27 @@ mod tests {
.layers .layers
.geometry .geometry
.of_surface(&surface) .of_surface(&surface)
.point_from_surface_coords(a); .point_from_surface_coords(a, core.tolerance());
let b = core let b = core
.layers .layers
.geometry .geometry
.of_surface(&surface) .of_surface(&surface)
.point_from_surface_coords(b); .point_from_surface_coords(b, core.tolerance());
let c = core let c = core
.layers .layers
.geometry .geometry
.of_surface(&surface) .of_surface(&surface)
.point_from_surface_coords(c); .point_from_surface_coords(c, core.tolerance());
let d = core let d = core
.layers .layers
.geometry .geometry
.of_surface(&surface) .of_surface(&surface)
.point_from_surface_coords(d); .point_from_surface_coords(d, core.tolerance());
let e = core let e = core
.layers .layers
.geometry .geometry
.of_surface(&surface) .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, b, d]));
assert!(triangles.contains_triangle([a, d, e])); assert!(triangles.contains_triangle([a, d, e]));

View File

@ -118,6 +118,7 @@ impl SurfaceGeom {
pub fn point_from_surface_coords( pub fn point_from_surface_coords(
&self, &self,
point: impl Into<Point<2>>, point: impl Into<Point<2>>,
_: impl Into<Tolerance>,
) -> Point<3> { ) -> Point<3> {
let point = point.into(); let point = point.into();
let Self::Basic { u, .. } = self; let Self::Basic { u, .. } = self;
@ -157,7 +158,10 @@ mod tests {
use fj_math::{Line, Point, Vector}; use fj_math::{Line, Point, Vector};
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use crate::geometry::{GlobalPath, SurfaceGeom}; use crate::{
algorithms::approx::Tolerance,
geometry::{GlobalPath, SurfaceGeom},
};
#[test] #[test]
fn point_from_surface_coords() { fn point_from_surface_coords() {
@ -169,8 +173,11 @@ mod tests {
v: Vector::from([0., 0., 2.]), 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!( assert_eq!(
surface.point_from_surface_coords([2., 4.]), surface.point_from_surface_coords([2., 4.], tolerance),
Point::from([1., 5., 9.]), Point::from([1., 5., 9.]),
); );
} }

View File

@ -93,7 +93,10 @@ impl AddHole for Shell {
core.layers core.layers
.geometry .geometry
.of_surface(location.face.surface()) .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); let entry_point = point(&entry_location);

View File

@ -66,7 +66,10 @@ impl SweepSurfacePath for SurfacePath {
let u = match self { let u = match self {
SurfacePath::Circle(circle) => { 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 a = surface.vector_from_surface_coords(circle.a());
let b = surface.vector_from_surface_coords(circle.b()); let b = surface.vector_from_surface_coords(circle.b());
@ -75,7 +78,8 @@ impl SweepSurfacePath for SurfacePath {
GlobalPath::Circle(circle) GlobalPath::Circle(circle)
} }
SurfacePath::Line(line) => { 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 = let direction =
surface.vector_from_surface_coords(line.direction()); surface.vector_from_surface_coords(line.direction());

View File

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

View File

@ -203,7 +203,7 @@ fn distances(
half_edge: &Handle<HalfEdge>, half_edge: &Handle<HalfEdge>,
end_vertex: &Handle<Vertex>, end_vertex: &Handle<Vertex>,
surface: &Handle<Surface>, surface: &Handle<Surface>,
_: Tolerance, tolerance: Tolerance,
geometry: &Geometry, geometry: &Geometry,
) -> Option<Point<3>> { ) -> Option<Point<3>> {
let [start, end] = [ let [start, end] = [
@ -229,7 +229,7 @@ fn distances(
Some( Some(
geometry geometry
.of_surface(surface) .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 .path
.point_from_path_coords(point_curve); .point_from_path_coords(point_curve);
let a_global = let a_global = surface_geom_a
surface_geom_a.point_from_surface_coords(a_surface); .point_from_surface_coords(
let b_global = a_surface,
surface_geom_b.point_from_surface_coords(b_surface); config.tolerance,
);
let b_global = surface_geom_b
.point_from_surface_coords(
b_surface,
config.tolerance,
);
let distance = (a_global - b_global).magnitude(); let distance = (a_global - b_global).magnitude();