Skip to content

Commit e6cd046

Browse files
committed
Rename Feature to MetaT
1 parent 630b9c1 commit e6cd046

File tree

3 files changed

+59
-59
lines changed

3 files changed

+59
-59
lines changed

src/GeometryBasics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module GeometryBasics
3535
export GLTriangleFace, GLNormalMesh3D, GLPlainTriangleMesh, GLUVMesh3D, GLUVNormalMesh3D
3636
export AbstractMesh, Mesh, TriangleMesh
3737
export GLNormalMesh2D, PlainTriangleMesh
38-
export Feature, collect_feature
38+
export MetaT, collect_MetaT
3939

4040
# all the different predefined mesh types
4141
# Note: meshes can contain arbitrary meta information,

src/metadata.jl

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -196,57 +196,57 @@ Base.size(x::MeshMeta) = size(metafree(x))
196196

197197
"""
198198
199-
Feature(::type{T}, Names, Types)
199+
MetaT(::type{T}, Names, Types)
200200
201-
Returns a `Feature` that holds a geometry and it's metadata
201+
Returns a `MetaT` that holds a geometry and it's metadata
202202
203-
`Feature` acts the same as `Meta` method.
203+
`MetaT` acts the same as `Meta` method.
204204
The difference lies in the fact that it is designed to handle
205205
geometries and metadata of different/heterogeneous types.
206206
207-
eg: While a Point MetaGeometry is a `PointMeta`, the Feature representation is `Feature{Point}`
207+
eg: While a Point MetaGeometry is a `PointMeta`, the MetaT representation is `MetaT{Point}`
208208
The downside being it's not subtyped to `AbstractPoint` like a `PointMeta` is.
209209
210210
Example:
211211
```julia
212-
julia> Feature(Point(1, 2), city = "Mumbai")
213-
Feature{Point{2,Int64},(:city,),Tuple{String}}([1, 2], (city = "Mumbai",))
212+
julia> MetaT(Point(1, 2), city = "Mumbai")
213+
MetaT{Point{2,Int64},(:city,),Tuple{String}}([1, 2], (city = "Mumbai",))
214214
```
215215
"""
216-
struct Feature{T, Names, Types}
216+
struct MetaT{T, Names, Types}
217217
main::T
218218
meta::NamedTuple{Names, Types}
219219
end
220220

221-
Feature(x; kwargs...) = Feature(x, values(kwargs))
221+
MetaT(x; kwargs...) = MetaT(x, values(kwargs))
222222

223223
"""
224224
225-
metafree(x::Feature)
226-
metafree(x::Array{Feature})
225+
metafree(x::MetaT)
226+
metafree(x::Array{MetaT})
227227
228-
Free the Feature from metadata
228+
Free the MetaT from metadata
229229
i.e. returns the geometry/array of geometries
230230
"""
231-
function metafree(x::Feature)
231+
function metafree(x::MetaT)
232232
getfield(x, 1)
233233
end
234-
metafree(x::AbstractVector{<: Feature}) = map(metafree, x)
234+
metafree(x::AbstractVector{<: MetaT}) = map(metafree, x)
235235

236236
"""
237237
238-
meta(x::Feature)
239-
meta(x::Array{Feature})
238+
meta(x::MetaT)
239+
meta(x::Array{MetaT})
240240
241-
Returns the metadata of a `Feature`
241+
Returns the metadata of a `MetaT`
242242
"""
243-
function meta(x::Feature)
243+
function meta(x::MetaT)
244244
getfield(x, 2)
245245
end
246-
meta(x::AbstractVector{<: Feature}) = map(meta, x)
246+
meta(x::AbstractVector{<: MetaT}) = map(meta, x)
247247

248248
# helper methods
249-
function Base.getproperty(x::Feature, field::Symbol)
249+
function Base.getproperty(x::MetaT, field::Symbol)
250250
if field == :main
251251
metafree(x)
252252
elseif field == :meta
@@ -256,34 +256,34 @@ function Base.getproperty(x::Feature, field::Symbol)
256256
end
257257
end
258258

259-
Base.propertynames(x::Feature) = (:main, propertynames(meta(x))...)
260-
getnamestypes(::Type{Feature{T, Names, Types}}) where {T, Names, Types} = (T, Names, Types)
259+
Base.propertynames(x::MetaT) = (:main, propertynames(meta(x))...)
260+
getnamestypes(::Type{MetaT{T, Names, Types}}) where {T, Names, Types} = (T, Names, Types)
261261

262262
# explicitly give the "schema" of the object to StructArrays
263-
function StructArrays.staticschema(::Type{F}) where {F<:Feature}
263+
function StructArrays.staticschema(::Type{F}) where {F<:MetaT}
264264
T, names, types = getnamestypes(F)
265265
NamedTuple{(:main, names...), Base.tuple_type_cons(T, types)}
266266
end
267267

