Skip to content

Commit

Permalink
updating sweepline algorithm with AVLTrees, needs
Browse files Browse the repository at this point in the history
more work
  • Loading branch information
souma4 committed Dec 29, 2024
1 parent 2ee18ae commit 22eec48
Showing 1 changed file with 63 additions and 11 deletions.
74 changes: 63 additions & 11 deletions src/utils/sweepline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function bentleyottmann(segments)
S = Tuple{P,P}

# initialization
𝒬 = AVLTree{P}()
𝒯 = AVLTree{S}()
𝒬 = BinaryTrees.AVLTree{P}()
𝒯 = BinaryTrees.AVLTree{S}()
= Dict{P,Vector{S}}()
𝒰 = Dict{P,Vector{S}}()
𝒞 = Dict{P,Vector{S}}()
Expand Down Expand Up @@ -57,20 +57,72 @@ function bentleyottmann(segments)
end

function handle!(I, p, 𝒬, 𝒯, ℒ, 𝒰, 𝒞)
ss = ℒ[p] 𝒰[p] 𝒞[p]
if length(ss) > 1
I[p] = ss
# Segments that start, end, or intersect at p
start_segments = ℒ[p]
end_segments = 𝒰[p]
intersection_segments = 𝒞[p]

# If there are multiple segments intersecting at p, record the intersection
if length(start_segments end_segments intersection_segments) > 1
I[p] = start_segments end_segments intersection_segments
end
for s in ℒ[p] 𝒞[p]

# Remove segments that end at p from the status structure
for s in end_segments intersection_segments
BinaryTrees.delete!(𝒯, s)
end
for s in 𝒰[p] 𝒞[p]

# Insert segments that start at p into the status structure
for s in start_segments intersection_segments
BinaryTrees.insert!(𝒯, s)
end
if length(𝒰[p] 𝒞[p]) == 0
# n = BinaryTrees.search(𝒯, p)
else
node = BinaryTrees.root(𝒬)

# Find new event points caused by the insertion or deletion of segments
for s in start_segments
s = Segment(s)
pred = BinaryTrees.left(node)
succ = BinaryTrees.right(node)
ns = Segment(pred, succ)
if pred !== nothing
new_geom, new_type = _newevent(s, ns)
if new_geom == IntersectionType(0)
BinaryTrees.insert!(𝒬, new_geom)
end
end
if succ !== nothing
new_geom, new_type = _newevent(s, ns)
if new_type == IntersectionType(0)
BinaryTrees.insert!(𝒬, new_geom)
end
end
end

for s in end_segments
s = Segment(s)
pred = BinaryTrees.left(node)
succ = BinaryTrees.right(node)
ns = Segment(pred, succ)
if pred !== nothing && succ !== nothing
new_geom, new_type = _newevent(s, ns)
if new_type == IntersectionType(0)
BinaryTrees.insert!(𝒬, new_geom)
end
end
end
end

_key(node::BinaryTrees.AVLNode) = node.key
_key(node::BinaryTrees.AVLNode) = node.key
_geom(intersect::Intersection) = intersect.geom
_type(intersect::Intersection) = intersect.type
function _newevent(s₁::Segment, s₂::Segment)
new_event = intersection(s₁, s₂)
_geom(new_event), _type(new_event)
end


function Segment(node₁::BinaryTrees.BinaryNode, node₂::BinaryTrees.BinaryNode)
node₁ = _key(node₁)
node₂ = _key(node₂)
Segment((node₁, node₂))
end

0 comments on commit 22eec48

Please sign in to comment.