@@ -5,6 +5,7 @@ using GeometryBasics: attributes
5
5
6
6
@testset " GeometryBasics" begin
7
7
8
+ #= This left till meta is removed completely
8
9
@testset "embedding metadata" begin
9
10
@testset "Meshes" begin
10
11
@@ -130,6 +131,126 @@ using GeometryBasics: attributes
130
131
@test propertynames(m_meta) == (:mesh, :boundingbox)
131
132
end
132
133
end
134
+ =#
135
+ @testset " embedding metadata(new)" begin
136
+ # @testset "Meshes" begin
137
+
138
+ # @testset "per vertex attributes" begin
139
+ # points = rand(Point{3, Float64}, 8)
140
+ # tfaces = TetrahedronFace{Int}[(1, 2, 3, 4), (5, 6, 7, 8)]
141
+ # normals = rand(SVector{3, Float64}, 8)
142
+ # stress = LinRange(0, 1, 8)
143
+ # mesh = Mesh(meta(points, normals = normals, stress = stress), tfaces)
144
+
145
+ # @test hasproperty(coordinates(mesh), :stress)
146
+ # @test hasproperty(coordinates(mesh), :normals)
147
+ # @test coordinates(mesh).stress === stress
148
+ # @test coordinates(mesh).normals === normals
149
+ # @test coordinates(mesh).normals === normals
150
+ # @test GeometryBasics.faces(mesh) === tfaces
151
+ # @test propertynames(coordinates(mesh)) == (:position, :normals, :stress)
152
+
153
+ # end
154
+
155
+ # @testset "per face attributes" begin
156
+
157
+ # # Construct a cube out of Quads
158
+ # points = Point{3, Float64}[
159
+ # (0.0, 0.0, 0.0), (2.0, 0.0, 0.0),
160
+ # (2.0, 2.0, 0.0), (0.0, 2.0, 0.0),
161
+ # (0.0, 0.0, 12.0), (2.0, 0.0, 12.0),
162
+ # (2.0, 2.0, 12.0), (0.0, 2.0, 12.0)
163
+ # ]
164
+
165
+ # facets = QuadFace{Cint}[
166
+ # 1:4,
167
+ # 5:8,
168
+ # [1,5,6,2],
169
+ # [2,6,7,3],
170
+ # [3, 7, 8, 4],
171
+ # [4, 8, 5, 1]
172
+ # ]
173
+
174
+ # markers = Cint[-1, -2, 0, 0, 0, 0]
175
+ # # attach some additional information to our faces!
176
+ # mesh = Mesh(points, meta(facets, markers = markers))
177
+ # @test hasproperty(GeometryBasics.faces(mesh), :markers)
178
+ # # test with === to assert we're not doing any copies
179
+ # @test GeometryBasics.faces(mesh).markers === markers
180
+ # @test coordinates(mesh) === points
181
+ # @test metafree(GeometryBasics.faces(mesh)) === facets
182
+
183
+ # end
184
+
185
+ # end
186
+
187
+ @testset " polygon with metadata" begin
188
+ polys = [Polygon (rand (Point{2 , Float32}, 20 )) for i in 1 : 10 ]
189
+ multipol = MultiPolygon (polys)
190
+ pnames = [randstring (4 ) for i in 1 : 10 ]
191
+ numbers = LinRange (0.0 , 1.0 , 10 )
192
+ bin = rand (Bool, 10 )
193
+ # create a polygon
194
+ poly = GeometryBasics. Feature (polys[1 ], name = pnames[1 ], value = numbers[1 ], category = bin[1 ])
195
+ # create a MultiPolygon with the right type & meta information!
196
+ multipoly = GeometryBasics. Feature (multipol, name = pnames, value = numbers, category = bin)
197
+ @test multipoly isa GeometryBasics. Feature
198
+ @test poly isa GeometryBasics. Feature
199
+
200
+ @test GeometryBasics. getcolumn (poly, :name ) == pnames[1 ]
201
+ @test GeometryBasics. getcolumn (multipoly, :name ) == pnames
202
+
203
+ meta_p = GeometryBasics. Feature (polys[1 ], boundingbox= Rect (0 , 0 , 2 , 2 ))
204
+ @test meta_p. boundingbox === Rect (0 , 0 , 2 , 2 )
205
+ end
206
+ @testset " point with metadata" begin
207
+ p = Point (1.1 , 2.2 )
208
+ @test p isa AbstractVector{Float64}
209
+ pm = GeometryBasics. Feature (Point (1.1 , 2.2 ); a= 1 , b= 2 )
210
+ p1 = Point (2.2 , 3.6 )
211
+ p2 = [p, p1]
212
+ @test coordinates (p2) == p2
213
+ @test pm. rest === (a= 1 , b= 2 )
214
+ @test pm. data === p
215
+ @test propertynames (pm) == (:data , :a , :b )
216
+ end
217
+
218
+ @testset " MultiPoint with metadata" begin
219
+ p = collect (Point {2, Float64} (x, x+ 1 ) for x in 1 : 5 )
220
+ @test p isa AbstractVector
221
+ mpm = GeometryBasics. Feature (MultiPoint (p), a= 1 , b= 2 )
222
+ @test coordinates (mpm. data) == Point{2 , Float64}[(x, x+ 1 ) for x in 1 : 5 ]
223
+ @test mpm. rest === (a= 1 , b= 2 )
224
+ @test mpm. data == p
225
+ @test propertynames (mpm) == (:data , :a , :b )
226
+ end
227
+
228
+ @testset " LineString with metadata" begin
229
+ linestring = GeometryBasics. Feature (LineString (Point{2 , Int}[(10 , 10 ), (20 , 20 ), (10 , 40 )]), a = 1 , b = 2 )
230
+ @test linestring isa GeometryBasics. Feature
231
+ @test linestring. rest === (a = 1 , b = 2 )
232
+ @test propertynames (linestring) == (:data , :a , :b )
233
+ end
234
+
235
+ @testset " MultiLineString with metadata" begin
236
+ linestring1 = LineString (Point{2 , Int}[(10 , 10 ), (20 , 20 ), (10 , 40 )])
237
+ linestring2 = LineString (Point{2 , Int}[(40 , 40 ), (30 , 30 ), (40 , 20 ), (30 , 10 )])
238
+ multilinestring = MultiLineString ([linestring1, linestring2])
239
+ multilinestringmeta = GeometryBasics. Feature (MultiLineString ([linestring1, linestring2]); boundingbox = Rect (1.0 , 1.0 , 2.0 , 2.0 ))
240
+ @test multilinestringmeta isa GeometryBasics. Feature
241
+ @test multilinestringmeta. rest === (boundingbox = Rect (1.0 , 1.0 , 2.0 , 2.0 ),)
242
+ @test multilinestringmeta. data == multilinestring
243
+ @test propertynames (multilinestringmeta) == (:data , :boundingbox )
244
+ end
245
+
246
+ # @testset "Mesh with metadata" begin
247
+ # m = triangle_mesh(Sphere(Point3f0(0), 1))
248
+ # m_meta = MeshMeta(m; boundingbox=Rect(1.0, 1.0, 2.0, 2.0))
249
+ # @test meta(m_meta) === (boundingbox = Rect(1.0, 1.0, 2.0, 2.0),)
250
+ # @test metafree(m_meta) === m
251
+ # @test propertynames(m_meta) == (:mesh, :boundingbox)
252
+ # end
253
+ end
133
254
134
255
@testset " view" begin
135
256
@testset " TupleView" begin
0 commit comments