# -*- coding: utf-8 -*- # Copyright (C) 2018 Michael Matthews # # This file is part of CutCraft. # # CutCraft is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # CutCraft is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with CutCraft. If not, see . from math import sqrt class Point(object): """ Point (x,y) class suppporting addition for offsets. """ def __init__(self, x, y): self.x = x self.y = y def distance(self, other): """ Distance between two points. """ x = self.x - other.x y = self.y - other.y return sqrt(x*x+y*y) def tup(self): return (self.x, self.y) def __eq__(self, other): return (self.x == other.x and self.y == other.y) def __ne__(self, other): return (self.x != other.x or self.y != other.y) def __add__(self, other): return Point(self.x + other.x, self.y + other.y) def __iadd__(self, other): self.x += other.x self.y += other.y return self def __sub__(self, other): return Point(self.x - other.x, self.y - other.y) def __isub__(self, other): self.x -= other.x self.y -= other.y return self def __neg__(self): return Point(-self.x, -self.y) def __repr__(self): return "Point(" + str(self.x) + ", " + str(self.y) + ")" def __str__(self): return "(" + str(self.x) + ", " + str(self.y) + ")"