@@ -6,12 +6,23 @@ use super::GlobalPath;
6
6
7
7
/// The geometry that defines a surface
8
8
#[ 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
+ } ,
15
26
}
16
27
17
28
impl SurfaceGeom {
@@ -21,7 +32,8 @@ impl SurfaceGeom {
21
32
point : impl Into < Point < 2 > > ,
22
33
) -> Point < 3 > {
23
34
let point = point. into ( ) ;
24
- self . u . point_from_path_coords ( [ point. u ] )
35
+ let Self :: Basic { u, .. } = self ;
36
+ u. point_from_path_coords ( [ point. u ] )
25
37
+ self . path_to_line ( ) . vector_from_line_coords ( [ point. v ] )
26
38
}
27
39
@@ -31,31 +43,36 @@ impl SurfaceGeom {
31
43
vector : impl Into < Vector < 2 > > ,
32
44
) -> Vector < 3 > {
33
45
let vector = vector. into ( ) ;
34
- self . u . vector_from_path_coords ( [ vector. u ] )
46
+ let Self :: Basic { u, .. } = self ;
47
+ u. vector_from_path_coords ( [ vector. u ] )
35
48
+ self . path_to_line ( ) . vector_from_line_coords ( [ vector. v ] )
36
49
}
37
50
38
51
fn path_to_line ( & self ) -> Line < 3 > {
39
- Line :: from_origin_and_direction ( self . u . origin ( ) , self . v )
52
+ let Self :: Basic { u, v } = self ;
53
+ Line :: from_origin_and_direction ( u. origin ( ) , * v)
40
54
}
41
55
42
56
/// Project the global point into the surface
43
57
pub fn project_global_point ( & self , point : impl Into < Point < 3 > > ) -> Point < 2 > {
44
- let GlobalPath :: Line ( line) = self . u else {
58
+ let Self :: Basic { u, v } = self ;
59
+
60
+ let GlobalPath :: Line ( line) = u else {
45
61
todo ! ( "Projecting point into non-plane surface is not supported" )
46
62
} ;
47
63
48
- let plane =
49
- Plane :: from_parametric ( line. origin ( ) , line. direction ( ) , self . v ) ;
64
+ let plane = Plane :: from_parametric ( line. origin ( ) , line. direction ( ) , * v) ;
50
65
plane. project_point ( point)
51
66
}
52
67
53
68
/// Transform the surface geometry
54
69
#[ must_use]
55
70
pub fn transform ( self , transform : & Transform ) -> Self {
56
- let u = self . u . transform ( transform) ;
57
- let v = transform. transform_vector ( & self . v ) ;
58
- Self { u, v }
71
+ let Self :: Basic { u, v } = self ;
72
+
73
+ let u = u. transform ( transform) ;
74
+ let v = transform. transform_vector ( & v) ;
75
+ Self :: Basic { u, v }
59
76
}
60
77
}
61
78
@@ -68,7 +85,7 @@ mod tests {
68
85
69
86
#[ test]
70
87
fn point_from_surface_coords ( ) {
71
- let surface = SurfaceGeom {
88
+ let surface = SurfaceGeom :: Basic {
72
89
u : GlobalPath :: Line ( Line :: from_origin_and_direction (
73
90
Point :: from ( [ 1. , 1. , 1. ] ) ,
74
91
Vector :: from ( [ 0. , 2. , 0. ] ) ,
@@ -84,7 +101,7 @@ mod tests {
84
101
85
102
#[ test]
86
103
fn vector_from_surface_coords ( ) {
87
- let surface = SurfaceGeom {
104
+ let surface = SurfaceGeom :: Basic {
88
105
u : GlobalPath :: Line ( Line :: from_origin_and_direction (
89
106
Point :: from ( [ 1. , 0. , 0. ] ) ,
90
107
Vector :: from ( [ 0. , 2. , 0. ] ) ,
0 commit comments