def __init__(self, items=None, depth=8, bounding_rect=None):
        """Creates a quad-tree.

        @param items:
            A sequence of items to store in the quad-tree.
            Note that these items must be of SimObject.

        @param depth:
            The maximum recursion depth.

        @param bounding_rect:
            The bounding rectangle of all of the items in the quad-tree.
            Type of Rect or (x,y,w,h) of the rectangle
            For internal use only.
        """

        # The sub-quadrants are empty to start with.
        self.nw = self.ne = self.se = self.sw = None
        self.depth = depth

        # Find this quadrant's centre.
        if bounding_rect:
            bounding_rect = Rect(bounding_rect)
        else:
            # If there isn't a bounding rect, then calculate it from the items.
            if items:
                bounding_rect = Rect(items[0].get_bounding_rect())
                for item in items[1:]:
                    bounding_rect.add(Rect(item.get_bounding_rect()))
            else:
                # in case there are no items, assume a big rect (100x100
                # meters)
                bounding_rect = Rect((0.0, 0.0, 100.0, 100.0))

        self.rect = bounding_rect
        self.items = []

        # Insert items
        self.insert_items(items)
Beispiel #2
0
    def __init__(self, items=None, depth=8, bounding_rect=None):
        """Creates a quad-tree.
 
        @param items:
            A sequence of items to store in the quad-tree.
            Note that these items must be of SimObject.
            
        @param depth:
            The maximum recursion depth.
            
        @param bounding_rect:
            The bounding rectangle of all of the items in the quad-tree.
            Type of Rect or (x,y,w,h) of the rectangle
            For internal use only.
        """

        # The sub-quadrants are empty to start with.
        self.nw = self.ne = self.se = self.sw = None
        self.depth = depth

        # Find this quadrant's centre.
        if bounding_rect:
            bounding_rect = Rect(bounding_rect)
        else:
            # If there isn't a bounding rect, then calculate it from the items.
            if items:
                bounding_rect = Rect(items[0].get_bounding_rect())
                for item in items[1:]:
                    bounding_rect.add(Rect(item.get_bounding_rect()))
            else:
                # in case there are no items, assume a big rect (100x100 meters)
                bounding_rect = Rect((0.0, 0.0, 100.0, 100.0))

        self.rect = bounding_rect
        self.items = []

        # Insert items
        self.insert_items(items)