in graspologic/layouts/nooverlap/_quad_node.py [0:0]
def quad_stats(self) -> Tuple[int, int, int, int, int, float, int]:
square_size = self.total_square_size()
tot_area = total_area(self.min_x, self.min_y, self.max_x, self.max_y)
if tot_area == 0:
tot_area = 0.01
num_quad_no_kids = 0
num_quad_to_dense = 0
num_quad_fits = 0
total_nodes_moved = self.total_nodes_moved
not_first_choice = self.not_first_choice
lowest_level = math.inf
max_nodes_in_grid = 0
has_children = False
for quad in [self.NW, self.NE, self.SW, self.SE]:
if quad:
no_kids, too_dense, fits, tnm, nfc, low_level, mng = quad.quad_stats()
num_quad_no_kids += no_kids
num_quad_to_dense += too_dense
num_quad_fits += fits
total_nodes_moved += tnm
not_first_choice += nfc
has_children = True
lowest_level = min(lowest_level, low_level)
max_nodes_in_grid = max(max_nodes_in_grid, mng)
if not has_children:
num_quad_no_kids += 1
if len(self.nodes) > self.total_cells:
if self.total_cells == 0:
nodes_to_cells = math.inf
else:
nodes_to_cells = len(self.nodes) / self.total_cells
# print ("too dense, nodes/cells: %g, nn: %d, cells: %d, level: %d" %(nodes_to_cells, len(self.nodes), self.total_cells, self.depth))
num_quad_to_dense = 1
lowest_level = math.inf
parent = self.parent
while parent is not None:
max_nodes_in_grid = parent.num_nodes()
lowest_level = parent.depth
if parent.num_nodes() > parent.total_cells:
# doesn't fit, go up one more level
parent = parent.parent
else:
break
else:
# we are at the bottom and we can fit everyone in here.
lowest_level = self.depth
max_nodes_in_grid = self.num_nodes()
num_quad_fits = 1
return (
num_quad_no_kids,
num_quad_to_dense,
num_quad_fits,
total_nodes_moved,
not_first_choice,
lowest_level,
max_nodes_in_grid,
)