nontree.NonTree

class NonTree:

A class for efficient collision detection of points in a sparse 2D plane.
Based on the well known Quadtree data structure.
This is a variant that splits each plane into 9 sub-trees in a 3 by 3 grid.

NonTree(rect, lvl=None, bucket=20)
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
Raises
  • ValueError: If lvl, bucket is out of bounds.
def add(self, point):

Adds a point to the tree.

Parameters
  • point: A point in the shape of (x, y).
def discard(self, point):

Removes a point from the tree.

Parameters
  • point: A data point in the shape of (x, y).
def get_encompassed(self):

Gets all points that are within the tree.

Returns

A list of points in the shape of (x, y).

def get_rect(self, rect):

Gets all points that are within a rectangle.

Parameters
  • rect: A rectangle in shape of (x, y, width, height).
Returns

A list of points in the shape of (x, y).

def get_circle(self, circ):

Gets all points that are within a circle.

Parameters
  • circ: A circle in the shape of (x, y, radius).
Returns

A list of points in the shape of (x, y).

def get_point(self, point):

Gets point if it is in the tree.

Parameters
  • point: A point in the shape of (x, y).
Returns

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

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_encompassed(self):

Deletes all points that are within the tree.

Returns

A list of deleted points.

def del_rect(self, rect):

Deletes points within a rectangle.

Parameters
  • rect: A rectangle in shape of (x, y, width, height).
Returns

A list of deleted points.

def del_circle(self, circ):

Deletes points within a circle.

Parameters
  • circ: A circle in the shape of (x, y, radius).
Returns

A list of deleted points.

def del_point(self, point):

Deletes a point from the tree.

Parameters
  • point: A point in the shape of (x, y).
Returns

A list of deleted point.

def prune(self):

Prunes empty sub-trees.

@staticmethod
def encompass_rectrect(rect, other_rect):

Test if rectangle encompasses rectangle.

Parameters
  • rect: A rectangle in shape of (x, y, width, height).
  • other_rect: A rectangle in shape of (x, y, width, height).
Returns

True if rect encompasses other_rect, False if not.

@staticmethod
def collide_rectpoint(rect, point):

Test collision between rectangle and point.

Parameters
  • rect: A rectangle in shape of (x, y, width, height).
  • point: A point in the shape of (x, y).
Returns

True if collision, False if not.

@staticmethod
def collide_rectrect(rect, other_rect):

Test collision between rectangle and rectangle.

Parameters
  • rect: A rectangle in shape of (x, y, width, height).
  • other_rect: A rectangle in shape of (x, y, width, height).
Returns

True if collision, False if not.

@staticmethod
def encompass_circlerect(circ, rect):

Test if circle encompasses rectangle.

Parameters
  • circ: A circle in the shape of (x, y, radius).
  • rect: A rectangle in shape of (x, y, width, height).
Returns

True if circ encompasses rect, False if not.

@staticmethod
def collide_rectcircle(rect, circ):

Test collision between rectangle and circle.

Parameters
  • rect: A rectangle in shape of (x, y, width, height).
  • circ: A circle in the shape of (x, y, radius).
Returns

True if collision, False if not.

@staticmethod
def collide_circlepoint(circ, point):

Test collision between circle and point.

Parameters
  • circ: A circle in the shape of (x, y, radius).
  • point: A point in the shape of (x, y).
Returns

True if collision, False if not.