Skip to content

Commit 9828a5a

Browse files
committed
Docstring changes; refactor getproperty; use getfield in metafree
1 parent 7394b6a commit 9828a5a

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/metadata.jl

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,25 +221,42 @@ end
221221
Feature(x; kwargs...) = Feature(x, values(kwargs))
222222

223223
"""
224-
Frees the Feature out of metadata
225-
i.e. returns and array of geometries
224+
225+
metafree(x::Feature)
226+
metafree(x::Array{Feature})
227+
228+
Free the Feature from metadata
229+
i.e. returns the geometry/array of geometries
226230
"""
227-
function metafree(F::Feature)
228-
getproperty(F, :main)
231+
function metafree(x::Feature)
232+
getfield(x, 1)
229233
end
230-
metafree(x::AbstractVector{<: Feature}) = [getproperty(i, :main) for i in x]
234+
metafree(x::AbstractVector{<: Feature}) = map(metafree, x)
231235

232236
"""
233-
Returns the metadata of a Feature
237+
238+
meta(x::Feature)
239+
meta(x::Array{Feature})
240+
241+
Returns the metadata of a `Feature`
234242
"""
235243
function meta(x::Feature)
236-
getfield(x, :meta)
244+
getfield(x, 2)
237245
end
238-
meta(x::AbstractVector{<: Feature}) = [getproperty(i, :meta) for i in x]
246+
meta(x::AbstractVector{<: Feature}) = map(meta, x)
239247

240248
# helper methods
241-
Base.getproperty(f::Feature, s::Symbol) = s == :main ? getfield(f, 1) : s == :meta ? getfield(f, 2) : getproperty(getfield(f, 2), s)
242-
Base.propertynames(f::Feature) = (:main, propertynames(f.meta)...)
249+
function Base.getproperty(x::Feature, field::Symbol)
250+
if field == :main
251+
metafree(x)
252+
elseif field == :meta
253+
meta(x)
254+
else
255+
getproperty(meta(x), field)
256+
end
257+
end
258+
259+
Base.propertynames(x::Feature) = (:main, propertynames(meta(x))...)
243260
getnamestypes(::Type{Feature{T, Names, Types}}) where {T, Names, Types} = (T, Names, Types)
244261

245262
# explicitly give the "schema" of the object to StructArrays

0 commit comments

Comments
 (0)