@@ -137,19 +137,26 @@ end
137
137
# less strict version of above
138
138
decompose (:: Type{Simplex{1}} , f:: Simplex{N, T} ) where {N, T} = decompose (Simplex{1 ,T}, f)
139
139
140
+
141
+ decompose (:: Type{P} , points:: AbstractVector{P} ) where {P<: Point } = points
142
+ function decompose (:: Type{Point{N1, T1}} , points:: AbstractVector{Point{N2, T2}} ) where {N1, T1, N2, T2}
143
+ return map (x-> to_pointn (Point{N1, T1}, x), points)
144
+ end
145
+
140
146
"""
141
147
Get decompose a `HyperRectangle` into points.
142
148
"""
143
149
function decompose (
144
- PT:: Type{Point{N , T1}} , rect:: HyperRectangle{N , T2}
145
- ) where {N , T1, T2}
150
+ PT:: Type{Point{N1 , T1}} , rect:: HyperRectangle{N2 , T2}
151
+ ) where {N1, N2 , T1, T2}
146
152
# The general strategy is that since there are a deterministic number of
147
153
# points, we can generate all points by looking at the binary increments.
148
154
w = widths (rect)
149
155
o = origin (rect)
150
- points = T1[o[j]+ ((i>> (j- 1 ))& 1 )* w[j] for j= 1 : N , i= 0 : (2 ^ N - 1 )]
151
- reshape (reinterpret (PT, points), (2 ^ N, ))
156
+ points = T1[o[j]+ ((i>> (j- 1 ))& 1 )* w[j] for j= 1 : N2 , i= 0 : (2 ^ N2 - 1 )]
157
+ return decompose (PT, reshape (reinterpret (Point{N2, T1}, points), (2 ^ N2,) ))
152
158
end
159
+
153
160
"""
154
161
Get decompose a `HyperRectangle` into Texture Coordinates.
155
162
"""
@@ -163,23 +170,6 @@ function decompose(
163
170
points = T1[((i>> (j- 1 ))& 1 ) for j= 1 : N, i= 0 : (2 ^ N- 1 )]
164
171
reshape (reinterpret (UVWT, points), (8 ,))
165
172
end
166
- decompose (:: Type{FT} , faces:: Vector{FT} ) where {FT<: Face } = faces
167
- function decompose (:: Type{FT1} , faces:: Vector{FT2} ) where {FT1<: Face , FT2<: Face }
168
- isempty (faces) && return FT1[]
169
- N1,N2 = length (FT1), length (FT2)
170
-
171
- n = length (decompose (FT1, first (faces)))
172
- outfaces = Vector {FT1} (undef, length (faces)* n)
173
- i = 1
174
- for face in faces
175
- for outface in decompose (FT1, face)
176
- outfaces[i] = outface
177
- i += 1
178
- end
179
- end
180
- outfaces
181
- end
182
-
183
173
184
174
"""
185
175
Get decompose a `HyperRectangle` into faces.
@@ -198,6 +188,30 @@ function decompose(
198
188
decompose (FT, faces)
199
189
end
200
190
191
+ function decompose (
192
+ FT:: Type{Face{N, T}} , rect:: HyperRectangle{2, T2}
193
+ ) where {N, T, T2}
194
+ return decompose (FT, SimpleRectangle (minimum (rect), widths (rect)))
195
+ end
196
+
197
+ decompose (:: Type{FT} , faces:: Vector{FT} ) where {FT<: Face } = faces
198
+
199
+ function decompose (:: Type{FT1} , faces:: Vector{FT2} ) where {FT1<: Face , FT2<: Face }
200
+ isempty (faces) && return FT1[]
201
+ N1,N2 = length (FT1), length (FT2)
202
+
203
+ n = length (decompose (FT1, first (faces)))
204
+ outfaces = Vector {FT1} (undef, length (faces)* n)
205
+ i = 1
206
+ for face in faces
207
+ for outface in decompose (FT1, face)
208
+ outfaces[i] = outface
209
+ i += 1
210
+ end
211
+ end
212
+ outfaces
213
+ end
214
+
201
215
function decompose (P:: Type{Point{2, PT}} , r:: SimpleRectangle , resolution= (2 ,2 )) where PT
202
216
w, h = resolution
203
217
vec (P[(x,y) for x= range (r. x, stop= r. x+ r. w, length= w), y= range (r. y, stop= r. y+ r. h, length= h)])
283
297
# Define decompose for your own meshtype, to easily convert it to Homogenous attributes
284
298
285
299
# Gets the normal attribute to a mesh
286
- function decompose (T:: Type{Point{3, VT}} , mesh:: AbstractMesh ) where VT
287
- vts = mesh. vertices
288
- eltype (vts) == T && return vts
289
- eltype (vts) <: Point && return map (T, vts)
300
+ function decompose (T:: Type{Point{N, VT}} , mesh:: AbstractMesh ) where {N, VT}
301
+ return decompose (T, mesh. vertices)
290
302
end
291
303
292
304
# gets the wanted face type
0 commit comments