Changeset 558

Show
Ignore:
Timestamp:
05/06/08 12:32:07 (7 months ago)
Author:
migurski
Message:

Using self.class to be more friendly to subclasses

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/py/ModestMaps/Core.py

    r317 r558  
    4242     
    4343class Coordinate: 
    44     MAX_ZOOM = 20 
     44    MAX_ZOOM = 25 
    4545 
    4646    def __init__(self, row, column, zoom): 
     
    5353         
    5454    def copy(self): 
    55         return Coordinate(self.row, self.column, self.zoom) 
     55        return self.__class__(self.row, self.column, self.zoom) 
    5656         
    5757    def container(self): 
    58         return Coordinate(math.floor(self.row), math.floor(self.column), self.zoom) 
     58        return self.__class__(math.floor(self.row), math.floor(self.column), self.zoom) 
    5959 
    6060    def zoomTo(self, destination): 
    61         return Coordinate(self.row * math.pow(2, destination - self.zoom), 
    62                           self.column * math.pow(2, destination - self.zoom), 
    63                           destination) 
     61        return self.__class__(self.row * math.pow(2, destination - self.zoom), 
     62                              self.column * math.pow(2, destination - self.zoom), 
     63                              destination) 
    6464     
    6565    def zoomBy(self, distance): 
    66         return Coordinate(self.row * math.pow(2, distance), 
    67                           self.column * math.pow(2, distance), 
    68                           self.zoom + distance) 
     66        return self.__class__(self.row * math.pow(2, distance), 
     67                              self.column * math.pow(2, distance), 
     68                              self.zoom + distance) 
    6969 
    7070    def up(self, distance=1): 
    71         return Coordinate(self.row - distance, self.column, self.zoom) 
     71        return self.__class__(self.row - distance, self.column, self.zoom) 
    7272 
    7373    def right(self, distance=1): 
    74         return Coordinate(self.row, self.column + distance, self.zoom) 
     74        return self.__class__(self.row, self.column + distance, self.zoom) 
    7575 
    7676    def down(self, distance=1): 
    77         return Coordinate(self.row + distance, self.column, self.zoom) 
     77        return self.__class__(self.row + distance, self.column, self.zoom) 
    7878 
    7979    def left(self, distance=1): 
    80         return Coordinate(self.row, self.column - distance, self.zoom) 
     80        return self.__class__(self.row, self.column - distance, self.zoom) 
    8181 
    8282if __name__ == '__main__':