from .special import gds_special_no_distort_transform
from .no_distort import gds_no_distort_transform
from .translation import gds_translation
from .rotation import gds_rotation
from .magnification import gds_magnification
from ..coord import coord2
from types import NoneType

__all__ = ["gds_identity_transform"]


class gds_identity_transform(gds_translation, gds_rotation, gds_magnification, gds_special_no_distort_transform ):
    """ transform that leaves an object unchanged """
    def __init__(self, **kwargs):
        super(gds_identity_transform, self).__init__(
            magnification_center = (0.0, 0.0),
            rotation_center = (0.0, 0.0),
            **kwargs)
    
    def apply(self, item):
        
        if isinstance(item, list):
            return shape.gds_shape(item)
        else:
            return item
            
    def reverse(self, shape):
        if isinstance(item, list):
            return shape.gds_shape(item)
        else:
            return item

    def apply_to_coord(self, coord):
        """ apply transformation to coordinate """
        return coord

    def reverse_on_coord(self, coord):
        """ apply reverse transformation to coordinate """
        return coord

    def apply_to_array(self, coords):
        """ apply transformation to numpy array"""
        return coords

    def reverse_on_array(self, coords):
        """ internal use: applies reverse transformation to a numpy array """
        return coords

    def __neg__(self):
        return gds_identity_transform()

    def __add__(self, other):
        """ returns the concatenation of this transform and other """
        if isinstance(other, (NoneType, gds_identity_transform)):
            return gds_identity_transform()
        elif isinstance(other, gds_translation):
            return gds_translation(other.translation)
        elif isinstance(other, gds_rotation):
            return gds_rotation(other.rotation_center, other.rotation, other.absolute_rotation)
        elif isinstance(other, gds_magnification):
            return gds_magnification(other.magnification_center, other.magnification, other.absolute_magnfication)
        else:
            return gds_special_no_distort_transform.__add__(self, other)
    
    def __iadd__(self, other):
        """ concatenates other to this transform """
        if isinstance(other, (NoneType, gds_identity_transform)):
            return self
        else:
            return gds_special_no_distort_transform.__iadd__(self, other)

    def is_identity(self):
        """ returns True if the transformation does nothing """
        return True
