Next / Previous / Contents / Shipman's homepage

56. Slot.__getitem__(): Slot position to puzzle position

kkck
# - - -   S l o t . _ _ g e t i t e m _ _

    def __getitem__ ( self, k ):
        '''Return the coord of the [k]th character of this slot.
        '''

There are two cases:

Assuming that self.isV is either 0 or 1, then perpendicutal(self.isV) is 0 for horizontal, 1 for vertical; see Section 12, “perpendicular(): Return the opposite orientation”. This transform allows us to generalize the logic to a single case.

kkck
        #-- 1 --
        # [ if self.isV is 0 ->
        #     return Coord ( self.origin[0]+k, self.origin[1] )
        #   else if self.isV is 1 ->
        #     return Coord ( self.origin[0], self.origin[1]+k ) ]
        return Coord ( self.origin[0] + k*self.isV,
                       self.origin[1] + k*perpendicular(self.isV) )