Skip to content

Commit 6436ca7

Browse files
authored
add one arg methods for all geometric predicates (#304)
1 parent f2a52ef commit 6436ca7

File tree

11 files changed

+84
-2
lines changed

11 files changed

+84
-2
lines changed

src/methods/geom_relations/contains.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,12 @@ GO.contains(line, point)
6262
true
6363
```
6464
"""
65-
contains(g1, g2) = GeometryOps.within(g2, g1)
65+
contains(g1, g2) = GeometryOps.within(g2, g1)
66+
67+
"""
68+
contains(g1)
69+
70+
Return a function that checks if its input contains `g1`.
71+
This is equivalent to `x -> contains(x, g1)`.
72+
"""
73+
contains(g1) = Base.Fix2(contains, g1)

src/methods/geom_relations/coveredby.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ true
7979
"""
8080
coveredby(g1, g2) = _coveredby(trait(g1), g1, trait(g2), g2)
8181

82+
"""
83+
coveredby(g1)
84+
85+
Return a function that checks if its input is covered by `g1`.
86+
This is equivalent to `x -> coveredby(x, g1)`.
87+
"""
88+
coveredby(g1) = Base.Fix2(coveredby, g1)
89+
8290
# # Convert features to geometries
8391
_coveredby(::GI.FeatureTrait, g1, ::Any, g2) = coveredby(GI.geometry(g1), g2)
8492
_coveredby(::Any, g1, t2::GI.FeatureTrait, g2) = coveredby(g1, GI.geometry(g2))

src/methods/geom_relations/covers.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ true
6262
```
6363
"""
6464
covers(g1, g2)::Bool = GeometryOps.coveredby(g2, g1)
65+
66+
"""
67+
covers(g1)
68+
69+
Return a function that checks if its input covers `g1`.
70+
This is equivalent to `x -> covers(x, g1)`.
71+
"""
72+
covers(g1) = Base.Fix2(covers, g1)

src/methods/geom_relations/crosses.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ crosses(::LineStringTrait, g1, ::LineStringTrait, g2)::Bool = line_crosses_line(
2626
crosses(::PolygonTrait, g1, ::MultiPointTrait, g2)::Bool = multipoint_crosses_poly(g2, g1)
2727
crosses(::PolygonTrait, g1, ::LineStringTrait, g2)::Bool = line_crosses_poly(g2, g1)
2828

29+
"""
30+
crosses(g1)
2931
32+
Return a function that checks if its input crosses `g1`.
33+
This is equivalent to `x -> crosses(x, g1)`.
34+
"""
35+
crosses(g1) = Base.Fix2(crosses, g1)
3036

3137
function crosses(t1::GI.AbstractGeometryTrait, g1, t2, e::Extents.Extent)
3238
return crosses(t1, g1, GI.PolygonTrait(), extent_to_polygon(e))

src/methods/geom_relations/disjoint.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ true
7575
"""
7676
disjoint(g1, g2) = _disjoint(trait(g1), g1, trait(g2), g2)
7777

78+
"""
79+
disjoint(g1)
80+
81+
Return a function that checks if its input is disjoint from `g1`.
82+
This is equivalent to `x -> disjoint(x, g1)`.
83+
"""
84+
disjoint(g1) = Base.Fix2(disjoint, g1)
85+
7886
# # Convert features to geometries
7987
_disjoint(::FeatureTrait, g1, ::Any, g2) = disjoint(GI.geometry(g1), g2)
8088
_disjoint(::Any, g1, ::FeatureTrait, g2) = disjoint(g1, geometry(g2))

src/methods/geom_relations/intersects.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,11 @@ true
5656
```
5757
"""
5858
intersects(geom1, geom2) = !disjoint(geom1, geom2)
59+
60+
"""
61+
intersects(g1)
62+
63+
Return a function that checks if its input intersects `g1`.
64+
This is equivalent to `x -> intersects(x, g1)`.
65+
"""
66+
intersects(g1) = Base.Fix2(intersects, g1)

src/methods/geom_relations/overlaps.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ overlaps(geom1, geom2)::Bool = overlaps(
7676
geom2,
7777
)
7878

79+
"""
80+
overlaps(g1)
81+
82+
Return a function that checks if its input overlaps `g1`.
83+
This is equivalent to `x -> overlaps(x, g1)`.
84+
"""
85+
overlaps(g1) = Base.Fix2(overlaps, g1)
86+
7987
"""
8088
overlaps(::GI.AbstractTrait, geom1, ::GI.AbstractTrait, geom2)::Bool
8189

src/methods/geom_relations/touches.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ true
7878
"""
7979
touches(g1, g2)::Bool = _touches(trait(g1), g1, trait(g2), g2)
8080

81+
"""
82+
touches(g1)
83+
84+
Return a function that checks if its input touches `g1`.
85+
This is equivalent to `x -> touches(x, g1)`.
86+
"""
87+
touches(g1) = Base.Fix2(touches, g1)
88+
8189
# # Convert features to geometries
8290
_touches(::GI.FeatureTrait, g1, ::Any, g2) = touches(GI.geometry(g1), g2)
8391
_touches(::Any, g1, t2::GI.FeatureTrait, g2) = touches(g1, GI.geometry(g2))

src/methods/geom_relations/within.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ true
8282
"""
8383
within(g1, g2) = _within(trait(g1), g1, trait(g2), g2)
8484

85+
"""
86+
within(g1)
87+
88+
Return a function that checks if its input is within `g1`.
89+
This is equivalent to `x -> within(x, g1)`.
90+
"""
91+
within(g1) = Base.Fix2(within, g1)
92+
8593
# # Convert features to geometries
8694
_within(::GI.FeatureTrait, g1, ::Any, g2) = within(GI.geometry(g1), g2)
8795
_within(::Any, g1, t2::GI.FeatureTrait, g2) = within(g1, GI.geometry(g2))

test/methods/geom_relations.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,15 @@ end
331331
@test GO.crosses(GI.LineString([(-2.0, 2.0), (-4.0, 2.0)]), $poly7) == false
332332
end
333333
end
334+
335+
@testset "Single-argument methods" begin
336+
@test GO.contains(p2)(p1) == GO.contains(p1, p2)
337+
@test GO.coveredby(p2)(p1) == GO.coveredby(p1, p2)
338+
@test GO.covers(p2)(p1) == GO.covers(p1, p2)
339+
@test GO.crosses(l2)(l1) == GO.crosses(l1, l2)
340+
@test GO.disjoint(p2)(p1) == GO.disjoint(p1, p2)
341+
@test GO.intersects(p2)(p1) == GO.intersects(p1, p2)
342+
@test GO.overlaps(p2)(p1) == GO.overlaps(p1, p2)
343+
@test GO.touches(p2)(p1) == GO.touches(p1, p2)
344+
@test GO.within(p2)(p1) == GO.within(p1, p2)
345+
end

0 commit comments

Comments
 (0)