Skip to content

Commit 1212783

Browse files
committed
Minor refactoring
1 parent 3003c07 commit 1212783

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/GeometryBasics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module GeometryBasics
3636
export AbstractMesh, Mesh, TriangleMesh
3737
export GLNormalMesh2D, PlainTriangleMesh
3838
export Feature, collect_feature
39+
3940
# all the different predefined mesh types
4041
# Note: meshes can contain arbitrary meta information,
4142
export AbstractMesh, TriangleMesh, PlainMesh, GLPlainMesh, GLPlainMesh2D, GLPlainMesh3D

src/metadata.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,15 @@ Base.getindex(x::MeshMeta, idx::Int) = getindex(metafree(x), idx)
192192
Base.size(x::MeshMeta) = size(metafree(x))
193193

194194

195-
#=
195+
"""
196196
`Feature` type acts same as Meta method
197197
The difference lies in the fact that it is designed to handle
198198
heterogeneous types.
199-
=#
200-
struct Feature{T, Names, Types} #<:AbstractVector{T}
199+
200+
eg: A Point MetaGeometry is a `PointMeta`
201+
But a feature is represented as `Feature{Point}`
202+
"""
203+
struct Feature{T, Names, Types}
201204
data::T
202205
rest::NamedTuple{Names, Types}
203206
end
@@ -253,3 +256,4 @@ end
253256

254257
Base.getindex(f::Feature, idx::Int) = getindex(metafree(f), idx)
255258
Base.size(f::Feature) = size(metafree(f))
259+

test/runtests.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,20 +604,21 @@ end
604604
@test <(x, x1)
605605
end
606606

607-
@testset "New Meta Methods" begin
607+
@testset "Feature 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]
612-
prop = [(country_states = "India$(i)", rainfall = i*10) for i in 1:12]
613-
614-
feat = [Feature(i, j) for (i,j) = zip(geom, prop)]
612+
prop = Any[(country_states = "India$(i)", rainfall = (i*9)/2) for i in 1:11]
613+
push!(prop, (country_states = 12, rainfall = 1000)) # a pinch of heterogeneity
614+
615+
feat = [Feature(i, j) for (i,j) = zip(geom, prop)]
615616
sa = collect_feature(feat)
616617

617618
@test nameof(eltype(feat)) == :Feature
618-
@test eltype(sa) === Feature{Any,(:country_states, :rainfall),Tuple{String,Int64}}
619+
@test eltype(sa) === Feature{Any,(:country_states, :rainfall),Tuple{Any,Float64}}
619620
@test propertynames(sa) === (:data, :country_states, :rainfall)
620-
@test getproperty(sa, :country_states) isa Array{String}
621+
@test getproperty(sa, :country_states) isa Array{Any}
621622
@test getproperty(sa, :data) == geom
622623
end
623624

0 commit comments

Comments
 (0)