Skip to content

Commit d202841

Browse files
committed
cleaner implementation
1 parent 4b231fc commit d202841

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/geometry_primitives.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ function widths(x::AbstractRange)
66
return maxi - mini
77
end
88

9-
# GeometryPrimitive's don't have attributes per se
10-
function attributes(nometa::GeometryPrimitive)
11-
return Dict{Symbol, Any}()
12-
end
13-
14-
function attributes(nometa::Tesselation)
15-
return attributes(nometa.primitive)
16-
end
179

1810
##
1911
# conversion & decompose

src/meshes.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,7 @@ Attaches metadata to the faces of a mesh
275275
function facemeta(mesh::Mesh; meta_data...)
276276
return Mesh(coordinates(mesh), meta(faces(mesh); meta_data...))
277277
end
278+
279+
function attributes(hasmeta::Mesh)
280+
return Dict((name => getproperty(hasmeta, name) for name in propertynames(hasmeta)))
281+
end

src/metadata.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ Table interface for this functionality. Once this is in e.g. Tables.jl,
44
it should be removed from GeometryBasics!
55
=#
66

7+
"""
8+
attributes(hasmeta)
9+
Returns all attributes of meta as a Dict{Symbol, Any}.
10+
Needs to be overloaded, and returns empty dict for non overloaded types!
11+
Gets overloaded by default for all Meta types.
12+
"""
713
function attributes(hasmeta)
8-
return Dict((name => getproperty(hasmeta, name) for name in propertynames(hasmeta)))
14+
return Dict{Symbol, Any}()
915
end
1016

1117
"""
@@ -88,6 +94,10 @@ macro meta_type(name, mainfield, supertype, params...)
8894
return $MetaName(main; meta...)
8995
end
9096

97+
function GeometryBasics.attributes(hasmeta::$MetaName)
98+
return Dict((name => getproperty(hasmeta, name) for name in propertynames(hasmeta)))
99+
end
100+
91101
function GeometryBasics.meta(elements::AbstractVector{T}; meta...) where T <: $supertype
92102
isempty(meta) && return elements # no meta to add!
93103
n = length(elements)
@@ -127,6 +137,8 @@ macro meta_type(name, mainfield, supertype, params...)
127137
) where {$(params...), Typ, Names, Types}
128138
$MetaName(metafree, NamedTuple{Names, Types}(args))
129139
end
140+
141+
130142
end
131143
return esc(expr)
132144
end

0 commit comments

Comments
 (0)