268-
# generate an instance of Feature type
269-
function StructArrays.createinstance(::Type{F}, x, args...) where {F<:Feature}
268+
# generate an instance of MetaT type
269+
function StructArrays.createinstance(::Type{F}, x, args...) where {F<:MetaT}
270270
T , names, types = getnamestypes(F)
271-
Feature(x, NamedTuple{names, types}(args))
271+
MetaT(x, NamedTuple{names, types}(args))
272272
end
273273

274274
"""
275-
Accepts an iterable of Features and put it into a StructArray
275+
Accepts an iterable of MetaTs and put it into a StructArray
276276
"""
277-
function collect_feature(iter)
277+
function collect_MetaT(iter)
278278
cols = Tables.columntable(iter)
279-
collect_feature(first(cols), Base.tail(cols))
279+
collect_MetaT(first(cols), Base.tail(cols))
280280
end
281281

282-
function collect_feature(main, meta::NamedTuple{names, types}) where {names, types}
283-
F = Feature{eltype(main), names, StructArrays.eltypes(types)}
282+
function collect_MetaT(main, meta::NamedTuple{names, types}) where {names, types}
283+
F = MetaT{eltype(main), names, StructArrays.eltypes(types)}
284284
return StructArray{F}(; main=main, meta...)
285285
end
286286

287-
Base.getindex(x::Feature, idx::Int) = getindex(metafree(x), idx)
288-
Base.size(x::Feature) = size(metafree(x))
287+
Base.getindex(x::MetaT, idx::Int) = getindex(metafree(x), idx)
288+
Base.size(x::MetaT) = size(metafree(x))
289289

test/runtests.jl

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,24 @@ using GeometryBasics: attributes
131131
end
132132
end
133133

134-
@testset "embedding Feature" begin
135-
@testset "Feature{Polygon}" begin
134+
@testset "embedding MetaT" begin
135+
@testset "MetaT{Polygon}" begin
136136
polys = [Polygon(rand(Point{2, Float32}, 20)) for i in 1:10]
137137
multipol = MultiPolygon(polys)
138138
pnames = [randstring(4) for i in 1:10]
139139
numbers = LinRange(0.0, 1.0, 10)
140140
bin = rand(Bool, 10)
141141
# create a polygon
142-
poly = Feature(polys[1], name = pnames[1], value = numbers[1], category = bin[1])
142+
poly = MetaT(polys[1], name = pnames[1], value = numbers[1], category = bin[1])
143143
# create a MultiPolygon with the right type & meta information!
144-
multipoly = Feature(multipol, name = pnames, value = numbers, category = bin)
145-
@test multipoly isa Feature
146-
@test poly isa Feature
144+
multipoly = MetaT(multipol, name = pnames, value = numbers, category = bin)
145+
@test multipoly isa MetaT
146+
@test poly isa MetaT
147147

148148
@test GeometryBasics.getcolumn(poly, :name) == pnames[1]
149149
@test GeometryBasics.getcolumn(multipoly, :name) == pnames
150150

151-
meta_p = Feature(polys[1], boundingbox=Rect(0, 0, 2, 2))
151+
meta_p = MetaT(polys[1], boundingbox=Rect(0, 0, 2, 2))
152152
@test meta_p.boundingbox === Rect(0, 0, 2, 2)
153153
@test GeometryBasics.metafree(meta_p) == polys[1]
154154
@test GeometryBasics.metafree(poly) == polys[1]
@@ -158,10 +158,10 @@ end
158158
@test GeometryBasics.meta(multipoly) == (name = pnames, value = numbers, category = bin)
159159
end
160160

161-
@testset "Feature{Point}" begin
161+
@testset "MetaT{Point}" begin
162162
p = Point(1.1, 2.2)
163163
@test p isa AbstractVector{Float64}
164-
pm = Feature(Point(1.1, 2.2); a=1, b=2)
164+
pm = MetaT(Point(1.1, 2.2); a=1, b=2)
165165
p1 = Point(2.2, 3.6)
166166
p2 = [p, p1]
167167
@test coordinates(p2) == p2
@@ -172,10 +172,10 @@ end
172172
@test GeometryBasics.meta(pm) == (a = 1, b = 2)
173173
end
174174

