made Position more correct
This commit is contained in:
parent
b8562d49b5
commit
6a5e5d3137
1 changed files with 12 additions and 6 deletions
|
|
@ -22,22 +22,28 @@ class Position:
|
|||
match direction:
|
||||
case Position(x, y):
|
||||
return self.__class__(self.x + x, self.y + y)
|
||||
x, y = direction
|
||||
case (x, y):
|
||||
return self.__class__(self.x + x, self.y + y)
|
||||
raise NotImplementedError
|
||||
|
||||
def __sub__(self, direction: tuple[int, int] | Position) -> Self:
|
||||
match direction:
|
||||
case Position(x, y):
|
||||
return self.__class__(self.x - x, self.y - y)
|
||||
x, y = direction
|
||||
case (x, y):
|
||||
return self.__class__(self.x - x, self.y - y)
|
||||
raise NotImplementedError
|
||||
|
||||
def mod(self, other: tuple[int,int] | Position | int) -> Self:
|
||||
match other:
|
||||
case Position(x,y):
|
||||
return self.__class__(self.x//x, self.y//y)
|
||||
case int(x):
|
||||
return self.__class__(self.x//x, self.y//x)
|
||||
x,y = other
|
||||
case (x, y):
|
||||
return self.__class__(self.x//x, self.y//y)
|
||||
raise NotImplementedError
|
||||
|
||||
def length(self):
|
||||
return math.sqrt(self.x**2+self.y**2)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue