Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ function indices(grid::OrthoRectilinearGrid, box::Box)
LinearIndices(size(grid))[range] |> vec
end

function indices(grid::TransformedGrid, geometry::Geometry)
# construct reverse transform from revertible steps
revtrans = reduce(→, reverse(filter(isrevertible, transform(grid))))

# find indices in non-transformed space
indices(parent(grid), revtrans(geometry))
end

# ----------------
# CARTESIAN RANGE
# ----------------
Expand Down
11 changes: 11 additions & 0 deletions test/indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,15 @@
@test linds[2, 2] == only(indices(grid, p4))
@test linds[10, 10] == only(indices(grid, p5))
@test isempty(indices(grid, p6))

# transformed grid
grid = cartgrid(20, 20)
poly = PolyArea(cart.([(3, 3), (9, 9), (3, 15), (17, 15), (17, 3)]))
inds = indices(grid, poly)
linds = LinearIndices(size(grid))
@test linds[12, 6] ∈ indices(grid, poly)
trans = Rotate(Angle2d(T(π / 2))) → Morphological(c -> Cartesian(c.x + c.y, c.y, c.x - c.y))
tgrid = trans(grid)
tpoly = trans(poly)
@test indices(tgrid, tpoly) == indices(grid, poly)
end
Loading