from weakref import ref

class TreeElement(object):
    
    root = False
    leaf = False
    node = False

    sub_box0 = None
    sub_box1 = None
    sub_box2 = None
    sub_box3 = None
    sub_box4 = None
    sub_box5 = None
    sub_box6 = None
    sub_box7 = None

    parent = None

    def __init__(self, points, max_child=8):

        self.max_child = max_child

        x0 = points[0][0]
        y0 = points[0][1]
        z0 = points[0][2]
        
        self.x_min = x0
        self.x_max = x0
        self.y_min = y0
        self.y_max = y0
        self.z_min = z0
        self.z_max = z0

        for point in points:
            if point[0] < self.x_min: self.x_min = point[0]
            if point[0] > self.x_max: self.x_max = point[0]
            if point[1] < self.y_min: self.y_min = point[1]
            if point[1] > self.y_max: self.y_max = point[1]
            if point[2] < self.z_min: self.z_min = point[2]
            if point[2] > self.z_max: self.z_max = point[2]

    def isContained(self, point):
        if point[0] < sel.x_min or point[0] > self.x_max: return False
        if point[1] < sel.y_min or point[1] > self.y_max: return False
        if point[2] < sel.z_min or point[2] > self.z_max: return False
        return True

    def __str__(self):
        output = str()
        output += "[X]> %+.3f === %+.3f <\n" % (self.x_min, self. x_max)
        output += "[Y]> %+.3f === %+.3f <\n" % (self.y_min, self. y_max)
        output += "[Z]> %+.3f === %+.3f <\n" % (self.z_min, self. z_max)

        return output

    def add(self):
        pass

if __name__ == "__main__":

    points = [ [1,1,0], [1,1,0], [2,0,0], [3,10,0],
               [4,4,0], [5,0,0], [10,0,0], [-1,-4,0] ]

    a = TreeElement(points)
    print a
