from bridges.bst_element import *
##
 #  @brief The This class can be used to create K-d Tree  elements, derived
 #  from BSTElement. K-D trees can be thought of as the spatial equivalent
 #  binary search trees and operate on multiple dimensions (2D and 3D are
 #  most common). These trees serve as a representation of the underlying
 #  geometrically defined spaces. Specialized versions of these trees
 #  include quadtrees and octrees, which subdivide into equal sized quadrants
 #  octants at each level, respectively.
 #  This class extends the BSTElement class by adding a dimension property.
 #  It also includes a thickness property for displaying the partitioning
 #  lines generated by the convex decomposition.
 #
 #  convenient to generate visual representation
 #  to allow for use in a binary search tree implementation.
 #
 # @author Kalpathi Subramanian
 # @date 12/26/18
 #

class KDTreeElement(BSTElement):

    ##
    # Constructs a KdTreeElement wit the provided value, label, key,
    # left and right KdTree elements. The defaults will be used if
    # not provided
    #
    # @param key The key for the ordering
    # @param val The Data to hold
    # @param lab the label to show
    # @param left The left KdTree Element
    # @param right the right KdTree element
    #
    def __init__(self, key = None, dim = None, th = None, left = None, right = None, val = None, lab = None):
        if key is not None and dim is not None and th is not None and left is not None and right is not None and val is not None:
            super(KDTreeElement, self).__init__(e = val, left = left, right = right)
            self.thickness = th
            self.dimension = dim
            self.set_key(key)
        elif key is not None and val is not None and left is not None and right is not None:
            super(KDTreeElement, self).__init__(e = val, left=left, right=right)
            self.thickness = 0.0
            self.dimension = 0
            self.set_key(key)
        elif val is not None and left is not None and right is not None:
            super(KDTreeElement, self).__init__(e = val, left=left, right=right)
            self.thickness = 0.0
            self.dimension = 0
        elif left is not None and right is not None:
            super(KDTreeElement, self).__init__(left=left, right=right)
        elif key is not None and dim is not None:
            super(KDTreeElement, self).__init__()
            self.dimension = dim
            self.thickness = 0.0
            self.set_key(key)
        elif key is not None and val is not None:
            super(KDTreeElement, self).__init__(e = val)
            self.set_key(key)
        elif key is not None and val is not None and lab is not None:
            super(KDTreeElement, self).__init__(e = val, label = lab)
            self.set_key(key)
        elif lab is not None and val is not None:
            super(KDTreeElement, self).__init__(e = val, label = lab)
        elif val is not None:
            super(KDTreeElement, self).__init__(e = val)
        else:
            super(KDTreeElement, self).__init__()
            self.thickness = 0.0
            self.dimension = 0


    def get_data_structure_type(self):
        return "KDTree"

    def get_dimension(self):
        return self.dimension

    def set_dimension(self, dim):
        self.dimension = dim

    def get_thickness(self):
        return self.thickness

    def set_thickness(self, th):
        self.thickness = th

    def get_left(self):
        return super(KDTreeElement, self).get_left()

    def get_right(self):
        return super(KDTreeElement, self).get_right()

