Skip to content

Commit

Permalink
Add 'InDomain' transform
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv committed Dec 16, 2024
1 parent 86359bb commit b7d9d5e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/transforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ include("transforms/affine.jl")
include("transforms/stretch.jl")
include("transforms/stdcoords.jl")
include("transforms/proj.jl")
include("transforms/indomain.jl")
include("transforms/morphological.jl")
include("transforms/lengthunit.jl")
include("transforms/shadow.jl")
Expand Down
41 changes: 41 additions & 0 deletions src/transforms/indomain.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

struct InDomain{CRS} <: CoordinateTransform end

InDomain(CRS) = InDomain{CRS}()

Check warning on line 7 in src/transforms/indomain.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/indomain.jl#L7

Added line #L7 was not covered by tests

InDomain(code::Type{<:EPSG}) = InDomain(CoordRefSystems.get(code))

Check warning on line 9 in src/transforms/indomain.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/indomain.jl#L9

Added line #L9 was not covered by tests

InDomain(code::Type{<:ESRI}) = InDomain(CoordRefSystems.get(code))

Check warning on line 11 in src/transforms/indomain.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/indomain.jl#L11

Added line #L11 was not covered by tests

parameters(::InDomain{CRS}) where {CRS} = (; CRS)

Check warning on line 13 in src/transforms/indomain.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/indomain.jl#L13

Added line #L13 was not covered by tests

function preprocess(::InDomain{CRS}, d::Domain) where {CRS}
findall(d) do g
all(pointify(g)) do p
indomain(CRS, coords(p))

Check warning on line 18 in src/transforms/indomain.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/indomain.jl#L15-L18

Added lines #L15 - L18 were not covered by tests
end
end
end

function preprocess(::InDomain{CRS}, d::Mesh) where {CRS}
findall(d) do g
all(eachvertex(g)) do p
indomain(CRS, coords(p))

Check warning on line 26 in src/transforms/indomain.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/indomain.jl#L23-L26

Added lines #L23 - L26 were not covered by tests
end
end
end

function preprocess(::InDomain{CRS}, d::GeometrySet{<:Any,<:Any,<:Union{Polytope,MultiPolytope}}) where {CRS}
findall(d) do g
all(eachvertex(g)) do p
indomain(CRS, coords(p))

Check warning on line 34 in src/transforms/indomain.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/indomain.jl#L31-L34

Added lines #L31 - L34 were not covered by tests
end
end
end

preprocess(::InDomain{CRS}, d::PointSet) where {CRS} = findall(p -> indomain(CRS, coords(p)), d)

Check warning on line 39 in src/transforms/indomain.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/indomain.jl#L39

Added line #L39 was not covered by tests

apply(t::InDomain, d::Domain) = view(d, preprocess(t, d)), nothing

Check warning on line 41 in src/transforms/indomain.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/indomain.jl#L41

Added line #L41 was not covered by tests

0 comments on commit b7d9d5e

Please sign in to comment.