@@ -7,131 +7,132 @@ using GeometryBasics: attributes
7
7
8
8
#= This left till meta is removed completely
9
9
# @testset "embedding metadata" begin
10
- # @testset "Meshes" begin
11
-
12
- # @testset "per vertex attributes" begin
13
- # points = rand(Point{3, Float64}, 8)
14
- # tfaces = TetrahedronFace{Int}[(1, 2, 3, 4), (5, 6, 7, 8)]
15
- # normals = rand(SVector{3, Float64}, 8)
16
- # stress = LinRange(0, 1, 8)
17
- # mesh = Mesh(meta(points, normals = normals, stress = stress), tfaces)
18
-
19
- # @test hasproperty(coordinates(mesh), :stress)
20
- # @test hasproperty(coordinates(mesh), :normals)
21
- # @test coordinates(mesh).stress === stress
22
- # @test coordinates(mesh).normals === normals
23
- # @test coordinates(mesh).normals === normals
24
- # @test GeometryBasics.faces(mesh) === tfaces
25
- # @test propertynames(coordinates(mesh)) == (:position, :normals, :stress)
26
-
27
- # end
28
-
29
- # @testset "per face attributes" begin
30
-
31
- # # Construct a cube out of Quads
32
- # points = Point{3, Float64}[
33
- # (0.0, 0.0, 0.0), (2.0, 0.0, 0.0),
34
- # (2.0, 2.0, 0.0), (0.0, 2.0, 0.0),
35
- # (0.0, 0.0, 12.0), (2.0, 0.0, 12.0),
36
- # (2.0, 2.0, 12.0), (0.0, 2.0, 12.0)
37
- # ]
38
-
39
- # facets = QuadFace{Cint}[
40
- # 1:4,
41
- # 5:8,
42
- # [1,5,6,2],
43
- # [2,6,7,3],
44
- # [3, 7, 8, 4],
45
- # [4, 8, 5, 1]
46
- # ]
47
-
48
- # markers = Cint[-1, -2, 0, 0, 0, 0]
49
- # # attach some additional information to our faces!
50
- # mesh = Mesh(points, meta(facets, markers = markers))
51
- # @test hasproperty(GeometryBasics.faces(mesh), :markers)
52
- # # test with === to assert we're not doing any copies
53
- # @test GeometryBasics.faces(mesh).markers === markers
54
- # @test coordinates(mesh) === points
55
- # @test metafree(GeometryBasics.faces(mesh)) === facets
56
-
57
- # end
58
-
59
- # end
10
+ @testset "Meshes" begin
11
+
12
+ @testset "per vertex attributes" begin
13
+ points = rand(Point{3, Float64}, 8)
14
+ tfaces = TetrahedronFace{Int}[(1, 2, 3, 4), (5, 6, 7, 8)]
15
+ normals = rand(SVector{3, Float64}, 8)
16
+ stress = LinRange(0, 1, 8)
17
+ mesh = Mesh(meta(points, normals = normals, stress = stress), tfaces)
18
+
19
+ @test hasproperty(coordinates(mesh), :stress)
20
+ @test hasproperty(coordinates(mesh), :normals)
21
+ @test coordinates(mesh).stress === stress
22
+ @test coordinates(mesh).normals === normals
23
+ @test coordinates(mesh).normals === normals
24
+ @test GeometryBasics.faces(mesh) === tfaces
25
+ @test propertynames(coordinates(mesh)) == (:position, :normals, :stress)
26
+
27
+ end
28
+
29
+ @testset "per face attributes" begin
30
+
31
+ # Construct a cube out of Quads
32
+ points = Point{3, Float64}[
33
+ (0.0, 0.0, 0.0), (2.0, 0.0, 0.0),
34
+ (2.0, 2.0, 0.0), (0.0, 2.0, 0.0),
35
+ (0.0, 0.0, 12.0), (2.0, 0.0, 12.0),
36
+ (2.0, 2.0, 12.0), (0.0, 2.0, 12.0)
37
+ ]
38
+
39
+ facets = QuadFace{Cint}[
40
+ 1:4,
41
+ 5:8,
42
+ [1,5,6,2],
43
+ [2,6,7,3],
44
+ [3, 7, 8, 4],
45
+ [4, 8, 5, 1]
46
+ ]
47
+
48
+ markers = Cint[-1, -2, 0, 0, 0, 0]
49
+ # attach some additional information to our faces!
50
+ mesh = Mesh(points, meta(facets, markers = markers))
51
+ @test hasproperty(GeometryBasics.faces(mesh), :markers)
52
+ # test with === to assert we're not doing any copies
53
+ @test GeometryBasics.faces(mesh).markers === markers
54
+ @test coordinates(mesh) === points
55
+ @test metafree(GeometryBasics.faces(mesh)) === facets
56
+
57
+ end
58
+
59
+ end
60
60
61
- # @testset "polygon with metadata" begin
62
- # polys = [Polygon(rand(Point{2, Float32}, 20)) for i in 1:10]
63
- # pnames = [randstring(4) for i in 1:10]
64
- # numbers = LinRange(0.0, 1.0, 10)
65
- # bin = rand(Bool, 10)
66
- # # create a polygon
67
- # poly = PolygonMeta(polys[1], name = pnames[1], value = numbers[1], category = bin[1])
68
- # # create a MultiPolygon with the right type & meta information!
69
- # multipoly = MultiPolygonMeta(polys, name = pnames, value = numbers, category = bin)
70
- # @test multipoly isa AbstractVector
71
- # @test poly isa GeometryBasics.AbstractPolygon
61
+ @testset "polygon with metadata" begin
62
+ polys = [Polygon(rand(Point{2, Float32}, 20)) for i in 1:10]
63
+ pnames = [randstring(4) for i in 1:10]
64
+ numbers = LinRange(0.0, 1.0, 10)
65
+ bin = rand(Bool, 10)
66
+ # create a polygon
67
+ poly = PolygonMeta(polys[1], name = pnames[1], value = numbers[1], category = bin[1])
68
+ # create a MultiPolygon with the right type & meta information!
69
+ multipoly = MultiPolygonMeta(polys, name = pnames, value = numbers, category = bin)
70
+ @test multipoly isa AbstractVector
71
+ @test poly isa GeometryBasics.AbstractPolygon
72
72
73
- # @test GeometryBasics.getcolumn(poly, :name) == pnames[1]
74
- # @test GeometryBasics.MetaFree(PolygonMeta) == Polygon
75
-
76
- # @test GeometryBasics.getcolumn(multipoly, :name) == pnames
77
- # @test GeometryBasics.MetaFree(MultiPolygonMeta) == MultiPolygon
78
-
79
- # meta_p = meta(polys[1], boundingbox=Rect(0, 0, 2, 2))
80
- # @test meta_p.boundingbox === Rect(0, 0, 2, 2)
81
- # @test metafree(meta_p) === polys[1]
82
- # attributes(meta_p) == Dict{Symbol, Any}(:boundingbox => meta_p.boundingbox,
83
- # :polygon => polys[1])
84
- # end
85
- # @testset "point with metadata" begin
86
- # p = Point(1.1, 2.2)
87
- # @test p isa AbstractVector{Float64}
88
- # pm = GeometryBasics.PointMeta(1.1, 2.2; a=1, b=2)
89
- # p1 = Point(2.2, 3.6)
90
- # p2 = [p, p1]
91
- # @test coordinates(p2) == p2
92
- # @test meta(pm) === (a=1, b=2)
93
- # @test metafree(pm) === p
94
- # @test propertynames(pm) == (:position, :a, :b)
95
- # end
73
+ @test GeometryBasics.getcolumn(poly, :name) == pnames[1]
74
+ @test GeometryBasics.MetaFree(PolygonMeta) == Polygon
75
+
76
+ @test GeometryBasics.getcolumn(multipoly, :name) == pnames
77
+ @test GeometryBasics.MetaFree(MultiPolygonMeta) == MultiPolygon
78
+
79
+ meta_p = meta(polys[1], boundingbox=Rect(0, 0, 2, 2))
80
+ @test meta_p.boundingbox === Rect(0, 0, 2, 2)
81
+ @test metafree(meta_p) === polys[1]
82
+ attributes(meta_p) == Dict{Symbol, Any}(:boundingbox => meta_p.boundingbox,
83
+ :polygon => polys[1])
84
+ end
85
+ @testset "point with metadata" begin
86
+ p = Point(1.1, 2.2)
87
+ @test p isa AbstractVector{Float64}
88
+ pm = GeometryBasics.PointMeta(1.1, 2.2; a=1, b=2)
89
+ p1 = Point(2.2, 3.6)
90
+ p2 = [p, p1]
91
+ @test coordinates(p2) == p2
92
+ @test meta(pm) === (a=1, b=2)
93
+ @test metafree(pm) === p
94
+ @test propertynames(pm) == (:position, :a, :b)
95
+ end
96
96
97
- # @testset "MultiPoint with metadata" begin
98
- # p = collect(Point{2, Float64}(x, x+1) for x in 1:5)
99
- # @test p isa AbstractVector
100
- # mpm = MultiPointMeta(p, a=1, b=2)
101
- # @test coordinates(mpm) == mpm
102
- # @test meta(mpm) === (a=1, b=2)
103
- # @test metafree(mpm) == p
104
- # @test propertynames(mpm) == (:points, :a, :b)
105
- # end
106
-
107
- # @testset "LineString with metadata" begin
108
- # linestring = LineStringMeta(Point{2, Int}[(10, 10), (20, 20), (10, 40)], a = 1, b = 2)
109
- # @test linestring isa AbstractVector
110
- # @test meta(linestring) === (a = 1, b = 2)
111
- # @test metafree(linestring) == linestring
112
- # @test propertynames(linestring) == (:lines, :a, :b)
113
- # end
114
-
115
- # @testset "MultiLineString with metadata" begin
116
- # linestring1 = LineString(Point{2, Int}[(10, 10), (20, 20), (10, 40)])
117
- # linestring2 = LineString(Point{2, Int}[(40, 40), (30, 30), (40, 20), (30, 10)])
118
- # multilinestring = MultiLineString([linestring1, linestring2])
119
- # multilinestringmeta = MultiLineStringMeta([linestring1, linestring2]; boundingbox = Rect(1.0, 1.0, 2.0, 2.0))
120
- # @test multilinestringmeta isa AbstractVector
121
- # @test meta(multilinestringmeta) === (boundingbox = Rect(1.0, 1.0, 2.0, 2.0),)
122
- # @test metafree(multilinestringmeta) == multilinestring
123
- # @test propertynames(multilinestringmeta) == (:linestrings, :boundingbox)
124
- # end
97
+ @testset "MultiPoint with metadata" begin
98
+ p = collect(Point{2, Float64}(x, x+1) for x in 1:5)
99
+ @test p isa AbstractVector
100
+ mpm = MultiPointMeta(p, a=1, b=2)
101
+ @test coordinates(mpm) == mpm
102
+ @test meta(mpm) === (a=1, b=2)
103
+ @test metafree(mpm) == p
104
+ @test propertynames(mpm) == (:points, :a, :b)
105
+ end
125
106
126
- # @testset "Mesh with metadata" begin
127
- # m = triangle_mesh(Sphere(Point3f0(0), 1))
128
- # m_meta = MeshMeta(m; boundingbox=Rect(1.0, 1.0, 2.0, 2.0))
129
- # @test meta(m_meta) === (boundingbox = Rect(1.0, 1.0, 2.0, 2.0),)
130
- # @test metafree(m_meta) === m
131
- # @test propertynames(m_meta) == (:mesh, :boundingbox)
132
- # end
107
+ @testset "LineString with metadata" begin
108
+ linestring = LineStringMeta(Point{2, Int}[(10, 10), (20, 20), (10, 40)], a = 1, b = 2)
109
+ @test linestring isa AbstractVector
110
+ @test meta(linestring) === (a = 1, b = 2)
111
+ @test metafree(linestring) == linestring
112
+ @test propertynames(linestring) == (:lines, :a, :b)
113
+ end
114
+
115
+ @testset "MultiLineString with metadata" begin
116
+ linestring1 = LineString(Point{2, Int}[(10, 10), (20, 20), (10, 40)])
117
+ linestring2 = LineString(Point{2, Int}[(40, 40), (30, 30), (40, 20), (30, 10)])
118
+ multilinestring = MultiLineString([linestring1, linestring2])
119
+ multilinestringmeta = MultiLineStringMeta([linestring1, linestring2]; boundingbox = Rect(1.0, 1.0, 2.0, 2.0))
120
+ @test multilinestringmeta isa AbstractVector
121
+ @test meta(multilinestringmeta) === (boundingbox = Rect(1.0, 1.0, 2.0, 2.0),)
122
+ @test metafree(multilinestringmeta) == multilinestring
123
+ @test propertynames(multilinestringmeta) == (:linestrings, :boundingbox)
124
+ end
125
+
126
+ @testset "Mesh with metadata" begin
127
+ m = triangle_mesh(Sphere(Point3f0(0), 1))
128
+ m_meta = MeshMeta(m; boundingbox=Rect(1.0, 1.0, 2.0, 2.0))
129
+ @test meta(m_meta) === (boundingbox = Rect(1.0, 1.0, 2.0, 2.0),)
130
+ @test metafree(m_meta) === m
131
+ @test propertynames(m_meta) == (:mesh, :boundingbox)
132
+ end
133
133
# end
134
134
=#
135
+
135
136
@testset " embedding metadata(new)" begin
136
137
# @testset "Meshes" begin
137
138
0 commit comments