from prototype import ProtoMeta __metaclass__ = ProtoMeta class origin: x = 0 y = 0 def distance(self, other): return ((self.x - other.x) ** 2 + (self.y - other.y) ** 2) ** 0.5 def newpoint(self, x, y): result = self.clone() result.x = x result.y = y return result def dist_to_origin(self): return origin.distance(self) def add(self, other): return self.newpoint(self.x + other.x, self.y + other.y) def test_distance(): p1 = origin.newpoint(3, 4) assert origin.distance(p1) == 5 class point_trait: def distance(self, other): return ((self.x - other.x) ** 2 + (self.y - other.y) ** 2) ** 0.5 def newpoint(self, x, y): result = self.clone() result.x = x result.y = y return result def dist_to_origin(self): return origin.distance(self) def add(self, other): return self.newpoint(self.x + other.x, self.y + other.y) class origin: parent = point_trait x = 0 y = 0 class polygon_trait: def new(self, pointlist): result = self.clone() result.vertices = pointlist return result def circumference(self): vertices = self.vertices last = vertices[-1] result = 0 for vertex in vertices: result += last.distance(vertex) last = vertex return result empty_polygon = polygon_trait.new([])