Next / Previous / Contents / Shipman's homepage

8.1. Xform.__init__(): Constructor

All we need to do is store the transform matrix in the .__m attribute. The argument may already be a num.array, in which case its type is num.ndarray. Otherwise we will apply the num.array() constructor to it and hope for the best.

homcoord.py
# - - -   X f o r m . _ _ i n i t _ _

    def __init__ ( self, m ):
        '''Constructor.
        '''
        #-- 1 --
        # [ if the type of m is num.ndarray ->
        #     self.__m  :=  m
        #   else if m is acceptable as an argument to
        #   num.array() ->
        #     self.__m  :=  array(m)
        #   else -> raise Exception ]
        if type(m) is num.ndarray:
            self.__m = m
        else:
            self.__m = num.array(m)

The next four attributes are memoized: that is, they are initially set to None, but when callers ask for the computation of the inverse transform (the .inverse() method) or its component parts (the .offset(), .angle(), or .mag() methods), the results are stored so that they need not be recomputed on successive calls.

homcoord.py
        #-- 2 --
        self.__mInverse = None
        self.__offset = self.__angle = self.__mag = None