Skip to content

Commit 0cc9501

Browse files
john-h-kastnernyalldawson
authored andcommitted
Remove try-except block in voronoi.py fixes #19798
This block was swallowing all exceptions within the voronoi method. Removing the block causes exceptions throw in the method to propagate up the stack and eventually become visible in log files.
1 parent 808963b commit 0cc9501

File tree

1 file changed

+133
-139
lines changed

1 file changed

+133
-139
lines changed

python/plugins/processing/algs/qgis/voronoi.py

+133-139
Original file line numberDiff line numberDiff line change
@@ -224,146 +224,140 @@ def outEdge(self, edge):
224224

225225

226226
def voronoi(siteList, context):
227-
try:
228-
edgeList = EdgeList(siteList.xmin, siteList.xmax, len(siteList))
229-
priorityQ = PriorityQueue(siteList.ymin, siteList.ymax, len(siteList))
230-
siteIter = siteList.iterator()
231-
232-
bottomsite = next(siteIter)
233-
context.outSite(bottomsite)
234-
newsite = next(siteIter)
235-
minpt = Site(-BIG_FLOAT, -BIG_FLOAT)
236-
while True:
237-
if not priorityQ.isEmpty():
238-
minpt = priorityQ.getMinPt()
239-
240-
if (newsite and (priorityQ.isEmpty() or cmp(newsite, minpt) < 0)):
241-
# newsite is smallest - this is a site event
242-
context.outSite(newsite)
243-
244-
# get first Halfedge to the LEFT and RIGHT of the new site
245-
lbnd = edgeList.leftbnd(newsite)
246-
rbnd = lbnd.right
247-
248-
# if this halfedge has no edge, bot = bottom site (whatever that is)
249-
# create a new edge that bisects
250-
bot = lbnd.rightreg(bottomsite)
251-
edge = Edge.bisect(bot, newsite)
252-
context.outBisector(edge)
253-
254-
# create a new Halfedge, setting its pm field to 0 and insert
255-
# this new bisector edge between the left and right vectors in
256-
# a linked list
257-
bisector = Halfedge(edge, Edge.LE)
258-
edgeList.insert(lbnd, bisector)
259-
260-
# if the new bisector intersects with the left edge, remove
261-
# the left edge's vertex, and put in the new one
262-
p = lbnd.intersect(bisector)
263-
if p is not None:
264-
priorityQ.delete(lbnd)
265-
priorityQ.insert(lbnd, p, newsite.distance(p))
266-
267-
# create a new Halfedge, setting its pm field to 1
268-
# insert the new Halfedge to the right of the original bisector
269-
lbnd = bisector
270-
bisector = Halfedge(edge, Edge.RE)
271-
edgeList.insert(lbnd, bisector)
272-
273-
# if this new bisector intersects with the right Halfedge
274-
p = bisector.intersect(rbnd)
275-
if p is not None:
276-
# push the Halfedge into the ordered linked list of vertices
277-
priorityQ.insert(bisector, p, newsite.distance(p))
278-
279-
newsite = next(siteIter)
280-
281-
elif not priorityQ.isEmpty():
282-
# intersection is smallest - this is a vector (circle) event
283-
284-
# pop the Halfedge with the lowest vector off the ordered list of
285-
# vectors. Get the Halfedge to the left and right of the above HE
286-
# and also the Halfedge to the right of the right HE
287-
lbnd = priorityQ.popMinHalfedge()
288-
llbnd = lbnd.left
289-
rbnd = lbnd.right
290-
rrbnd = rbnd.right
291-
292-
# get the Site to the left of the left HE and to the right of
293-
# the right HE which it bisects
294-
bot = lbnd.leftreg(bottomsite)
295-
top = rbnd.rightreg(bottomsite)
296-
297-
# output the triple of sites, stating that a circle goes through them
298-
mid = lbnd.rightreg(bottomsite)
299-
context.outTriple(bot, top, mid)
300-
301-
# get the vertex that caused this event and set the vertex number
302-
# couldn't do this earlier since we didn't know when it would be processed
303-
v = lbnd.vertex
304-
siteList.setSiteNumber(v)
305-
context.outVertex(v)
306-
307-
# set the endpoint of the left and right Halfedge to be this vector
308-
if lbnd.edge.setEndpoint(lbnd.pm, v):
309-
context.outEdge(lbnd.edge)
310-
311-
if rbnd.edge.setEndpoint(rbnd.pm, v):
312-
context.outEdge(rbnd.edge)
313-
314-
# delete the lowest HE, remove all vertex events to do with the
315-
# right HE and delete the right HE
316-
edgeList.delete(lbnd)
317-
priorityQ.delete(rbnd)
318-
edgeList.delete(rbnd)
319-
320-
# if the site to the left of the event is higher than the Site
321-
# to the right of it, then swap them and set 'pm' to RIGHT
322-
pm = Edge.LE
323-
if bot.y > top.y:
324-
bot, top = top, bot
325-
pm = Edge.RE
326-
327-
# Create an Edge (or line) that is between the two Sites. This
328-
# creates the formula of the line, and assigns a line number to it
329-
edge = Edge.bisect(bot, top)
330-
context.outBisector(edge)
331-
332-
# create a HE from the edge
333-
bisector = Halfedge(edge, pm)
334-
335-
# insert the new bisector to the right of the left HE
336-
# set one endpoint to the new edge to be the vector point 'v'
337-
# If the site to the left of this bisector is higher than the right
338-
# Site, then this endpoint is put in position 0; otherwise in pos 1
339-
edgeList.insert(llbnd, bisector)
340-
if edge.setEndpoint(Edge.RE - pm, v):
341-
context.outEdge(edge)
342-
343-
# if left HE and the new bisector don't intersect, then delete
344-
# the left HE, and reinsert it
345-
p = llbnd.intersect(bisector)
346-
if p is not None:
347-
priorityQ.delete(llbnd)
348-
priorityQ.insert(llbnd, p, bot.distance(p))
349-
350-
# if right HE and the new bisector don't intersect, then reinsert it
351-
p = bisector.intersect(rrbnd)
352-
if p is not None:
353-
priorityQ.insert(bisector, p, bot.distance(p))
354-
else:
355-
break
227+
edgeList = EdgeList(siteList.xmin, siteList.xmax, len(siteList))
228+
priorityQ = PriorityQueue(siteList.ymin, siteList.ymax, len(siteList))
229+
siteIter = siteList.iterator()
230+
231+
bottomsite = next(siteIter)
232+
context.outSite(bottomsite)
233+
newsite = next(siteIter)
234+
minpt = Site(-BIG_FLOAT, -BIG_FLOAT)
235+
while True:
236+
if not priorityQ.isEmpty():
237+
minpt = priorityQ.getMinPt()
238+
239+
if (newsite and (priorityQ.isEmpty() or cmp(newsite, minpt) < 0)):
240+
# newsite is smallest - this is a site event
241+
context.outSite(newsite)
242+
243+
# get first Halfedge to the LEFT and RIGHT of the new site
244+
lbnd = edgeList.leftbnd(newsite)
245+
rbnd = lbnd.right
246+
247+
# if this halfedge has no edge, bot = bottom site (whatever that is)
248+
# create a new edge that bisects
249+
bot = lbnd.rightreg(bottomsite)
250+
edge = Edge.bisect(bot, newsite)
251+
context.outBisector(edge)
252+
253+
# create a new Halfedge, setting its pm field to 0 and insert
254+
# this new bisector edge between the left and right vectors in
255+
# a linked list
256+
bisector = Halfedge(edge, Edge.LE)
257+
edgeList.insert(lbnd, bisector)
258+
259+
# if the new bisector intersects with the left edge, remove
260+
# the left edge's vertex, and put in the new one
261+
p = lbnd.intersect(bisector)
262+
if p is not None:
263+
priorityQ.delete(lbnd)
264+
priorityQ.insert(lbnd, p, newsite.distance(p))
265+
266+
# create a new Halfedge, setting its pm field to 1
267+
# insert the new Halfedge to the right of the original bisector
268+
lbnd = bisector
269+
bisector = Halfedge(edge, Edge.RE)
270+
edgeList.insert(lbnd, bisector)
271+
272+
# if this new bisector intersects with the right Halfedge
273+
p = bisector.intersect(rbnd)
274+
if p is not None:
275+
# push the Halfedge into the ordered linked list of vertices
276+
priorityQ.insert(bisector, p, newsite.distance(p))
277+
278+
newsite = next(siteIter)
279+
280+
elif not priorityQ.isEmpty():
281+
# intersection is smallest - this is a vector (circle) event
282+
283+
# pop the Halfedge with the lowest vector off the ordered list of
284+
# vectors. Get the Halfedge to the left and right of the above HE
285+
# and also the Halfedge to the right of the right HE
286+
lbnd = priorityQ.popMinHalfedge()
287+
llbnd = lbnd.left
288+
rbnd = lbnd.right
289+
rrbnd = rbnd.right
290+
291+
# get the Site to the left of the left HE and to the right of
292+
# the right HE which it bisects
293+
bot = lbnd.leftreg(bottomsite)
294+
top = rbnd.rightreg(bottomsite)
295+
296+
# output the triple of sites, stating that a circle goes through them
297+
mid = lbnd.rightreg(bottomsite)
298+
context.outTriple(bot, top, mid)
299+
300+
# get the vertex that caused this event and set the vertex number
301+
# couldn't do this earlier since we didn't know when it would be processed
302+
v = lbnd.vertex
303+
siteList.setSiteNumber(v)
304+
context.outVertex(v)
305+
306+
# set the endpoint of the left and right Halfedge to be this vector
307+
if lbnd.edge.setEndpoint(lbnd.pm, v):
308+
context.outEdge(lbnd.edge)
309+
310+
if rbnd.edge.setEndpoint(rbnd.pm, v):
311+
context.outEdge(rbnd.edge)
312+
313+
# delete the lowest HE, remove all vertex events to do with the
314+
# right HE and delete the right HE
315+
edgeList.delete(lbnd)
316+
priorityQ.delete(rbnd)
317+
edgeList.delete(rbnd)
318+
319+
# if the site to the left of the event is higher than the Site
320+
# to the right of it, then swap them and set 'pm' to RIGHT
321+
pm = Edge.LE
322+
if bot.y > top.y:
323+
bot, top = top, bot
324+
pm = Edge.RE
325+
326+
# Create an Edge (or line) that is between the two Sites. This
327+
# creates the formula of the line, and assigns a line number to it
328+
edge = Edge.bisect(bot, top)
329+
context.outBisector(edge)
330+
331+
# create a HE from the edge
332+
bisector = Halfedge(edge, pm)
333+
334+
# insert the new bisector to the right of the left HE
335+
# set one endpoint to the new edge to be the vector point 'v'
336+
# If the site to the left of this bisector is higher than the right
337+
# Site, then this endpoint is put in position 0; otherwise in pos 1
338+
edgeList.insert(llbnd, bisector)
339+
if edge.setEndpoint(Edge.RE - pm, v):
340+
context.outEdge(edge)
341+
342+
# if left HE and the new bisector don't intersect, then delete
343+
# the left HE, and reinsert it
344+
p = llbnd.intersect(bisector)
345+
if p is not None:
346+
priorityQ.delete(llbnd)
347+
priorityQ.insert(llbnd, p, bot.distance(p))
348+
349+
# if right HE and the new bisector don't intersect, then reinsert it
350+
p = bisector.intersect(rrbnd)
351+
if p is not None:
352+
priorityQ.insert(bisector, p, bot.distance(p))
353+
else:
354+
break
356355

357-
he = edgeList.leftend.right
358-
while he is not edgeList.rightend:
359-
context.outEdge(he.edge)
360-
he = he.right
361-
Edge.EDGE_NUM = 0
362-
except Exception as err:
363-
# fix_print_with_import
364-
print("######################################################")
365-
# fix_print_with_import
366-
print(str(err))
356+
he = edgeList.leftend.right
357+
while he is not edgeList.rightend:
358+
context.outEdge(he.edge)
359+
he = he.right
360+
Edge.EDGE_NUM = 0
367361

368362
# ------------------------------------------------------------------
369363

0 commit comments

Comments
 (0)