Coordinate.getLineTo(): return coordinates in a line from self to target
This commit is contained in:
parent
122f1e768e
commit
2b19538fb2
@ -1,9 +1,11 @@
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from math import sqrt, inf, atan2, degrees
|
||||
from math import gcd, sqrt, inf, atan2, degrees
|
||||
from typing import Union, List, Optional
|
||||
|
||||
from tools import compare
|
||||
|
||||
|
||||
class DistanceAlgorithm(Enum):
|
||||
MANHATTAN = 0
|
||||
@ -116,6 +118,14 @@ class Coordinate:
|
||||
else:
|
||||
return 180.0 + abs(angle)
|
||||
|
||||
def getLineTo(self, target: Coordinate) -> List[Coordinate]:
|
||||
diff = target - self
|
||||
steps = gcd(diff.x, diff.y)
|
||||
step_x = diff.x // steps
|
||||
step_y = diff.y // steps
|
||||
|
||||
return [Coordinate(self.x + step_x * i, self.y + step_y * i) for i in range(steps + 1)]
|
||||
|
||||
def __add__(self, other: Coordinate) -> Coordinate:
|
||||
if self.z is None:
|
||||
return Coordinate(self.x + other.x, self.y + other.y)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user