# -*- python -*-

import copy
import math

class Point:
    def translate(self, x):
        p = copy.copy(self)
        p.x += x
        return p


class Point2d(Point):
    def __init__(self, x, y):
        self.x, self.y = x, y

    def length(self):
        return math.sqrt(self.x * self.x + self.y * self.y)

    def __repr__(self):
        return "[%g, %g]" % (self.x, self.y)

class Point3d(Point):
    def __init__(self, x, y, z):
        self.x, self.y, self.z = x, y, z

    def length(self):
        return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)

    def __repr__(self):
        return "[%g, %g, %g]" % (self.x, self.y, self.z)

p2d = Point2d(3, 4)
p3d = Point3d(1, 2, 2)

l = [ p2d, p3d ]

def test(p):
    return p.length(), p.translate(1)

print test(p2d), test(p3d), map(lambda self: self.length(), l)

# after translate, we still have a Point3d
print p3d.translate(1).z, "\n"
