#!/usr/bin/python # -*- coding: utf-8 -*- import math class Vec2D: def __init__(self, x, y): self.x = x self.y = y def __add__(self, other): return Vec2D(self.x + other.x, self.y + other.y) def __sub__(self, other): return Vec2D(self.x - other.x, self.y - other.y) def __mul__(self, other): return self.x * other.x + self.y * other.y def __eq__(self, other): return self.x == other.x and self.y == other.y def __str__(self): return "(%g, %g)" % (self.x, self.y) def __abs__(self): return math.sqrt(self.x**2 + self.y**2) def __ne__(self, other): return not self.__eq__(other) # reuse __eq__