Skip to content

Commit 5beee30

Browse files
committed
Prepare SurfaceGeom for better geometry repr
1 parent 2ca54ec commit 5beee30

File tree

7 files changed

+36
-25
lines changed

7 files changed

+36
-25
lines changed

crates/fj-core/src/algorithms/approx/curve.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn approx_curve(
4848
boundary: CurveBoundary<Point<1>>,
4949
tolerance: impl Into<Tolerance>,
5050
) -> CurveApprox {
51-
let SurfaceGeom { u, .. } = surface;
51+
let SurfaceGeom::Basic { u, .. } = surface;
5252
let points = match (path, u) {
5353
(SurfacePath::Circle(_), GlobalPath::Circle(_)) => {
5454
approx_circle_on_curved_surface()
@@ -111,7 +111,7 @@ fn approx_line_on_any_surface(
111111
.map(|point_curve| [line.point_from_line_coords(point_curve).u]),
112112
);
113113

114-
let SurfaceGeom { u, .. } = surface;
114+
let SurfaceGeom::Basic { u, .. } = surface;
115115
let approx_u = match u {
116116
GlobalPath::Circle(circle) => approx_circle(circle, range_u, tolerance),
117117
GlobalPath::Line(line) => approx_line(line),
@@ -216,7 +216,7 @@ mod tests {
216216

217217
#[test]
218218
fn approx_line_on_curved_surface_but_not_along_curve() {
219-
let surface = SurfaceGeom {
219+
let surface = SurfaceGeom::Basic {
220220
u: GlobalPath::circle_from_radius(1.),
221221
v: Vector::from([0., 0., 1.]),
222222
};
@@ -236,7 +236,7 @@ mod tests {
236236

237237
let circle = Circle::from_center_and_radius(Point::origin(), 1.);
238238
let global_path = GlobalPath::Circle(circle);
239-
let surface_geom = SurfaceGeom {
239+
let surface_geom = SurfaceGeom::Basic {
240240
u: global_path,
241241
v: Vector::from([0., 0., 1.]),
242242
};

crates/fj-core/src/algorithms/bounding_volume/face.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl super::BoundingVolume<3> for &Face {
1414
.map(|aabb2| {
1515
let surface = geometry.of_surface(self.surface());
1616

17-
let SurfaceGeom { u, v } = surface;
17+
let SurfaceGeom::Basic { u, v } = surface;
1818
match u {
1919
GlobalPath::Circle(circle) => {
2020
// This is not the most precise way to calculate the

crates/fj-core/src/geometry/geometry.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ impl Geometry {
4242

4343
self_.define_surface_inner(
4444
self_.xy_plane.clone(),
45-
SurfaceGeom {
45+
SurfaceGeom::Basic {
4646
u: GlobalPath::x_axis(),
4747
v: Vector::unit_y(),
4848
},
4949
);
5050
self_.define_surface_inner(
5151
self_.xz_plane.clone(),
52-
SurfaceGeom {
52+
SurfaceGeom::Basic {
5353
u: GlobalPath::x_axis(),
5454
v: Vector::unit_z(),
5555
},
5656
);
5757
self_.define_surface_inner(
5858
self_.yz_plane.clone(),
59-
SurfaceGeom {
59+
SurfaceGeom::Basic {
6060
u: GlobalPath::y_axis(),
6161
v: Vector::unit_z(),
6262
},

crates/fj-core/src/geometry/surface.rs

+25-14
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ use super::GlobalPath;
66

77
/// The geometry that defines a surface
88
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
9-
pub struct SurfaceGeom {
10-
/// The u-axis of the surface
11-
pub u: GlobalPath,
12-
13-
/// The v-axis of the surface
14-
pub v: Vector<3>,
9+
pub enum SurfaceGeom {
10+
/// # Basic definition of surface geometry
11+
///
12+
/// ## Implementation Note
13+
///
14+
/// At the time of writing, this is the sole variant of `SurfaceGeom`.
15+
/// `SurfaceGeom` simply used to be a struct, identical to this variant.
16+
///
17+
/// This was changed as part of a transition to a new, less basic and more
18+
/// flexible, representation of surface geometry.
19+
Basic {
20+
/// The u-axis of the surface
21+
u: GlobalPath,
22+
23+
/// The v-axis of the surface
24+
v: Vector<3>,
25+
},
1526
}
1627

1728
impl SurfaceGeom {
@@ -21,7 +32,7 @@ impl SurfaceGeom {
2132
point: impl Into<Point<2>>,
2233
) -> Point<3> {
2334
let point = point.into();
24-
let Self { u, .. } = self;
35+
let Self::Basic { u, .. } = self;
2536
u.point_from_path_coords([point.u])
2637
+ self.path_to_line().vector_from_line_coords([point.v])
2738
}
@@ -32,19 +43,19 @@ impl SurfaceGeom {
3243
vector: impl Into<Vector<2>>,
3344
) -> Vector<3> {
3445
let vector = vector.into();
35-
let Self { u, .. } = self;
46+
let Self::Basic { u, .. } = self;
3647
u.vector_from_path_coords([vector.u])
3748
+ self.path_to_line().vector_from_line_coords([vector.v])
3849
}
3950

4051
fn path_to_line(&self) -> Line<3> {
41-
let Self { u, v } = self;
52+
let Self::Basic { u, v } = self;
4253
Line::from_origin_and_direction(u.origin(), *v)
4354
}
4455

4556
/// Project the global point into the surface
4657
pub fn project_global_point(&self, point: impl Into<Point<3>>) -> Point<2> {
47-
let Self { u, v } = self;
58+
let Self::Basic { u, v } = self;
4859

4960
let GlobalPath::Line(line) = u else {
5061
todo!("Projecting point into non-plane surface is not supported")
@@ -57,11 +68,11 @@ impl SurfaceGeom {
5768
/// Transform the surface geometry
5869
#[must_use]
5970
pub fn transform(self, transform: &Transform) -> Self {
60-
let Self { u, v } = self;
71+
let Self::Basic { u, v } = self;
6172

6273
let u = u.transform(transform);
6374
let v = transform.transform_vector(&v);
64-
Self { u, v }
75+
Self::Basic { u, v }
6576
}
6677
}
6778

@@ -74,7 +85,7 @@ mod tests {
7485

7586
#[test]
7687
fn point_from_surface_coords() {
77-
let surface = SurfaceGeom {
88+
let surface = SurfaceGeom::Basic {
7889
u: GlobalPath::Line(Line::from_origin_and_direction(
7990
Point::from([1., 1., 1.]),
8091
Vector::from([0., 2., 0.]),
@@ -90,7 +101,7 @@ mod tests {
90101

91102
#[test]
92103
fn vector_from_surface_coords() {
93-
let surface = SurfaceGeom {
104+
let surface = SurfaceGeom::Basic {
94105
u: GlobalPath::Line(Line::from_origin_and_direction(
95106
Point::from([1., 0., 0.]),
96107
Vector::from([0., 2., 0.]),

crates/fj-core/src/operations/build/surface.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub trait BuildSurface {
3535
core: &mut Core,
3636
) -> Handle<Surface> {
3737
Self::from_geometry(
38-
SurfaceGeom {
38+
SurfaceGeom::Basic {
3939
u: u.into(),
4040
v: v.into(),
4141
},

crates/fj-core/src/operations/sweep/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl SweepSurfacePath for SurfacePath {
3939
path: impl Into<Vector<3>>,
4040
core: &mut Core,
4141
) -> Handle<Surface> {
42-
let SurfaceGeom { u, .. } = surface;
42+
let SurfaceGeom::Basic { u, .. } = surface;
4343
match u {
4444
GlobalPath::Circle(_) => {
4545
// Sweeping a `Curve` creates a `Surface`. The u-axis of that

crates/fj-core/src/operations/sweep/sketch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl SweepSketch for Sketch {
4545
.winding(&core.layers.geometry, self.surface())
4646
.is_ccw());
4747

48-
let SurfaceGeom { u, v } =
48+
let SurfaceGeom::Basic { u, v } =
4949
core.layers.geometry.of_surface(&surface);
5050

5151
let is_negative_sweep = {

0 commit comments

Comments
 (0)