Commit 3587347a authored by Michael Büsch's avatar Michael Büsch

fup: Rename collision cache

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent 2072ffc2
......@@ -91,8 +91,9 @@ class FupGrid(object):
resizeEvent = None
class Line(object):
"""Inter-element line descriptor.
This is used for describing drawn wires.
"""Collision cache line descriptor.
This is used for describing drawn wires and
detecting collisions among them.
"""
def __init__(self, lineSeg, wire=None):
......@@ -125,7 +126,7 @@ class FupGrid(object):
self.clickedConn = None # The recently clicked connection in this grid
self.clickedArea = None # The recently clicked area in this grid
self.clearLineCache()
self.collisionCacheClear()
def clear(self):
for wire in self.wires:
......@@ -133,13 +134,20 @@ class FupGrid(object):
self.wires.clear()
self.elems = []
self.selectedElems.clear()
self.clearLineCache()
self.collisionCacheClear()
def clearLineCache(self):
"""Clear the cache of drawn inter-element lines.
def collisionCacheClear(self):
"""Clear the collision cache of drawn lines.
"""
# __lines is a list of Line() instances.
self.__lines = []
# __collCacheLines is a list of FupGrid.Line() instances.
self.__collCacheLines = []
def collisionCacheAdd(self, line):
"""Add a line entry to the collision cache.
line => A FupGrid.Line() instance
"""
assert(isinstance(line, self.Line))
self.__collCacheLines.append(line)
def resize(self, width, height):
"""Resize the grid.
......@@ -184,8 +192,8 @@ class FupGrid(object):
"""
with contextlib.suppress(KeyError):
self.wires.remove(wire)
# Remove Line()s that belong to 'wire'.
self.__lines = [ line for line in self.__lines
# Remove Line()s that belong to 'wire' from the collision cache.
self.__collCacheLines = [ line for line in self.__collCacheLines
if line.wire is not wire ]
def getWireById(self, wireIdNum):
......@@ -221,7 +229,7 @@ class FupGrid(object):
Returns a set of colliding self.Line() instances.
"""
collisions = set()
for line in self.__lines:
for line in self.__collCacheLines:
if line.wire in excludeWires:
continue
inter = lineSeg.intersection(line.lineSeg)
......@@ -240,7 +248,7 @@ class FupGrid(object):
return # Zero length line
painter.drawLine(lineSeg.pointA.xInt, lineSeg.pointA.yInt,
lineSeg.pointB.xInt, lineSeg.pointB.yInt)
self.__lines.append(self.Line(lineSeg, wire=wire))
self.collisionCacheAdd(self.Line(lineSeg, wire=wire))
@property
def cellPixWidth(self):
......
......@@ -331,8 +331,8 @@ class FupDrawWidget(QWidget):
if not grid:
return
# Build a new line cache.
grid.clearLineCache()
# Build a new collision cache.
grid.collisionCacheClear()
size = self.size()
width, height = size.width(), size.height()
......@@ -421,10 +421,6 @@ class FupDrawWidget(QWidget):
selWidth, selHeight,
r, r)
# We don't need the line cache anymore.
# The next paint event will build a new one.
grid.clearLineCache()
def posToGridCoords(self, pixX, pixY):
"""Convert pixel coordinates to grid coordinates.
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment