Skip to content

Commit

Permalink
Viewing with Geometries (#60)
Browse files Browse the repository at this point in the history
* Viewing with Geometries

* Update tests

* Update tests
  • Loading branch information
eliascarv authored Sep 12, 2023
1 parent c1ba33a commit b274c3c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
17 changes: 1 addition & 16 deletions src/abstractgeotable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,7 @@ ncol(geotable::AbstractGeoTable) = length(Tables.columnnames(Tables.columns(valu

Base.view(geotable::AbstractGeoTable, inds) = GeoTableView(geotable, inds)

function Base.view(geotable::AbstractGeoTable, geometry::Geometry)
dom = domain(geotable)
tab = values(geotable)

# retrieve subdomain
inds = indices(dom, geometry)
subdom = view(dom, inds)

# retrieve subtable
subtab = Tables.subset(tab, inds)

# data table for elements
vals = Dict(paramdim(dom) => subtab)

constructor(geotable)(subdom, vals)
end
Base.view(geotable::AbstractGeoTable, geometry::Geometry) = GeoTableView(geotable, indices(domain(geotable), geometry))

# -----------------
# TABLES INTERFACE
Expand Down
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ dummymeta(domain, table) = GeoTable(domain, Dict(paramdim(domain) => table))
@test centroid(domain(v), 3) == Point(1.5, 1.5)
@test v.a == v."a" == [2, 3, 4]
@test v.b == v."b" == [6, 7, 8]

# viewing with geometries
a = rand(100)
b = rand(100)
grid = CartesianGrid(10, 10)
linds = LinearIndices(size(grid))
gtb = dummy(grid, (; a, b))
tri = Triangle((1.5, 1.5), (4.5, 4.5), (7.5, 1.5))
v = view(gtb, tri)
@test gtb.a[linds[4, 3]] v.a
@test gtb.a[linds[5, 3]] v.a
@test gtb.a[linds[6, 3]] v.a
@test gtb.b[linds[4, 3]] v.b
@test gtb.b[linds[5, 3]] v.b
@test gtb.b[linds[6, 3]] v.b
end
end

Expand Down

0 comments on commit b274c3c

Please sign in to comment.