TaipanRex / pyvisgraph

Given a list of simple obstacle polygons, build the visibility graph and find the shortest path between two points
MIT License
217 stars 45 forks source link

IndexError #50

Open drewjgray opened 4 years ago

drewjgray commented 4 years ago

Hi! This is an amazing library and I have really enjoyed working with it. I have come across an issue I haven't been able to root cause. Some of the shapefiles I have used (such as: https://geodata.lib.berkeley.edu/catalog/ark28722-s7d02x) will have an IndexError during if self._open_edges[index] == edge, where the index is -1 (calculated from index = self._index(p1, p2, edge) - 1 in the delete function of class OpenEdges. I have been unable to figure out why some shapefiles would lead to this. I have examined and cleaned the polygons closely in QGIS. Any ideas on how to overcome this?

JvandenAssum commented 2 years ago

Hi man, I encoutered the same problem while using polygons extracted from QGIS. self._open_edges gave an empty list sometimes.

My solution was to change the code to: def delete(self, p1, p2, edge): index = self._index(p1, p2, edge) - 1 if self._open_edges: if self._open_edges[index] == edge: del self._open_edges[index]