nontree.TreeMap API documentation

# nontree.TreeMap

class TreeMap(collections.abc.MutableMapping):

The TreeMap contains a NonTree (or QuadTree, BiTree) and maps its points to payload data.
A single point can map to multiple data objects.
The TreeMap provides methods to make use of the underlying NonTree (or QuadTree, BiTree).
It also provides a dict-ish interface.

TreeMap(rect, lvl=None, bucket=20, mode=9, initial_dict=None)

###### Parameters

- rect: A rectangle in the shape of (x, y, width, height).
- lvl: Maximum nesting depth. None for automatic heuristic value. >= 0
- bucket: Maximum number of points in a tree, before it is split into subtrees. >= 1
- mode: Number of subtrees a tree is split into. 9: NonTree, 4: QuadTree, 2: BiTree
- initial_dict: A dict with points (x, y) as keys and lists of objects as values for initial filling.

###### Raises

- ValueError: If lvl, bucket, mode is out of bounds.

def keys(self):

D.keys() -> a set-like object providing a view on D's keys

def clear(self):

D.clear() -> None. Remove all items from D.

def copy(self):

Copies this TreeMap.

###### Returns

> A shallow copy of this TreeMap.

def get_rect(self, rect):

Gets payload data of all points that are within a rectangle.

###### Parameters

- rect: A rectangle in shape of (x, y, width, height).

###### Returns

> A list of objects.

def get_circle(self, circ):

Gets payload data of all points that are within a circle.

###### Parameters

- circ: A circle in the shape of (x, y, radius).

###### Returns

> A list of objects.

def get_point(self, point):

Gets payload data of point if it is in the tree.

###### Parameters

- point: A point in the shape of (x, y).

###### Returns

> A list of objects.

def test_rect(self, rect):

Tests if there are points within a rectangle.

###### Parameters

- rect: A rectangle in shape of (x, y, width, height).

###### Returns

> True if there are points within the rectangle, False if not.

def test_circle(self, circ):

Tests if there are points within a circle.

###### Parameters

- circ: A circle in the shape of (x, y, radius).

###### Returns

> True if there are points within the circle, False if not.

def test_point(self, point):

Tests if point is in the tree.

###### Parameters

- point: A point in the shape of (x, y).

###### Returns

> True if point is in the tree, False if not.

def del_rect(self, rect):

Deletes points within a rectangle.

###### Parameters

- rect: A rectangle in shape of (x, y, width, height).

###### Returns

> True if there have been points to delete, False if not.

def del_circle(self, circ):

Deletes points within a circle.

###### Parameters

- circ: A circle in the shape of (x, y, radius).

###### Returns

> True if there have been points to delete, False if not.

def del_point(self, point):

Deletes a point from the tree.

###### Parameters

- point: A point in the shape of (x, y).

###### Returns

> True if there has been a point to delete, False if not.

def pop_point(self, point, default=Ellipsis):

Pops a point from the tree and returns its payload data.

###### Parameters

- point: A point in the shape of (x, y).
- default: Optional default value if point is not in tree.

###### Returns

> A list of objects.

###### Raises

- KeyError: If point is not in the tree, and no default is given.

def add(self, point, value):

Adds payload data to a point in the tree. Also adds the point itself to the tree, if not yet existing.

###### Parameters

- point: A point in the shape of (x, y).
- value: An object.

def add_datapoints(self, datapoints):

Adds points with payload data to the tree.

###### Parameters

- datapoints: An iterable of datapoints in the shape of ((x, y), value).

def extend(self, extend_dict):

Extends this tree with points and payload data from a dictionary.

###### Parameters

- extend_dict: A dict with points (x, y) as keys and lists of objects as values.

def discard(self, point, value):

Discards a payload value from a point in the tree. Also deletes the point if it has no payload values left.

###### Parameters

- point: A point in the shape of (x, y).
- value: An object.

def discard_datapoints(self, datapoints):

Discards datapoints from the tree.

###### Parameters

- datapoints: An iterable of datapoints in the shape of ((x, y), value).

def datapoints(self):

An iterator over all datapoints in the tree. Datapoint shape: ((x, y), value)

def data(self):

An iterator over all payload data in the tree.

def prune(self):

Prunes empty sub-trees.

##### Inherited Members

collections.abc.MutableMapping
  pop
  popitem
  update
  setdefault
collections.abc.Mapping
  get
  items
  values