From f2b5a32b353bb3b6e693add9926df6565532d1e0 Mon Sep 17 00:00:00 2001 From: adrienmalin <41926238+adrienmalin@users.noreply.github.com> Date: Mon, 6 Aug 2018 21:02:27 +0200 Subject: [PATCH] Revert "move rotate to top" This reverts commit 9d0f2392caaa70d285d7e071fe97d3b7ef1ef77a. --- point.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 point.py diff --git a/point.py b/point.py new file mode 100644 index 0000000..9e23b56 --- /dev/null +++ b/point.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + + +from consts import CLOCKWISE +from qt5 import QtCore + +class Point(QtCore.QPoint): + """ + Point of coordinates (x, y) + """ + + def __add__(self, o): + return Point(self.x() + o.x(), self.y() + o.y()) + + def __sub__(self, o): + return Point(self.x() - o.x(), self.y() - o.y()) + + def __mul__(self, k): + return Point(k * self.x(), k * self.y()) + + def __truediv__(self, k): + return Point(self.x() / k, self.y() / k) + + __radd__ = __add__ + __rsub__ = __sub__ + __rmul__ = __mul__ + __rtruediv__ = __truediv__ + + def rotate(self, center, direction=CLOCKWISE): + """ Returns the Point image of the rotation of self + through 90° CLOKWISE or COUNTERCLOCKWISE around center""" + if self == center: + return self + + p = self - center + p = Point(-direction * p.y(), direction * p.x()) + p += center + return p + + def __repr__(self): + return "Point({}, {})".format(self.x(), self.y()) + + __str__ = __repr__ \ No newline at end of file