<reponame>Safffatttu/PyOsciAudio
import math

class Point:
    
    def __init__(self, x = 0 , y = 0):
        self.x = x
        self.y = y

    def __add__(self, other):
        newX = self.x + other.x
        newY = self.y + other.y
        return Point(newX, newY)

    def __iadd(self, other):
        self.x += other.x
        self.y += other.y

    def distance(self, other):
        dx = self.x - other.x
        dy = self.y - other.y
        return(math.hypot(dx, dy))

    def transition(self, other, proc):
        newX = self.x * ( 1 - proc) + other.x * proc
        newY = self.y * ( 1 - proc) + other.y * proc
        return Point(newX, newY)

    def rotateByAngle(self, byAngle, center = None):
        if center is None:
            center = Point(0,0)
        
        rad = math.radians(byAngle)
        dx = self.x - center.x
        dy = self.y - center.y

        lengh = math.hypot(dx, dy)

        angle = math.atan2(self.x,  self.y)
        newAngle = angle + rad

        newDx = lengh * math.sin(newAngle)
        newDy = lengh * math.cos(newAngle)

        newX = newDx + center.x
        newY = newDy + center.y

        return Point(newX, newY)

    def moveBy(self, x, y):
        newX = self.x
        newY = self.y

        return Point(newX, newY)


    def scaleBy(self, scale, center = None):
        if center is None:
            center = Point(0,0)

        dx = self.x - center.x
        dy = self.y - center.y
        lengh = math.hypot(dx, dy)
        newLengh = lengh * scale

        angle = math.atan2(self.x, self.y)

        newDx = newLengh * math.sin(angle)
        newDy = newLengh * math.cos(angle)

        newX = newDx + center.x
        newY = newDy + center.y

        return Point(newX, newY)
        