~obeancomputer/pyquad

8a845e8dcbca71dc2ea389dd623ac8bdf98fd8a6 — ocsmit 1 year, 10 months ago 2099a21
Remove uneeded file
1 files changed, 0 insertions(+), 72 deletions(-)

D pyquad/base_quadtree.py
D pyquad/base_quadtree.py => pyquad/base_quadtree.py +0 -72
@@ 1,72 0,0 @@
from __future__ import annotations
from typing import TYPE_CHECKING, List


from matplotlib.axes._axes import Axes as MplAxes

if TYPE_CHECKING or __package__:
    from .geometry_objects import BoundingBox, Point
else:
    from geometry_objects import BoundingBox, Point


###############################################################################
# Point quadtree


class QuadTree:
    def __init__(
        self,
        bounding_box: BoundingBox,
        # points: List[Point],
        depth: int = 0,
    ):

        self.bounding_box = bounding_box
        self.depth = depth
        self.children = 0
        self.variance = None

        self.points: List[Point] = []
        # self.points_num = 0 if points is None else len(points)

        self._divided = False

    def divide(self) -> None:

        tiles = self.bounding_box.split()
        depth = self.depth + 1
        self.nw = QuadTree(tiles.nw, depth=depth)
        self.ne = QuadTree(tiles.ne, depth=depth)
        self.se = QuadTree(tiles.se, depth=depth)
        self.sw = QuadTree(tiles.sw, depth=depth)

        self._divided = True

    def __str__(self) -> str:
        sp = " " * self.depth * 2
        s = str(self.bounding_box) + "\n"
        s += sp + ", ".join(str(point) for point in self.points)
        if not self._divided:
            return s
        return (
            s
            + "\n"
            + "\n".join(
                [
                    sp + "nw: " + str(self.nw),
                    sp + "ne: " + str(self.ne),
                    sp + "se: " + str(self.se),
                    sp + "sw: " + str(self.sw),
                ]
            )
        )

    def draw(self, ax: MplAxes) -> None:

        self.bounding_box.draw(ax)
        if self._divided:
            self.nw.draw(ax)
            self.ne.draw(ax)
            self.se.draw(ax)
            self.sw.draw(ax)