175-
@testset "Feature{MultiPoint}" begin
175+
@testset "MetaT{MultiPoint}" begin
176176
p = collect(Point{2, Float64}(x, x+1) for x in 1:5)
177177
@test p isa AbstractVector
178-
mpm = Feature(MultiPoint(p); a=1, b=2)
178+
mpm = MetaT(MultiPoint(p); a=1, b=2)
179179
@test coordinates(mpm.main) == Point{2, Float64}[(x, x+1) for x in 1:5]
180180
@test mpm.meta === (a=1, b=2)
181181
@test mpm.main == p
@@ -184,21 +184,21 @@ end
184184
@test GeometryBasics.meta(mpm) == (a = 1, b = 2)
185185
end
186186

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
187+
@testset "MetaT{LineString}" begin
188+
linestring = MetaT(LineString(Point{2, Int}[(10, 10), (20, 20), (10, 40)]), a = 1, b = 2)
189+
@test linestring isa MetaT
190190
@test linestring.meta === (a = 1, b = 2)
191191
@test propertynames(linestring) == (:main, :a, :b)
192192
@test GeometryBasics.metafree(linestring) == LineString(Point{2, Int}[(10, 10), (20, 20), (10, 40)])
193193
@test GeometryBasics.meta(linestring) == (a = 1, b = 2)
194194
end
195195

196-
@testset "Feature{MultiLineString}" begin
196+
@testset "MetaT{MultiLineString}" begin
197197
linestring1 = LineString(Point{2, Int}[(10, 10), (20, 20), (10, 40)])
198198
linestring2 = LineString(Point{2, Int}[(40, 40), (30, 30), (40, 20), (30, 10)])
199199
multilinestring = MultiLineString([linestring1, linestring2])
200-
multilinestringmeta = Feature(MultiLineString([linestring1, linestring2]); boundingbox = Rect(1.0, 1.0, 2.0, 2.0))
201-
@test multilinestringmeta isa Feature
200+
multilinestringmeta = MetaT(MultiLineString([linestring1, linestring2]); boundingbox = Rect(1.0, 1.0, 2.0, 2.0))
201+
@test multilinestringmeta isa MetaT
202202
@test multilinestringmeta.meta === (boundingbox = Rect(1.0, 1.0, 2.0, 2.0),)
203203
@test multilinestringmeta.main == multilinestring
204204
@test propertynames(multilinestringmeta) == (:main, :boundingbox)
@@ -207,18 +207,18 @@ end
207207
end
208208

209209
#=
210-
So mesh works differently for Feature
211-
since `Feature{Point}` not subtyped to `AbstractPoint`
210+
So mesh works differently for MetaT
211+
since `MetaT{Point}` not subtyped to `AbstractPoint`
212212
=#
213213

214-
@testset "Feature{Mesh}" begin
214+
@testset "MetaT{Mesh}" begin
215215
@testset "per vertex attributes" begin
216216
points = rand(Point{3, Float64}, 8)
217217
tfaces = TetrahedronFace{Int}[(1, 2, 3, 4), (5, 6, 7, 8)]
218218
normals = rand(SVector{3, Float64}, 8)
219219
stress = LinRange(0, 1, 8)
220220
mesh_nometa = Mesh(points, tfaces)
221-
mesh = Feature(mesh_nometa, normals = normals, stress = stress)
221+
mesh = MetaT(mesh_nometa, normals = normals, stress = stress)
222222

223223
@test hasproperty(mesh, :stress)
224224
@test hasproperty(mesh, :normals)
@@ -604,19 +604,19 @@ end
604604
@test <(x, x1)
605605
end
606606

607-
@testset "Feature and heterogeneous data" begin
607+
@testset "MetaT and heterogeneous data" begin
608608
ls = [LineString([Point(i, (i+1)^2/6), Point(i*0.86,i+5), Point(i/3, i/7)]) for i in 1:10]
609609
mls = MultiLineString([LineString([Point(i+1, (i)^2/6), Point(i*0.75,i+8), Point(i/2.5, i/6.79)]) for i in 5:10])
610610
poly = Polygon(Point{2, Int}[(40, 40), (20, 45), (45, 30), (40, 40)])
611611
geom = [ls..., mls, poly]
612612
prop = Any[(country_states = "India$(i)", rainfall = (i*9)/2) for i in 1:11]
613613
push!(prop, (country_states = 12, rainfall = 1000)) # a pinch of heterogeneity
614614

615-
feat = [Feature(i, j) for (i,j) = zip(geom, prop)]
616-
sa = collect_feature(feat)
615+
feat = [MetaT(i, j) for (i,j) = zip(geom, prop)]
616+
sa = collect_MetaT(feat)
617617

618-
@test nameof(eltype(feat)) == :Feature
619-
@test eltype(sa) === Feature{Any,(:country_states, :rainfall),Tuple{Any,Float64}}
618+
@test nameof(eltype(feat)) == :MetaT
619+
@test eltype(sa) === MetaT{Any,(:country_states, :rainfall),Tuple{Any,Float64}}
620620
@test propertynames(sa) === (:main, :country_states, :rainfall)
621621
@test getproperty(sa, :country_states) isa Array{Any}
622622
@test getproperty(sa, :main) == geom

0 commit comments

Comments
 (0)