Prepare SurfaceGeom for better geometry repr

This commit is contained in:
Hanno Braun 2024-07-26 19:02:44 +02:00
parent 0aac52a0f2
commit 0dade0ea96
7 changed files with 35 additions and 24 deletions

View File

@ -48,7 +48,7 @@ fn approx_curve(
boundary: CurveBoundary<Point<1>>,
tolerance: impl Into<Tolerance>,
) -> CurveApprox {
let SurfaceGeom { u, .. } = surface;
let SurfaceGeom::Basic { u, .. } = surface;
let points = match (path, u) {
(SurfacePath::Circle(_), GlobalPath::Circle(_)) => {
approx_circle_on_curved_surface()
@ -111,7 +111,7 @@ fn approx_line_on_any_surface(
.map(|point_curve| [line.point_from_line_coords(point_curve).u]),
);
let SurfaceGeom { u, .. } = surface;
let SurfaceGeom::Basic { u, .. } = surface;
let approx_u = match u {
GlobalPath::Circle(circle) => approx_circle(circle, range_u, tolerance),
GlobalPath::Line(line) => approx_line(line),
@ -216,7 +216,7 @@ mod tests {
#[test]
fn approx_line_on_curved_surface_but_not_along_curve() {
let surface = SurfaceGeom {
let surface = SurfaceGeom::Basic {
u: GlobalPath::circle_from_radius(1.),
v: Vector::from([0., 0., 1.]),
};
@ -236,7 +236,7 @@ mod tests {
let circle = Circle::from_center_and_radius(Point::origin(), 1.);
let global_path = GlobalPath::Circle(circle);
let surface_geom = SurfaceGeom {
let surface_geom = SurfaceGeom::Basic {
u: global_path,
v: Vector::from([0., 0., 1.]),
};

View File

@ -14,7 +14,7 @@ impl super::BoundingVolume<3> for &Face {
.map(|aabb2| {
let surface = geometry.of_surface(self.surface());
let SurfaceGeom { u, v } = surface;
let SurfaceGeom::Basic { u, v } = surface;
match u {
GlobalPath::Circle(circle) => {
// This is not the most precise way to calculate the

View File

@ -42,21 +42,21 @@ impl Geometry {
self_.define_surface_inner(
self_.xy_plane.clone(),
SurfaceGeom {
SurfaceGeom::Basic {
u: GlobalPath::x_axis(),
v: Vector::unit_y(),
},
);
self_.define_surface_inner(
self_.xz_plane.clone(),
SurfaceGeom {
SurfaceGeom::Basic {
u: GlobalPath::x_axis(),
v: Vector::unit_z(),
},
);
self_.define_surface_inner(
self_.yz_plane.clone(),
SurfaceGeom {
SurfaceGeom::Basic {
u: GlobalPath::y_axis(),
v: Vector::unit_z(),
},

View File

@ -6,12 +6,23 @@ use super::GlobalPath;
/// The geometry that defines a surface
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct SurfaceGeom {
/// The u-axis of the surface
pub u: GlobalPath,
pub enum SurfaceGeom {
/// # Basic definition of surface geometry
///
/// ## Implementation Note
///
/// At the time of writing, this is the sole variant of `SurfaceGeom`.
/// `SurfaceGeom` simply used to be a struct, identical to this variant.
///
/// This was changed as part of a transition to a new, less basic and more
/// flexible, representation of surface geometry.
Basic {
/// The u-axis of the surface
u: GlobalPath,
/// The v-axis of the surface
pub v: Vector<3>,
/// The v-axis of the surface
v: Vector<3>,
},
}
impl SurfaceGeom {
@ -21,7 +32,7 @@ impl SurfaceGeom {
point: impl Into<Point<2>>,
) -> Point<3> {
let point = point.into();
let Self { u, .. } = self;
let Self::Basic { u, .. } = self;
u.point_from_path_coords([point.u])
+ self.path_to_line().vector_from_line_coords([point.v])
}
@ -32,19 +43,19 @@ impl SurfaceGeom {
vector: impl Into<Vector<2>>,
) -> Vector<3> {
let vector = vector.into();
let Self { u, .. } = self;
let Self::Basic { u, .. } = self;
u.vector_from_path_coords([vector.u])
+ self.path_to_line().vector_from_line_coords([vector.v])
}
fn path_to_line(&self) -> Line<3> {
let Self { u, v } = self;
let Self::Basic { u, v } = self;
Line::from_origin_and_direction(u.origin(), *v)
}
/// Project the global point into the surface
pub fn project_global_point(&self, point: impl Into<Point<3>>) -> Point<2> {
let Self { u, v } = self;
let Self::Basic { u, v } = self;
let GlobalPath::Line(line) = u else {
todo!("Projecting point into non-plane surface is not supported")
@ -57,11 +68,11 @@ impl SurfaceGeom {
/// Transform the surface geometry
#[must_use]
pub fn transform(self, transform: &Transform) -> Self {
let Self { u, v } = self;
let Self::Basic { u, v } = self;
let u = u.transform(transform);
let v = transform.transform_vector(&v);
Self { u, v }
Self::Basic { u, v }
}
}
@ -74,7 +85,7 @@ mod tests {
#[test]
fn point_from_surface_coords() {
let surface = SurfaceGeom {
let surface = SurfaceGeom::Basic {
u: GlobalPath::Line(Line::from_origin_and_direction(
Point::from([1., 1., 1.]),
Vector::from([0., 2., 0.]),
@ -90,7 +101,7 @@ mod tests {
#[test]
fn vector_from_surface_coords() {
let surface = SurfaceGeom {
let surface = SurfaceGeom::Basic {
u: GlobalPath::Line(Line::from_origin_and_direction(
Point::from([1., 0., 0.]),
Vector::from([0., 2., 0.]),

View File

@ -35,7 +35,7 @@ pub trait BuildSurface {
core: &mut Core,
) -> Handle<Surface> {
Self::from_geometry(
SurfaceGeom {
SurfaceGeom::Basic {
u: u.into(),
v: v.into(),
},

View File

@ -39,7 +39,7 @@ impl SweepSurfacePath for SurfacePath {
path: impl Into<Vector<3>>,
core: &mut Core,
) -> Handle<Surface> {
let SurfaceGeom { u, .. } = surface;
let SurfaceGeom::Basic { u, .. } = surface;
match u {
GlobalPath::Circle(_) => {
// Sweeping a `Curve` creates a `Surface`. The u-axis of that

View File

@ -45,7 +45,7 @@ impl SweepSketch for Sketch {
.winding(&core.layers.geometry, self.surface())
.is_ccw());
let SurfaceGeom { u, v } =
let SurfaceGeom::Basic { u, v } =
core.layers.geometry.of_surface(&surface);
let is_negative_sweep = {