[Tutor] Am I making this harder than it needs to be?

Ron Phillips RPhillips at engineer.co.summit.oh.us
Wed May 25 15:03:27 CEST 2005


short version: I  need a way to get max and min E and N out of
[(E0,N0),(E1,N1)...(En,Nn)] without reordering the list
 
long version:
 
I would like a list of geographic coordinates (Easting, Northing) to
maintain a "bounding box"
[(minEasting,minNorthing),(maxEasting,maxNorthing)] attribute.
 
I did it like this:
 
class geoCoordinateList(UserList):
    def __init__(self):
        UserList.__init__(self)
        self.boundingBox = geoBox(minEN=geoCoordinate(),
                                  maxEN=geoCoordinate())

    def append(self, geoCoord):
        self.extend([geoCoord])
        self.boundingBox.challenge(geoCoord)#bumps the max and min if
necessary

but I'd have to override almost all the UserList methods, unless
there's a way to call boundingBox.challenge() on any change to the
list.
 
The other way I thought would be to make a getBB method, like:
 
    def getBB(self):
        new=geoBox()
        for gC in self:
            new.challenge(gC)#bumps the corners if needed
        self.boundingBox=new
        return(new)

but that seems like a lot of churning if nothing has changed. 
 
I suspect there's some slick, readable way to do this, and when I see
it I'll say "Doh!"
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050525/e0f53d6b/attachment.htm


More information about the Tutor mailing list