Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

fix type instability in self_intersections #189

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/lines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,20 @@ function simple_concat(vec, range, endpoint::P) where P
result
end

function consecutive_pairs(arr)
n = length(arr)
zip(view(arr, 1:n-1), view(arr, 2:n))
end

"""
Finds all self intersections of polygon `points`
"""
function self_intersections(points::Vector{Point{N,T}}) where {N,T}
sections = Point{N,T}[]
intersections = Int[]
wraparound = i-> mod1(i, length(points) - 1)
for (i, (a,b)) in enumerate(partition(points, 2, 1))
for (j, (a2, b2)) in enumerate(partition(points, 2, 1))
for (i, (a,b)) in enumerate(consecutive_pairs(points))
for (j, (a2, b2)) in enumerate(consecutive_pairs(points))
is1, is2 = wraparound(i+1), wraparound(i-1)
if i!=j && is1!=j && is2!=j && !(i in intersections) && !(j in intersections)
intersected, p = GeometryTypes.intersects(LineSegment(a,b), LineSegment(a2, b2))
Expand Down