def getPolygon(self, x, y): """ Returns the polygon that fills the coordinate x, y. What is returned is a list of the form (x1, y1, x2, y2, ...). If there is no polyon, None is returned. If there are multiple polygons, the polygon with the lowest index (first polygon in the list) is returned. """ whichPolygon = insideWhichPolygon( self.polygonsX, self.polygonsY, self.polygonBeginningsIndex, self.polygonNumberOfItems, x, y ) # not inside any polygon if whichPolygon == -1: return None index = self.polygonBeginningsIndex[whichPolygon] numberOfItems = self.polygonNumberOfItems[whichPolygon] polygon = [] # pull out just the interesting polygon and flatten it # so it can easily be displayed for i in range(numberOfItems): polygon += self.polygonsX[index + i], self.polygonsY[index + i] return polygon
def getPolygon(self, x, y): """ Returns the polygon that fills the coordinate x, y. What is returned is a list of the form (x1, y1, x2, y2, ...). If there is no polyon, None is returned. If there are multiple polygons, the polygon with the lowest index (first polygon in the list) is returned. """ whichPolygon = insideWhichPolygon(self.polygonsX, self.polygonsY, self.polygonBeginningsIndex, self.polygonNumberOfItems, x, y) # not inside any polygon if whichPolygon == -1: return None index = self.polygonBeginningsIndex[whichPolygon] numberOfItems = self.polygonNumberOfItems[whichPolygon] polygon = [] # pull out just the interesting polygon and flatten it # so it can easily be displayed for i in range(numberOfItems): polygon += self.polygonsX[index + i], self.polygonsY[index + i] return polygon
def removePolygon(self, x, y): """ Removes the polygon that fills the coordinate x, y If there are multiple polygons, the polygon with the lowest index (first polygon in the list) is returned. Returns 1 if a polygon was acutally removed. 0 is returned otherwise. """ whichPolygon = insideWhichPolygon(self.polygonsX, self.polygonsY, self.polygonBeginningsIndex, self.polygonNumberOfItems, x, y) # No polygon to delete, so do nothing if whichPolygon == -1: return 0 index = self.polygonBeginningsIndex[whichPolygon] numberOfItems = self.polygonNumberOfItems[whichPolygon] oldSize = self.polygonsX.shape[0] newSize = oldSize - numberOfItems newPolygonsX = Numeric.zeros((newSize, ), Numeric.Float) newPolygonsY = Numeric.zeros((newSize, ), Numeric.Float) # remove the offending polygon newPolygonsX[0:index] = self.polygonsX[0:index] newPolygonsX[index:] = self.polygonsX[index + numberOfItems:] newPolygonsY[0:index] = self.polygonsY[0:index] newPolygonsY[index:] = self.polygonsY[index + numberOfItems:] oldNumberOfPolygons = self.polygonNumberOfItems.shape[0] newNumberOfPolygons = oldNumberOfPolygons - 1 newPolygonBeginningsIndex = Numeric.zeros((newNumberOfPolygons, ), Numeric.Int) newPolygonNumberOfItems = Numeric.zeros((newNumberOfPolygons, ), Numeric.Int) newPolygonBeginningsIndex[0:whichPolygon] = \ self.polygonBeginningsIndex[0:whichPolygon] # note that the indicies of the items after the offending # polygon need to be modified to affect the new array newPolygonBeginningsIndex[whichPolygon:] = \ (self.polygonBeginningsIndex[whichPolygon+1:]-numberOfItems) newPolygonNumberOfItems[0:whichPolygon] = \ self.polygonNumberOfItems[0:whichPolygon] newPolygonNumberOfItems[whichPolygon:] = \ self.polygonNumberOfItems[whichPolygon+1:] self.polygonsX = newPolygonsX self.polygonsY = newPolygonsY self.polygonBeginningsIndex = newPolygonBeginningsIndex self.polygonNumberOfItems = newPolygonNumberOfItems return 1
def removePolygon(self,x,y): """ Removes the polygon that fills the coordinate x, y If there are multiple polygons, the polygon with the lowest index (first polygon in the list) is returned. Returns 1 if a polygon was acutally removed. 0 is returned otherwise. """ whichPolygon = insideWhichPolygon(self.polygonsX,self.polygonsY, self.polygonBeginningsIndex,self.polygonNumberOfItems,x,y) # No polygon to delete, so do nothing if whichPolygon == -1: return 0 index = self.polygonBeginningsIndex[whichPolygon] numberOfItems = self.polygonNumberOfItems[whichPolygon] oldSize = self.polygonsX.shape[0] newSize = oldSize - numberOfItems newPolygonsX = Numeric.zeros( (newSize,) ,Numeric.Float) newPolygonsY = Numeric.zeros( (newSize,) ,Numeric.Float) # remove the offending polygon newPolygonsX[0:index] = self.polygonsX[0:index] newPolygonsX[index:] = self.polygonsX[index+numberOfItems:] newPolygonsY[0:index] = self.polygonsY[0:index] newPolygonsY[index:] = self.polygonsY[index+numberOfItems:] oldNumberOfPolygons = self.polygonNumberOfItems.shape[0] newNumberOfPolygons = oldNumberOfPolygons-1 newPolygonBeginningsIndex = Numeric.zeros( (newNumberOfPolygons,) ,Numeric.Int) newPolygonNumberOfItems = Numeric.zeros( (newNumberOfPolygons,) ,Numeric.Int) newPolygonBeginningsIndex[0:whichPolygon] = \ self.polygonBeginningsIndex[0:whichPolygon] # note that the indicies of the items after the offending # polygon need to be modified to affect the new array newPolygonBeginningsIndex[whichPolygon:] = \ (self.polygonBeginningsIndex[whichPolygon+1:]-numberOfItems) newPolygonNumberOfItems[0:whichPolygon] = \ self.polygonNumberOfItems[0:whichPolygon] newPolygonNumberOfItems[whichPolygon:] = \ self.polygonNumberOfItems[whichPolygon+1:] self.polygonsX = newPolygonsX self.polygonsY = newPolygonsY self.polygonBeginningsIndex = newPolygonBeginningsIndex self.polygonNumberOfItems = newPolygonNumberOfItems return 1