@@ -61,39 +61,39 @@ func Revolve3D(sdf SDF2, theta float64) SDF3 {
61
61
sin := math .Sin (s .theta )
62
62
cos := math .Cos (s .theta )
63
63
// pre-calculate the normal to the theta line
64
- s .norm = r2.Vec {- sin , cos }
64
+ s .norm = r2.Vec {X : - sin , Y : cos }
65
65
// work out the bounding box
66
66
var vset d2.Set
67
67
if theta == 0 {
68
- vset = []r2.Vec {{1 , 1 }, {- 1 , - 1 }}
68
+ vset = []r2.Vec {{X : 1 , Y : 1 }, {X : - 1 , Y : - 1 }}
69
69
} else {
70
- vset = []r2.Vec {{0 , 0 }, {1 , 0 }, {cos , sin }}
70
+ vset = []r2.Vec {{X : 0 , Y : 0 }, {X : 1 , Y : 0 }, {X : cos , Y : sin }}
71
71
if s .theta > 0.5 * pi {
72
- vset = append (vset , r2.Vec {0 , 1 })
72
+ vset = append (vset , r2.Vec {X : 0 , Y : 1 })
73
73
}
74
74
if s .theta > pi {
75
- vset = append (vset , r2.Vec {- 1 , 0 })
75
+ vset = append (vset , r2.Vec {X : - 1 , Y : 0 })
76
76
}
77
77
if s .theta > 1.5 * pi {
78
- vset = append (vset , r2.Vec {0 , - 1 })
78
+ vset = append (vset , r2.Vec {X : 0 , Y : - 1 })
79
79
}
80
80
}
81
81
bb := s .sdf .Bounds ()
82
82
l := math .Max (math .Abs (bb .Min .X ), math .Abs (bb .Max .X ))
83
83
vmin := r2 .Scale (l , vset .Min ())
84
84
vmax := r2 .Scale (l , vset .Max ())
85
- s .bb = r3.Box {r3.Vec {vmin .X , vmin .Y , bb .Min .Y }, r3.Vec {vmax .X , vmax .Y , bb .Max .Y }}
85
+ s .bb = r3.Box {Min : r3.Vec {X : vmin .X , Y : vmin .Y , Z : bb .Min .Y }, Max : r3.Vec {X : vmax .X , Y : vmax .Y , Z : bb .Max .Y }}
86
86
return & s
87
87
}
88
88
89
89
// Evaluate returns the minimum distance to a solid of revolution.
90
90
func (s * revolution3 ) Evaluate (p r3.Vec ) float64 {
91
91
x := math .Sqrt (p .X * p .X + p .Y * p .Y )
92
- a := s .sdf .Evaluate (r2.Vec {x , p .Z })
92
+ a := s .sdf .Evaluate (r2.Vec {X : x , Y : p .Z })
93
93
b := a
94
94
if s .theta != 0 {
95
95
// combine two vertical planes to give an intersection wedge
96
- d := s .norm .Dot (r2.Vec {p .X , p .Y })
96
+ d := s .norm .Dot (r2.Vec {X : p .X , Y : p .Y })
97
97
if s .theta < pi {
98
98
b = math .Max (- p .Y , d ) // intersect
99
99
} else {
@@ -125,7 +125,7 @@ func Extrude3D(sdf SDF2, height float64) SDF3 {
125
125
s .extrude = NormalExtrude
126
126
// work out the bounding box
127
127
bb := sdf .Bounds ()
128
- s .bb = r3.Box {r3.Vec {bb .Min .X , bb .Min .Y , - s .height }, r3.Vec {bb .Max .X , bb .Max .Y , s .height }}
128
+ s .bb = r3.Box {Min : r3.Vec {X : bb .Min .X , Y : bb .Min .Y , Z : - s .height }, Max : r3.Vec {X : bb .Max .X , Y : bb .Max .Y , Z : s .height }}
129
129
return & s
130
130
}
131
131
@@ -138,7 +138,7 @@ func TwistExtrude3D(sdf SDF2, height, twist float64) SDF3 {
138
138
// work out the bounding box
139
139
bb := sdf .Bounds ()
140
140
l := r2 .Norm (bb .Max )
141
- s .bb = r3.Box {r3.Vec {- l , - l , - s .height }, r3.Vec {l , l , s .height }}
141
+ s .bb = r3.Box {Min : r3.Vec {X : - l , Y : - l , Z : - s .height }, Max : r3.Vec {X : l , Y : l , Z : s .height }}
142
142
return & s
143
143
}
144
144
@@ -150,8 +150,8 @@ func ScaleExtrude3D(sdf SDF2, height float64, scale r2.Vec) SDF3 {
150
150
s .extrude = ScaleExtrude (height , scale )
151
151
// work out the bounding box
152
152
bb := d2 .Box (sdf .Bounds ())
153
- bb = bb .Extend (d2.Box {d2 .MulElem (bb .Min , scale ), d2 .MulElem (bb .Max , scale )})
154
- s .bb = r3.Box {r3.Vec {bb .Min .X , bb .Min .Y , - s .height }, r3.Vec {bb .Max .X , bb .Max .Y , s .height }}
153
+ bb = bb .Extend (d2.Box {Min : d2 .MulElem (bb .Min , scale ), Max : d2 .MulElem (bb .Max , scale )})
154
+ s .bb = r3.Box {Min : r3.Vec {X : bb .Min .X , Y : bb .Min .Y , Z : - s .height }, Max : r3.Vec {X : bb .Max .X , Y : bb .Max .Y , Z : s .height }}
155
155
return & s
156
156
}
157
157
@@ -163,9 +163,9 @@ func ScaleTwistExtrude3D(sdf SDF2, height, twist float64, scale r2.Vec) SDF3 {
163
163
s .extrude = ScaleTwistExtrude (height , twist , scale )
164
164
// work out the bounding box
165
165
bb := d2 .Box (sdf .Bounds ())
166
- bb = bb .Extend (d2.Box {d2 .MulElem (bb .Min , scale ), d2 .MulElem (bb .Max , scale )})
166
+ bb = bb .Extend (d2.Box {Min : d2 .MulElem (bb .Min , scale ), Max : d2 .MulElem (bb .Max , scale )})
167
167
l := r2 .Norm (bb .Max )
168
- s .bb = r3.Box {r3.Vec {- l , - l , - s .height }, r3.Vec {l , l , s .height }}
168
+ s .bb = r3.Box {Min : r3.Vec {X : - l , Y : - l , Z : - s .height }, Max : r3.Vec {X : l , Y : l , Z : s .height }}
169
169
return & s
170
170
}
171
171
@@ -223,16 +223,16 @@ func ExtrudeRounded3D(sdf SDF2, height, round float64) SDF3 {
223
223
// work out the bounding box
224
224
bb := sdf .Bounds ()
225
225
s .bb = r3.Box {
226
- Min : r3 .Sub (r3.Vec {bb .Min .X , bb .Min .Y , - s .height }, d3 .Elem (round )),
227
- Max : r3 .Add (r3.Vec {bb .Max .X , bb .Max .Y , s .height }, d3 .Elem (round )),
226
+ Min : r3 .Sub (r3.Vec {X : bb .Min .X , Y : bb .Min .Y , Z : - s .height }, d3 .Elem (round )),
227
+ Max : r3 .Add (r3.Vec {X : bb .Max .X , Y : bb .Max .Y , Z : s .height }, d3 .Elem (round )),
228
228
}
229
229
return & s
230
230
}
231
231
232
232
// Evaluate returns the minimum distance to a rounded extrusion.
233
233
func (s * extrudeRounded ) Evaluate (p r3.Vec ) float64 {
234
234
// sdf for the projected 2d surface
235
- a := s .sdf .Evaluate (r2.Vec {p .X , p .Y })
235
+ a := s .sdf .Evaluate (r2.Vec {X : p .X , Y : p .Y })
236
236
b := math .Abs (p .Z ) - s .height
237
237
var d float64
238
238
if b > 0 {
@@ -296,8 +296,8 @@ func Loft3D(sdf0, sdf1 SDF2, height, round float64) SDF3 {
296
296
bb1 := d2 .Box (sdf1 .Bounds ())
297
297
bb := bb0 .Extend (bb1 )
298
298
s .bb = r3.Box {
299
- Min : r3 .Sub (r3.Vec {bb .Min .X , bb .Min .Y , - s .height }, d3 .Elem (round )),
300
- Max : r3 .Add (r3.Vec {bb .Max .X , bb .Max .Y , s .height }, d3 .Elem (round ))}
299
+ Min : r3 .Sub (r3.Vec {X : bb .Min .X , Y : bb .Min .Y , Z : - s .height }, d3 .Elem (round )),
300
+ Max : r3 .Add (r3.Vec {X : bb .Max .X , Y : bb .Max .Y , Z : s .height }, d3 .Elem (round ))}
301
301
return & s
302
302
}
303
303
@@ -306,8 +306,8 @@ func (s *loft3) Evaluate(p r3.Vec) float64 {
306
306
// work out the mix value as a function of height
307
307
k := clamp ((0.5 * p .Z / s .height )+ 0.5 , 0 , 1 )
308
308
// mix the 2D SDFs
309
- a0 := s .sdf0 .Evaluate (r2.Vec {p .X , p .Y })
310
- a1 := s .sdf1 .Evaluate (r2.Vec {p .X , p .Y })
309
+ a0 := s .sdf0 .Evaluate (r2.Vec {X : p .X , Y : p .Y })
310
+ a1 := s .sdf1 .Evaluate (r2.Vec {X : p .X , Y : p .Y })
311
311
a := mix (a0 , a1 , k )
312
312
313
313
b := math .Abs (p .Z ) - s .height
@@ -384,7 +384,7 @@ type scaleUniform3 struct {
384
384
385
385
// ScaleUniform3D uniformly scales an SDF3 on all axes.
386
386
func ScaleUniform3D (sdf SDF3 , k float64 ) SDF3 {
387
- m := Scale3d (r3.Vec {k , k , k })
387
+ m := Scale3d (r3.Vec {X : k , Y : k , Z : k })
388
388
return & scaleUniform3 {
389
389
sdf : sdf ,
390
390
k : k ,
@@ -637,7 +637,7 @@ func (s *array3) Evaluate(p r3.Vec) float64 {
637
637
for j := 0 ; j < s .num [0 ]; j ++ {
638
638
for k := 0 ; k < s .num [1 ]; k ++ {
639
639
for l := 0 ; l < s .num [2 ]; l ++ {
640
- x := p .Sub (r3.Vec {float64 (j ) * s .step .X , float64 (k ) * s .step .Y , float64 (l ) * s .step .Z })
640
+ x := p .Sub (r3.Vec {X : float64 (j ) * s .step .X , Y : float64 (k ) * s .step .Y , Z : float64 (l ) * s .step .Z })
641
641
d = s .min (d , s .sdf .Evaluate (x ))
642
642
}
643
643
}
@@ -681,7 +681,7 @@ func RotateUnion3D(sdf SDF3, num int, step m44) SDF3Union {
681
681
mulVertices3 (v , step )
682
682
// v.MulVertices(step)
683
683
}
684
- s .bb = r3.Box {bbMin , bbMax }
684
+ s .bb = r3.Box {Min : bbMin , Max : bbMax }
685
685
return & s
686
686
}
687
687
@@ -737,16 +737,16 @@ func RotateCopy3D(sdf SDF3, num int) SDF3 {
737
737
rmax = l
738
738
}
739
739
}
740
- s .bb = r3.Box {r3.Vec {- rmax , - rmax , zmin }, r3.Vec {rmax , rmax , zmax }}
740
+ s .bb = r3.Box {Min : r3.Vec {X : - rmax , Y : - rmax , Z : zmin }, Max : r3.Vec {X : rmax , Y : rmax , Z : zmax }}
741
741
return & s
742
742
}
743
743
744
744
// Evaluate returns the minimum distance to a rotate/copy SDF3.
745
745
func (s * rotateCopy3 ) Evaluate (p r3.Vec ) float64 {
746
746
// Map p to a point in the first copy sector.
747
- p2 := r2.Vec {p .X , p .Y }
747
+ p2 := r2.Vec {X : p .X , Y : p .Y }
748
748
p2 = d2 .PolarToXY (r2 .Norm (p2 ), sawTooth (math .Atan2 (p2 .Y , p2 .X ), s .theta ))
749
- return s .sdf .Evaluate (r3.Vec {p2 .X , p2 .Y , p .Z })
749
+ return s .sdf .Evaluate (r3.Vec {X : p2 .X , Y : p2 .Y , Z : p .Z })
750
750
}
751
751
752
752
// BoundingBox returns the bounding box of a rotate/copy SDF3.
@@ -842,7 +842,7 @@ func Shell3D(sdf SDF3, thickness float64) SDF3 {
842
842
return & shell3 {
843
843
sdf : sdf ,
844
844
delta : 0.5 * thickness ,
845
- bb : r3 .Box (bb .Enlarge (r3.Vec {thickness , thickness , thickness })),
845
+ bb : r3 .Box (bb .Enlarge (r3.Vec {X : thickness , Y : thickness , Z : thickness })),
846
846
}
847
847
}
848
848
0 commit comments