from .elements import gds_layer_element
from ..geometry import size_info
from ..geometry.coord import coord2_property, size2_property

__all__ = ["gds_box_element", "el_box"]

class gds_box_element(gds_layer_element):
    center = coord2_property(default = (0.0, 0.0))
    box_size = size2_property(default = (1.0, 1.0))
    def __init__ (self, layer, center = (0.0,0.0), box_size = (1.0, 1.0), transformation = None, **kwargs):
        super(gds_box_element, self).__init__(layer = layer, transformation = transformation, center = center, box_size = box_size, **kwargs)

    def size_info(self):
        return size_info.gds_size_info ([(self.center[0] - 0.5* self.box_size[0], self.center[1] - 0.5* self.box_size[1]) ,
                      (self.center[0] + 0.5* self.box_size[0], self.center[1] + 0.5* self.box_size[1])])

    def flat_copy(self, level = -1):
        return gds_elementlist(gds_box_element(self.layer, self.center, self.box_size))

    def __copy__(self):
        return gds_box_element(self.layer, self.center, self.box_size, self.transformation)

    def __deepcopy__(self, memo):
        # layer should not be deepcopied!
        return gds_box_element(self.layer, self.center, self.box_size, copy.deepcopy(self.transformation))
    
    def is_empty(self):
        return (self.box_size[0] == 0.0 and self.box_size[1]==0.0)

def el_box(layer, bottom_left = (1.0,1.0), box_size = (1.0, 1.0)):
    center = (bottom_left[0] + 0.5 * box_size[0], bottom_left[1] + 0.5 * box_size[1])
    return gds_box_element(layer, center, box_size)

        