@@ -5,8 +5,7 @@ using GeometryBasics: attributes
5
5
6
6
@testset " GeometryBasics" begin
7
7
8
- #= This left till meta is removed completely
9
- # @testset "embedding metadata" begin
8
+ @testset " embedding metadata" begin
10
9
@testset " Meshes" begin
11
10
12
11
@testset " per vertex attributes" begin
@@ -130,78 +129,26 @@ using GeometryBasics: attributes
130
129
@test metafree (m_meta) === m
131
130
@test propertynames (m_meta) == (:mesh , :boundingbox )
132
131
end
133
- # end
134
- =#
135
-
136
- @testset " embedding metadata(new)" begin
137
- # @testset "Meshes" begin
138
-
139
- # @testset "per vertex attributes" begin
140
- # points = rand(Point{3, Float64}, 8)
141
- # tfaces = TetrahedronFace{Int}[(1, 2, 3, 4), (5, 6, 7, 8)]
142
- # normals = rand(SVector{3, Float64}, 8)
143
- # stress = LinRange(0, 1, 8)
144
- # mesh = Mesh(meta(points, normals = normals, stress = stress), tfaces)
145
-
146
- # @test hasproperty(coordinates(mesh), :stress)
147
- # @test hasproperty(coordinates(mesh), :normals)
148
- # @test coordinates(mesh).stress === stress
149
- # @test coordinates(mesh).normals === normals
150
- # @test coordinates(mesh).normals === normals
151
- # @test GeometryBasics.faces(mesh) === tfaces
152
- # @test propertynames(coordinates(mesh)) == (:position, :normals, :stress)
153
-
154
- # end
155
-
156
- # @testset "per face attributes" begin
157
-
158
- # # Construct a cube out of Quads
159
- # points = Point{3, Float64}[
160
- # (0.0, 0.0, 0.0), (2.0, 0.0, 0.0),
161
- # (2.0, 2.0, 0.0), (0.0, 2.0, 0.0),
162
- # (0.0, 0.0, 12.0), (2.0, 0.0, 12.0),
163
- # (2.0, 2.0, 12.0), (0.0, 2.0, 12.0)
164
- # ]
165
-
166
- # facets = QuadFace{Cint}[
167
- # 1:4,
168
- # 5:8,
169
- # [1,5,6,2],
170
- # [2,6,7,3],
171
- # [3, 7, 8, 4],
172
- # [4, 8, 5, 1]
173
- # ]
174
-
175
- # markers = Cint[-1, -2, 0, 0, 0, 0]
176
- # # attach some additional information to our faces!
177
- # mesh = Mesh(points, meta(facets, markers = markers))
178
- # @test hasproperty(GeometryBasics.faces(mesh), :markers)
179
- # # test with === to assert we're not doing any copies
180
- # @test GeometryBasics.faces(mesh).markers === markers
181
- # @test coordinates(mesh) === points
182
- # @test metafree(GeometryBasics.faces(mesh)) === facets
183
-
184
- # end
185
-
186
- # end
187
-
188
- @testset " polygon with metadata" begin
132
+ end
133
+
134
+ @testset " embedding Feature" begin
135
+ @testset " Feature{Polygon}" begin
189
136
polys = [Polygon (rand (Point{2 , Float32}, 20 )) for i in 1 : 10 ]
190
137
multipol = MultiPolygon (polys)
191
138
pnames = [randstring (4 ) for i in 1 : 10 ]
192
139
numbers = LinRange (0.0 , 1.0 , 10 )
193
140
bin = rand (Bool, 10 )
194
141
# create a polygon
195
- poly = GeometryBasics . Feature (polys[1 ], name = pnames[1 ], value = numbers[1 ], category = bin[1 ])
142
+ poly = Feature (polys[1 ], name = pnames[1 ], value = numbers[1 ], category = bin[1 ])
196
143
# create a MultiPolygon with the right type & meta information!
197
- multipoly = GeometryBasics . Feature (multipol, name = pnames, value = numbers, category = bin)
198
- @test multipoly isa GeometryBasics . Feature
199
- @test poly isa GeometryBasics . Feature
144
+ multipoly = Feature (multipol, name = pnames, value = numbers, category = bin)
145
+ @test multipoly isa Feature
146
+ @test poly isa Feature
200
147
201
148
@test GeometryBasics. getcolumn (poly, :name ) == pnames[1 ]
202
149
@test GeometryBasics. getcolumn (multipoly, :name ) == pnames
203
150
204
- meta_p = GeometryBasics . Feature (polys[1 ], boundingbox= Rect (0 , 0 , 2 , 2 ))
151
+ meta_p = Feature (polys[1 ], boundingbox= Rect (0 , 0 , 2 , 2 ))
205
152
@test meta_p. boundingbox === Rect (0 , 0 , 2 , 2 )
206
153
@test GeometryBasics. metafree (meta_p) == polys[1 ]
207
154
@test GeometryBasics. metafree (poly) == polys[1 ]
@@ -211,10 +158,10 @@ using GeometryBasics: attributes
211
158
@test GeometryBasics. meta (multipoly) == (name = pnames, value = numbers, category = bin)
212
159
end
213
160
214
- @testset " point with metadata " begin
161
+ @testset " Feature{Point} " begin
215
162
p = Point (1.1 , 2.2 )
216
163
@test p isa AbstractVector{Float64}
217
- pm = GeometryBasics . Feature (Point (1.1 , 2.2 ); a= 1 , b= 2 )
164
+ pm = Feature (Point (1.1 , 2.2 ); a= 1 , b= 2 )
218
165
p1 = Point (2.2 , 3.6 )
219
166
p2 = [p, p1]
220
167
@test coordinates (p2) == p2
@@ -225,10 +172,10 @@ using GeometryBasics: attributes
225
172
@test GeometryBasics. meta (pm) == (a = 1 , b = 2 )
226
173
end
227
174
228
- @testset " MultiPoint with metadata " begin
175
+ @testset " Feature{ MultiPoint} " begin
229
176
p = collect (Point {2, Float64} (x, x+ 1 ) for x in 1 : 5 )
230
177
@test p isa AbstractVector
231
- mpm = GeometryBasics . Feature (MultiPoint (p); a= 1 , b= 2 )
178
+ mpm = Feature (MultiPoint (p); a= 1 , b= 2 )
232
179
@test coordinates (mpm. data) == Point{2 , Float64}[(x, x+ 1 ) for x in 1 : 5 ]
233
180
@test mpm. rest === (a= 1 , b= 2 )
234
181
@test mpm. data == p
@@ -237,35 +184,50 @@ using GeometryBasics: attributes
237
184
@test GeometryBasics. meta (mpm) == (a = 1 , b = 2 )
238
185
end
239
186
240
- @testset " LineString with metadata " begin
241
- linestring = GeometryBasics . Feature (LineString (Point{2 , Int}[(10 , 10 ), (20 , 20 ), (10 , 40 )]), a = 1 , b = 2 )
242
- @test linestring isa GeometryBasics . Feature
187
+ @testset " Feature{ LineString} " begin
188
+ linestring = Feature (LineString (Point{2 , Int}[(10 , 10 ), (20 , 20 ), (10 , 40 )]), a = 1 , b = 2 )
189
+ @test linestring isa Feature
243
190
@test linestring. rest === (a = 1 , b = 2 )
244
191
@test propertynames (linestring) == (:data , :a , :b )
245
192
@test GeometryBasics. metafree (linestring) == LineString (Point{2 , Int}[(10 , 10 ), (20 , 20 ), (10 , 40 )])
246
193
@test GeometryBasics. meta (linestring) == (a = 1 , b = 2 )
247
194
end
248
195
249
- @testset " MultiLineString with metadata " begin
196
+ @testset " Feature{ MultiLineString} " begin
250
197
linestring1 = LineString (Point{2 , Int}[(10 , 10 ), (20 , 20 ), (10 , 40 )])
251
198
linestring2 = LineString (Point{2 , Int}[(40 , 40 ), (30 , 30 ), (40 , 20 ), (30 , 10 )])
252
199
multilinestring = MultiLineString ([linestring1, linestring2])
253
- multilinestringmeta = GeometryBasics . Feature (MultiLineString ([linestring1, linestring2]); boundingbox = Rect (1.0 , 1.0 , 2.0 , 2.0 ))
254
- @test multilinestringmeta isa GeometryBasics . Feature
200
+ multilinestringmeta = Feature (MultiLineString ([linestring1, linestring2]); boundingbox = Rect (1.0 , 1.0 , 2.0 , 2.0 ))
201
+ @test multilinestringmeta isa Feature
255
202
@test multilinestringmeta. rest === (boundingbox = Rect (1.0 , 1.0 , 2.0 , 2.0 ),)
256
203
@test multilinestringmeta. data == multilinestring
257
204
@test propertynames (multilinestringmeta) == (:data , :boundingbox )
258
205
@test GeometryBasics. metafree (multilinestringmeta) == multilinestring
259
206
@test GeometryBasics. meta (multilinestringmeta) == (boundingbox = GeometryBasics. HyperRectangle {2,Float64} ([1.0 , 1.0 ], [2.0 , 2.0 ]),)
260
207
end
261
208
262
- # @testset "Mesh with metadata" begin
263
- # m = triangle_mesh(Sphere(Point3f0(0), 1))
264
- # m_meta = MeshMeta(m; boundingbox=Rect(1.0, 1.0, 2.0, 2.0))
265
- # @test meta(m_meta) === (boundingbox = Rect(1.0, 1.0, 2.0, 2.0),)
266
- # @test metafree(m_meta) === m
267
- # @test propertynames(m_meta) == (:mesh, :boundingbox)
268
- # end
209
+ #=
210
+ So mesh works differently for Feature
211
+ since `Feature{Point}` not subtyped to `AbstractPoint`
212
+ =#
213
+
214
+ @testset " Feature{Mesh}" begin
215
+ @testset " per vertex attributes" begin
216
+ points = rand (Point{3 , Float64}, 8 )
217
+ tfaces = TetrahedronFace{Int}[(1 , 2 , 3 , 4 ), (5 , 6 , 7 , 8 )]
218
+ normals = rand (SVector{3 , Float64}, 8 )
219
+ stress = LinRange (0 , 1 , 8 )
220
+ mesh_nometa = Mesh (points, tfaces)
221
+ mesh = Feature (mesh_nometa, normals = normals, stress = stress)
222
+
223
+ @test hasproperty (mesh, :stress )
224
+ @test hasproperty (mesh, :normals )
225
+ @test mesh. stress == stress
226
+ @test mesh. normals == normals
227
+ @test GeometryBasics. faces (mesh. data) == tfaces
228
+ @test propertynames (mesh) == (:data , :normals , :stress )
229
+ end
230
+ end
269
231
end
270
232
271
233
@testset " view" begin
@@ -649,11 +611,11 @@ end
649
611
geom = [ls... , mls, poly]
650
612
prop = [(country_states = " India$(i) " , rainfall = i* 10 ) for i in 1 : 12 ]
651
613
652
- feat = [GeometryBasics . Feature (i, j) for (i,j) = zip (geom, prop)]
653
- sa = GeometryBasics . structarray (feat)
614
+ feat = [Feature (i, j) for (i,j) = zip (geom, prop)]
615
+ sa = collect_feature (feat)
654
616
655
617
@test nameof (eltype (feat)) == :Feature
656
- @test eltype (sa) === GeometryBasics . Feature{Any,(:country_states , :rainfall ),Tuple{String,Int64}}
618
+ @test eltype (sa) === Feature{Any,(:country_states , :rainfall ),Tuple{String,Int64}}
657
619
@test propertynames (sa) === (:data , :country_states , :rainfall )
658
620
@test getproperty (sa, :country_states ) isa Array{String}
659
621
@test getproperty (sa, :data ) == geom
0 commit comments