@@ -25,8 +25,8 @@ function bentleyottmann(segments)
2525 S = Tuple{P,P}
2626
2727 # initialization
28- 𝒬 = AVLTree {P} ()
29- 𝒯 = AVLTree {S} ()
28+ 𝒬 = BinaryTrees . AVLTree {P} ()
29+ 𝒯 = BinaryTrees . AVLTree {S} ()
3030 ℒ = Dict {P,Vector{S}} ()
3131 𝒰 = Dict {P,Vector{S}} ()
3232 𝒞 = Dict {P,Vector{S}} ()
@@ -57,20 +57,72 @@ function bentleyottmann(segments)
5757end
5858
5959function handle! (I, p, 𝒬, 𝒯, ℒ, 𝒰, 𝒞)
60- ss = ℒ[p] ∪ 𝒰[p] ∪ 𝒞[p]
61- if length (ss) > 1
62- I[p] = ss
60+ # Segments that start, end, or intersect at p
61+ start_segments = ℒ[p]
62+ end_segments = 𝒰[p]
63+ intersection_segments = 𝒞[p]
64+
65+ # If there are multiple segments intersecting at p, record the intersection
66+ if length (start_segments ∪ end_segments ∪ intersection_segments) > 1
67+ I[p] = start_segments ∪ end_segments ∪ intersection_segments
6368 end
64- for s in ℒ[p] ∪ 𝒞[p]
69+
70+ # Remove segments that end at p from the status structure
71+ for s in end_segments ∪ intersection_segments
6572 BinaryTrees. delete! (𝒯, s)
6673 end
67- for s in 𝒰[p] ∪ 𝒞[p]
74+
75+ # Insert segments that start at p into the status structure
76+ for s in start_segments ∪ intersection_segments
6877 BinaryTrees. insert! (𝒯, s)
6978 end
70- if length (𝒰[p] ∪ 𝒞[p]) == 0
71- # n = BinaryTrees.search(𝒯, p)
72- else
79+ node = BinaryTrees. root (𝒬)
80+
81+ # Find new event points caused by the insertion or deletion of segments
82+ for s in start_segments
83+ s = Segment (s)
84+ pred = BinaryTrees. left (node)
85+ succ = BinaryTrees. right (node)
86+ ns = Segment (pred, succ)
87+ if pred != = nothing
88+ new_geom, new_type = _newevent (s, ns)
89+ if new_geom == IntersectionType (0 )
90+ BinaryTrees. insert! (𝒬, new_geom)
91+ end
92+ end
93+ if succ != = nothing
94+ new_geom, new_type = _newevent (s, ns)
95+ if new_type == IntersectionType (0 )
96+ BinaryTrees. insert! (𝒬, new_geom)
97+ end
98+ end
99+ end
100+
101+ for s in end_segments
102+ s = Segment (s)
103+ pred = BinaryTrees. left (node)
104+ succ = BinaryTrees. right (node)
105+ ns = Segment (pred, succ)
106+ if pred != = nothing && succ != = nothing
107+ new_geom, new_type = _newevent (s, ns)
108+ if new_type == IntersectionType (0 )
109+ BinaryTrees. insert! (𝒬, new_geom)
110+ end
111+ end
73112 end
74113end
75114
76- _key (node:: BinaryTrees.AVLNode ) = node. key
115+ _key (node:: BinaryTrees.AVLNode ) = node. key
116+ _geom (intersect:: Intersection ) = intersect. geom
117+ _type (intersect:: Intersection ) = intersect. type
118+ function _newevent (s₁:: Segment , s₂:: Segment )
119+ new_event = intersection (s₁, s₂)
120+ _geom (new_event), _type (new_event)
121+ end
122+
123+
124+ function Segment (node₁:: BinaryTrees.BinaryNode , node₂:: BinaryTrees.BinaryNode )
125+ node₁ = _key (node₁)
126+ node₂ = _key (node₂)
127+ Segment ((node₁, node₂))
128+ end
0 commit comments