Skip to content

Commit d3f5146

Browse files
authored
Refactor viewing.jl (#1035)
1 parent 7761035 commit d3f5146

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/viewing.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ that intersect with the `geometry`.
2828
"""
2929
indices(domain::Domain, geometry::Geometry) = findall(intersects(geometry), domain)
3030

31-
function indices(grid::Grid, point::Point)
31+
# --------------
32+
# OPTIMIZATIONS
33+
# --------------
34+
35+
function indices(grid::CartesianGrid, point::Point)
3236
point grid && return Int[]
3337

3438
# grid properties
@@ -46,7 +50,7 @@ function indices(grid::Grid, point::Point)
4650
[LinearIndices(dims)[coords...]]
4751
end
4852

49-
function indices(grid::Grid, chain::Chain)
53+
function indices(grid::CartesianGrid, chain::Chain)
5054
dims = size(grid)
5155
mask = falses(dims)
5256

@@ -55,11 +59,10 @@ function indices(grid::Grid, chain::Chain)
5559
_bresenham!(mask, grid, true, p₁, p₂)
5660
end
5761

58-
# convert to linear indices
5962
LinearIndices(dims)[mask]
6063
end
6164

62-
function indices(grid::Grid, poly::Polygon)
65+
function indices(grid::CartesianGrid, poly::Polygon)
6366
dims = size(grid)
6467
mask = zeros(Int, dims)
6568
cpoly = poly boundingbox(grid)
@@ -69,7 +72,6 @@ function indices(grid::Grid, poly::Polygon)
6972
_fill!(mask, grid, i, triangle)
7073
end
7174

72-
# convert to linear indices
7375
LinearIndices(dims)[mask .> 0]
7476
end
7577

@@ -93,9 +95,12 @@ function indices(grid::CartesianGrid, box::Box)
9395
LinearIndices(sz)[range] |> vec
9496
end
9597

96-
indices(domain::Domain, multi::Multi) = mapreduce(geom -> indices(domain, geom), vcat, parent(multi)) |> unique
98+
indices(grid::CartesianGrid, multi::Multi) = mapreduce(geom -> indices(grid, geom), vcat, parent(multi)) |> unique
99+
100+
# -----------------
101+
# HELPER FUNCTIONS
102+
# -----------------
97103

98-
# utils
99104
function _fill!(mask, grid, val, triangle)
100105
v = vertices(triangle)
101106

0 commit comments

Comments
 (0)