I applied the group loading method of the dot quadrant. But for some inputs, this does not work correctly, for example, if there are many points that have the same x or y coordinate. Sample data set:
test = [(3, 1), (16, 1), (11, 4), (5, 4), (9, 6), (5, 10), (1, 15), (11, 5), (11, 15), (12, 16), (19, 17)] tree = create(test)
The problem arises at the points: (11,4),(11,5),(11,15) and (5,10),(5,4) .
This is the create function:
def create(point_list, presorted=False): if not point_list: return QuadNode() if not presorted: point_list.sort(key=lambda p: [p[0],p[1]]) median = len(point_list) >> 1 relevantPoint = point_list[median] relevantYCoordinate = relevantPoint[1] node = QuadNode(data=relevantPoint) leftBins = point_list[:median] rightBins = point_list[median + 1:] nwBins = [bin for bin in leftBins if bin[1] >= relevantYCoordinate] swBins = [bin for bin in leftBins if bin[1] < relevantYCoordinate] neBins = [bin for bin in rightBins if bin[1] >= relevantYCoordinate] seBins = [bin for bin in rightBins if bin[1] < relevantYCoordinate] node.nwNode = create(nwBins, presorted=True) node.swNode = create(swBins, presorted=True) node.neNode = create(neBins, presorted=True) node.seNode = create(seBins, presorted=True) return node
and QuadNode :
class QuadNode(object): def __init__(self, data=None, nwNode=None, neNode=None, swNode=None, seNode=None): self.data = data self.nwNode = nwNode self.neNode = neNode self.swNode = swNode self.seNode = seNode
I want to follow the rule for insert, delete, etc .:
swNode point.x < parent.x and point.y < parent.yseNode point.x >= parent.x and point.y < parent.ynwNode point.x < parent.x and point.y >= parent.yneNode point.x >= parent.x and point.y >= parent.y