from math import sqrt
from multipledispatch import dispatch

class PointXY():
        def distance_from_zero(point):
            return sqrt( point.x ** 2 + point.y ** 2 )

        def distance_to(self, point):
            return sqrt( (point.x - self.x) ** 2 + (point.y - self.y) ** 2)

        def if_inside(self, r):
            if (r.a.x <= self.x <= r.b.x) and (r.a.y <= self.y <= r.b.y):
                return 'точка внутри прямоуголника'
            else:
                return 'точка вне прямоугольника'

        def __init__(self, x:int, y:int):
            self.x = x
            self.y = y

        def __str__(self):
            return 'x = ' + str(self.x) + ' y = ' + str(self.y)

class Rect():
    def area(self):
        return self.lenght * self.width

    def perimeter(self):
        return (self.lenght + self.width) * 2

    def scale(self, coef):
        self.lenght *= coef
        self.width *= coef

    def rotate(self):
        self.lenght, self.width = self.width, self.lenght

    def has_inside(self, p: PointXY):
        if (self.a.x <= p.x <= self.b.x) and (self.a.y <= p.y <= self.b.y):
            return 'точка внутри прямоуголника'
        else:
            return 'точка вне прямоугольника'

    @dispatch(int, int)
    def __init__(self, x: int, y: int):
        self.lenght = x
        self.width = y

    @dispatch(PointXY, PointXY)
    def __init__(self, a: PointXY, b: PointXY):
        self.a = a
        self.b = b
        self.lenght = sqrt((a.x - a.x) ** 2 + (b.x - a.y) ** 2)
        self.width = sqrt((b.x - a.x) ** 2 + (b.y - b.x) ** 2)

    def __str__(self):
        if str(hasattr(self, 'a')) == 'False':
            return 'x = ' + str(self.lenght) + ' y = ' + str(self.width)
        else:
            return 'x = ' + str(self.lenght) + ' y = ' + str(self.width) + ' a(' + str(self.a.x) + ':' + str(self.a.y) + ')' + ' b(' + str(self.b.x) + ':' + str(self.b.y) + ')'


