@@ -37,8 +37,11 @@ impl<M: Clone + Debug + Send + Sync> Mesh<M> {
3737
3838 // ------------ Specific minimal‑surface flavours --------------------
3939
40- /// Gyroid surface: `sin x cos y + sin y cos z + sin z cos x = iso`
41- /// (`period` rescales the spatial frequency; larger => slower repeat)
40+ /// Gyroid surface: `sin x cos y + sin y cos z + sin z cos x = iso`
41+ /// after scaling coordinates by `2π / period`.
42+ ///
43+ /// `period` is a spatial wavelength in model units; larger values repeat
44+ /// more slowly.
4245 /// **Mathematical Foundation**: Gyroid is a triply periodic minimal surface with zero mean curvature.
4346 /// **Optimization**: Pre-compute trigonometric values for better performance.
4447 pub fn gyroid (
@@ -49,13 +52,13 @@ impl<M: Clone + Debug + Send + Sync> Mesh<M> {
4952 metadata : M ,
5053 ) -> Mesh < M > {
5154 let res = ( resolution. max ( 2 ) , resolution. max ( 2 ) , resolution. max ( 2 ) ) ;
52- let period_inv = 1.0 / period;
55+ let scale = std :: f64 :: consts :: TAU as Real / period;
5356 self . tpms_from_sdf (
5457 move |p : & Point3 < Real > | {
5558 // Pre-compute scaled coordinates for efficiency
56- let x_scaled = p. x * period_inv ;
57- let y_scaled = p. y * period_inv ;
58- let z_scaled = p. z * period_inv ;
59+ let x_scaled = p. x * scale ;
60+ let y_scaled = p. y * scale ;
61+ let z_scaled = p. z * scale ;
5962
6063 // Pre-compute trigonometric values to avoid redundant calculations
6164 let ( sin_x, cos_x) = x_scaled. sin_cos ( ) ;
@@ -73,6 +76,7 @@ impl<M: Clone + Debug + Send + Sync> Mesh<M> {
7376 }
7477
7578 /// Schwarz‑P surface: `cos x + cos y + cos z = iso` (default iso = 0)
79+ /// after scaling coordinates by `2π / period`.
7680 /// **Mathematical Foundation**: Schwarz P-surface has constant mean curvature and cubic symmetry.
7781 /// **Optimization**: Use direct cosine computation for this simpler surface equation.
7882 pub fn schwarz_p (
@@ -83,13 +87,13 @@ impl<M: Clone + Debug + Send + Sync> Mesh<M> {
8387 metadata : M ,
8488 ) -> Mesh < M > {
8589 let res = ( resolution. max ( 2 ) , resolution. max ( 2 ) , resolution. max ( 2 ) ) ;
86- let period_inv = 1.0 / period;
90+ let scale = std :: f64 :: consts :: TAU as Real / period;
8791 self . tpms_from_sdf (
8892 move |p : & Point3 < Real > | {
8993 // Pre-compute scaled coordinates
90- let x_scaled = p. x * period_inv ;
91- let y_scaled = p. y * period_inv ;
92- let z_scaled = p. z * period_inv ;
94+ let x_scaled = p. x * scale ;
95+ let y_scaled = p. y * scale ;
96+ let z_scaled = p. z * scale ;
9397
9498 // **Mathematical Formula**: Schwarz P-surface equation
9599 // P(x,y,z) = cos(x) + cos(y) + cos(z)
@@ -102,6 +106,7 @@ impl<M: Clone + Debug + Send + Sync> Mesh<M> {
102106 }
103107
104108 /// Schwarz‑D (Diamond) surface: `sin x sin y sin z + sin x cos y cos z + ... = iso`
109+ /// after scaling coordinates by `2π / period`.
105110 /// **Mathematical Foundation**: Diamond surface exhibits tetrahedral symmetry and is self-intersecting.
106111 /// **Optimization**: Pre-compute all trigonometric values for maximum efficiency.
107112 pub fn schwarz_d (
@@ -112,13 +117,13 @@ impl<M: Clone + Debug + Send + Sync> Mesh<M> {
112117 metadata : M ,
113118 ) -> Mesh < M > {
114119 let res = ( resolution. max ( 2 ) , resolution. max ( 2 ) , resolution. max ( 2 ) ) ;
115- let period_inv = 1.0 / period;
120+ let scale = std :: f64 :: consts :: TAU as Real / period;
116121 self . tpms_from_sdf (
117122 move |p : & Point3 < Real > | {
118123 // Pre-compute scaled coordinates
119- let x_scaled = p. x * period_inv ;
120- let y_scaled = p. y * period_inv ;
121- let z_scaled = p. z * period_inv ;
124+ let x_scaled = p. x * scale ;
125+ let y_scaled = p. y * scale ;
126+ let z_scaled = p. z * scale ;
122127
123128 // Pre-compute all trigonometric values once
124129 let ( sin_x, cos_x) = x_scaled. sin_cos ( ) ;
0 commit comments