This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/cutcraft/core/point.py
2020-07-31 13:46:07 +02:00

66 lines
1.9 KiB
Python

# -*- 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 <http://www.gnu.org/licenses/>.
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) + ")"