class Vector2D(EUDStruct):
_fields_ = ['x', 'y']
def __init__(self, x=None, y=None):
if y is None:
super().__init__(x)
else:
super().__init__([x, y])
def lengthsq(self):
return self.x * self.x + self.y * self.y
def length(self):
return f_sqrt(self.lengthsq())
def dot(self, rhs):
return self.x * rhs.x + self.y * rhs.y
# Operator support
def add(self, rhs):
t = self.clone()
t += rhs
return t
def sub(self, rhs):
t = self.clone()
t -= rhs
return t
def mul(self, rhs):
t = self.clone()
t *= rhs
return t
def div(self, rhs):
t = self.clone()
t //= rhs
return t
def __iadd__(self, rhs):
self.x += rhs.x
self.y += rhs.y
return self
def __isub__(self, rhs):
self.x -= rhs.x
self.y -= rhs.y
return self
def __imul__(self, rhs):
self.x *= rhs
self.y *= rhs
return self
def __ifloordiv__(self, rhs):
if EUDIf()(self.x >= 0x80000000):
self.x = -(-self.x // rhs)
if EUDElse()():
self.x //= rhs
EUDEndIf()
if EUDIf()(self.y >= 0x80000000):
self.y = -(-self.y // rhs)
if EUDElse()():
self.y //= rhs
EUDEndIf()
return self