mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-08 03:48:27 +00:00
Merge pull request #2455 from hannobraun/geom
Convert `SurfaceGeom` back into struct
This commit is contained in:
commit
07ffb0f94a
@ -48,7 +48,7 @@ fn approx_curve(
|
||||
boundary: CurveBoundary<Point<1>>,
|
||||
tolerance: impl Into<Tolerance>,
|
||||
) -> CurveApprox {
|
||||
let SurfaceGeom::Basic { u, .. } = surface;
|
||||
let SurfaceGeom { u, .. } = surface;
|
||||
let points = match (path, u) {
|
||||
(SurfacePath::Circle(_), GlobalPath::Circle(_)) => {
|
||||
approx_circle_on_curved_surface()
|
||||
@ -116,7 +116,7 @@ fn approx_line_on_any_surface(
|
||||
.map(|point_curve| [line.point_from_line_coords(point_curve).u]),
|
||||
);
|
||||
|
||||
let SurfaceGeom::Basic { u, .. } = surface;
|
||||
let SurfaceGeom { u, .. } = surface;
|
||||
let approx_u = match u {
|
||||
GlobalPath::Circle(circle) => approx_circle(circle, range_u, tolerance),
|
||||
GlobalPath::Line(line) => approx_line(line),
|
||||
@ -222,7 +222,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn approx_line_on_curved_surface_but_not_along_curve() {
|
||||
let surface = SurfaceGeom::Basic {
|
||||
let surface = SurfaceGeom {
|
||||
u: GlobalPath::circle_from_radius(1.),
|
||||
v: Vector::from([0., 0., 1.]),
|
||||
};
|
||||
@ -242,7 +242,7 @@ mod tests {
|
||||
|
||||
let circle = Circle::from_center_and_radius(Point::origin(), 1.);
|
||||
let global_path = GlobalPath::Circle(circle);
|
||||
let surface_geom = SurfaceGeom::Basic {
|
||||
let surface_geom = SurfaceGeom {
|
||||
u: global_path,
|
||||
v: Vector::from([0., 0., 1.]),
|
||||
};
|
||||
|
@ -15,7 +15,7 @@ impl super::BoundingVolume<3> for &Face {
|
||||
.map(|aabb2| {
|
||||
let surface = geometry.of_surface(self.surface());
|
||||
|
||||
let SurfaceGeom::Basic { u, v } = surface;
|
||||
let SurfaceGeom { u, v } = surface;
|
||||
match u {
|
||||
GlobalPath::Circle(circle) => {
|
||||
// This is not the most precise way to calculate the
|
||||
|
@ -42,21 +42,21 @@ impl Geometry {
|
||||
|
||||
self_.define_surface_inner(
|
||||
self_.xy_plane.clone(),
|
||||
SurfaceGeom::Basic {
|
||||
SurfaceGeom {
|
||||
u: GlobalPath::x_axis(),
|
||||
v: Vector::unit_y(),
|
||||
},
|
||||
);
|
||||
self_.define_surface_inner(
|
||||
self_.xz_plane.clone(),
|
||||
SurfaceGeom::Basic {
|
||||
SurfaceGeom {
|
||||
u: GlobalPath::x_axis(),
|
||||
v: Vector::unit_z(),
|
||||
},
|
||||
);
|
||||
self_.define_surface_inner(
|
||||
self_.yz_plane.clone(),
|
||||
SurfaceGeom::Basic {
|
||||
SurfaceGeom {
|
||||
u: GlobalPath::y_axis(),
|
||||
v: Vector::unit_z(),
|
||||
},
|
||||
|
@ -8,29 +8,18 @@ use super::GlobalPath;
|
||||
|
||||
/// The geometry that defines a surface
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
||||
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,
|
||||
pub struct SurfaceGeom {
|
||||
/// The u-axis of the surface
|
||||
pub u: GlobalPath,
|
||||
|
||||
/// The v-axis of the surface
|
||||
v: Vector<3>,
|
||||
},
|
||||
/// The v-axis of the surface
|
||||
pub v: Vector<3>,
|
||||
}
|
||||
|
||||
impl SurfaceGeom {
|
||||
/// # Access the origin of the surface
|
||||
pub fn origin(&self) -> Point<3> {
|
||||
let Self::Basic { u, .. } = self;
|
||||
let Self { u, .. } = self;
|
||||
match u {
|
||||
GlobalPath::Circle(circle) => circle.center(),
|
||||
GlobalPath::Line(line) => line.origin(),
|
||||
@ -80,7 +69,7 @@ impl SurfaceGeom {
|
||||
) -> (Triangle<3>, [Scalar; 3]) {
|
||||
let point_surface = point_surface.into();
|
||||
|
||||
let Self::Basic { u, v } = self;
|
||||
let Self { u, v } = self;
|
||||
match u {
|
||||
GlobalPath::Circle(circle) => {
|
||||
let params = PathApproxParams::for_circle(circle, tolerance);
|
||||
@ -148,11 +137,11 @@ impl SurfaceGeom {
|
||||
/// Transform the surface geometry
|
||||
#[must_use]
|
||||
pub fn transform(self, transform: &Transform) -> Self {
|
||||
let Self::Basic { u, v } = self;
|
||||
let Self { u, v } = self;
|
||||
|
||||
let u = u.transform(transform);
|
||||
let v = transform.transform_vector(&v);
|
||||
Self::Basic { u, v }
|
||||
Self { u, v }
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,7 +157,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn point_from_surface_coords() {
|
||||
let surface = SurfaceGeom::Basic {
|
||||
let surface = SurfaceGeom {
|
||||
u: GlobalPath::Line(Line::from_origin_and_direction(
|
||||
Point::from([1., 1., 1.]),
|
||||
Vector::from([0., 2., 0.]),
|
||||
@ -187,7 +176,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn vector_from_surface_coords() {
|
||||
let surface = SurfaceGeom::Basic {
|
||||
let surface = SurfaceGeom {
|
||||
u: GlobalPath::Line(Line::from_origin_and_direction(
|
||||
Point::from([1., 0., 0.]),
|
||||
Vector::from([0., 2., 0.]),
|
||||
|
@ -35,7 +35,7 @@ pub trait BuildSurface {
|
||||
core: &mut Core,
|
||||
) -> Handle<Surface> {
|
||||
Self::from_geometry(
|
||||
SurfaceGeom::Basic {
|
||||
SurfaceGeom {
|
||||
u: u.into(),
|
||||
v: v.into(),
|
||||
},
|
||||
|
@ -39,7 +39,7 @@ impl SweepSurfacePath for SurfacePath {
|
||||
path: impl Into<Vector<3>>,
|
||||
core: &mut Core,
|
||||
) -> Handle<Surface> {
|
||||
let SurfaceGeom::Basic { u, .. } = surface;
|
||||
let SurfaceGeom { u, .. } = surface;
|
||||
match u {
|
||||
GlobalPath::Circle(_) => {
|
||||
// Sweeping a `Curve` creates a `Surface`. The u-axis of that
|
||||
|
Loading…
Reference in New Issue
Block a user