Skip to content

Commit 5d649b5

Browse files
committed
Forward exact through recursive intersections
Signed-off-by: Avnish Jaltare <avnishjaltare8@gmail.com>
1 parent 686b3e8 commit 5d649b5

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

src/methods/clipping/intersection.jl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,23 @@ Enum for the orientation of a line with respect to a curve. A line can be
1010
@enum LineOrientation line_cross=1 line_hinge=2 line_over=3 line_out=4
1111

1212
"""
13-
intersection(geom_a, geom_b, [T::Type]; target::Type, fix_multipoly = UnionIntersectingPolygons())
13+
intersection(geom_a, geom_b, [T::Type];
14+
target::Type,
15+
exact = True(),
16+
fix_multipoly = UnionIntersectingPolygons())
1417
1518
Return the intersection between two geometries as a list of geometries. Return an empty list
1619
if none are found. The type of the list will be constrained as much as possible given the
1720
input geometries. Furthermore, the user can provide a `target` type as a keyword argument and
1821
a list of target geometries found in the intersection will be returned. The user can also
19-
provide a float type that they would like the points of returned geometries to be. If the
20-
user is taking a intersection involving one or more multipolygons, and the multipolygon
21-
might be comprised of polygons that intersect, if `fix_multipoly` is set to an
22-
`IntersectingPolygons` correction (the default is `UnionIntersectingPolygons()`), then the
23-
needed multipolygons will be fixed to be valid before performing the intersection to ensure
24-
a correct answer. Only set `fix_multipoly` to nothing if you know that the multipolygons are
25-
valid, as it will avoid unneeded computation.
22+
provide a float type that they would like the points of returned geometries to be. Set
23+
`exact = false` (or `False()`) to use the inexact predicate path instead of the default
24+
exact one. If the user is taking a intersection involving one or more multipolygons, and
25+
the multipolygon might be comprised of polygons that intersect, if `fix_multipoly` is set
26+
to an `IntersectingPolygons` correction (the default is `UnionIntersectingPolygons()`),
27+
then the needed multipolygons will be fixed to be valid before performing the intersection
28+
to ensure a correct answer. Only set `fix_multipoly` to nothing if you know that the
29+
multipolygons are valid, as it will avoid unneeded computation.
2630
2731
## Example
2832
@@ -132,7 +136,7 @@ function _intersection(
132136
end
133137
polys = Vector{_get_poly_type(T)}()
134138
for poly_b in GI.getpolygon(multipoly_b)
135-
append!(polys, intersection(alg, poly_a, poly_b; target))
139+
append!(polys, intersection(alg, poly_a, poly_b; target, kwargs...))
136140
end
137141
return polys
138142
end
@@ -165,7 +169,7 @@ function _intersection(
165169
end
166170
polys = Vector{_get_poly_type(T)}()
167171
for poly_a in GI.getpolygon(multipoly_a)
168-
append!(polys, intersection(alg, poly_a, multipoly_b; target, fix_multipoly))
172+
append!(polys, intersection(alg, poly_a, multipoly_b; target, fix_multipoly, kwargs...))
169173
end
170174
return polys
171175
end

test/methods/clipping/intersection_points.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ l5 = GI.LineString([(19999.999, 25000.0), (19999.999, 29000.0), (39999.998999999
1212
l6 = GI.LineString([(0.0, 25000.0), (0.0, 29000.0), (20000.0, 29000.0), (20000.0, 25000.0), (0.0, 25000.0)])
1313

1414
p1, p2 = GI.Polygon([l1]), GI.Polygon([l2])
15+
mp1 = GI.MultiPolygon([p1, GI.Polygon([l3])])
16+
17+
struct TrackingExact end
18+
GO.GeometryOpsCore.booltype(::TrackingExact) = error("tracking exact forwarded")
1519

1620
@testset_implementations begin
1721
# Three intersection points
@@ -33,4 +37,7 @@ p1, p2 = GI.Polygon([l1]), GI.Polygon([l2])
3337

3438
# No intersection points between polygon and line
3539
@test isempty(GO.intersection_points($p1, $l6))
40+
41+
# Recursive polygon-multipolygon intersections should forward `exact`
42+
@test_throws "tracking exact forwarded" GO.intersection($p1, $mp1; target = GI.PolygonTrait(), exact = TrackingExact())
3643
end

0 commit comments

Comments
 (0)