Skip to content

Commit 686b3e8

Browse files
committed
Pass exact through point intersections
Signed-off-by: Avnish Jaltare <avnishjaltare8@gmail.com>
1 parent 9de9c8e commit 686b3e8

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/methods/clipping/intersection.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ GI.coordinates.(inter_points)
4040
```
4141
"""
4242
function intersection(
43-
alg::FosterHormannClipping, geom_a, geom_b, ::Type{T}=Float64; target=nothing, kwargs...
43+
alg::FosterHormannClipping, geom_a, geom_b, ::Type{T}=Float64; target=nothing, exact = True(), kwargs...
4444
) where {T<:AbstractFloat}
4545
return _intersection(
4646
alg, TraitTarget(target), T, GI.trait(geom_a), geom_a, GI.trait(geom_b), geom_b;
47-
exact = True(), kwargs...,
47+
exact, kwargs...,
4848
)
4949
end
5050
# fallback definitions
@@ -64,8 +64,8 @@ _intersection(
6464
alg::FosterHormannClipping, ::TraitTarget{GI.PointTrait}, ::Type{T},
6565
trait_a::Union{GI.LineTrait, GI.LineStringTrait, GI.LinearRingTrait}, geom_a,
6666
trait_b::Union{GI.LineTrait, GI.LineStringTrait, GI.LinearRingTrait}, geom_b;
67-
kwargs...,
68-
) where T = _intersection_points(alg.manifold, alg.accelerator, T, trait_a, geom_a, trait_b, geom_b)
67+
exact, kwargs...,
68+
) where T = _intersection_points(alg.manifold, alg.accelerator, T, trait_a, geom_a, trait_b, geom_b; exact)
6969

7070
#= Polygon-Polygon Intersections with target Polygon
7171
The algorithm to determine the intersection was adapted from "Efficient clipping
@@ -200,10 +200,10 @@ function _intersection(
200200
end
201201

202202
"""
203-
intersection_points(geom_a, geom_b, [T::Type])
203+
intersection_points(geom_a, geom_b, [T::Type]; exact = True())
204204
205205
Return a list of intersection tuple points between two geometries. If no intersection points
206-
exist, returns an empty list.
206+
exist, returns an empty list. Set `exact = false` to use the inexact predicate path.
207207
208208
## Example
209209
@@ -218,13 +218,14 @@ inter_points = GO.intersection_points(line1, line2)
218218
1-element Vector{Tuple{Float64, Float64}}:
219219
(125.58375366067548, -14.83572303404496)
220220
"""
221-
intersection_points(geom_a, geom_b, ::Type{T} = Float64) where T <: AbstractFloat = intersection_points(FosterHormannClipping(Planar()), geom_a, geom_b, T)
222-
function intersection_points(alg::FosterHormannClipping{M, A}, geom_a, geom_b, ::Type{T} = Float64) where {M, A, T <: AbstractFloat}
223-
return _intersection_points(alg.manifold, alg.accelerator, T, GI.trait(geom_a), geom_a, GI.trait(geom_b), geom_b)
221+
intersection_points(geom_a, geom_b, ::Type{T} = Float64; exact = True()) where T <: AbstractFloat =
222+
intersection_points(FosterHormannClipping(Planar()), geom_a, geom_b, T; exact)
223+
function intersection_points(alg::FosterHormannClipping{M, A}, geom_a, geom_b, ::Type{T} = Float64; exact = True()) where {M, A, T <: AbstractFloat}
224+
return _intersection_points(alg.manifold, alg.accelerator, T, GI.trait(geom_a), geom_a, GI.trait(geom_b), geom_b; exact)
224225
end
225226

226-
function intersection_points(m::Manifold, a::IntersectionAccelerator, geom_a, geom_b, ::Type{T} = Float64) where T <: AbstractFloat
227-
return _intersection_points(m, a, T, GI.trait(geom_a), geom_a, GI.trait(geom_b), geom_b)
227+
function intersection_points(m::Manifold, a::IntersectionAccelerator, geom_a, geom_b, ::Type{T} = Float64; exact = True()) where T <: AbstractFloat
228+
return _intersection_points(m, a, T, GI.trait(geom_a), geom_a, GI.trait(geom_b), geom_b; exact)
228229
end
229230

230231

test/methods/clipping/intersection_points.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ p1, p2 = GI.Polygon([l1]), GI.Polygon([l2])
1717
# Three intersection points
1818
LG_l1_l2_mp = GI.MultiPoint(collect(GI.getpoint(LG.intersection($l1, $l2))))
1919
@test GO.equals(GI.MultiPoint(GO.intersection_points($l1, $l2)), LG_l1_l2_mp)
20+
@test GO.equals(GI.MultiPoint(GO.intersection_points($l1, $l2; exact = false)), LG_l1_l2_mp)
21+
@test GO.equals(GI.MultiPoint(GO.intersection($l1, $l2; target = GI.PointTrait(), exact = false)), LG_l1_l2_mp)
2022

2123
# Four intersection points with large intersection
2224
LG_l3_l4_mp = GI.MultiPoint(collect(GI.getpoint(LG.intersection($l3, $l4))))

0 commit comments

Comments
 (0)