Coordinate: remember the 3rd dimension ...
This commit is contained in:
parent
2b19538fb2
commit
311cb9edba
@ -105,7 +105,7 @@ class Coordinate:
|
||||
def getAngleTo(self, target: Coordinate, normalized: bool = False) -> float:
|
||||
"""normalized returns an angle going clockwise with 0 starting in the 'north'"""
|
||||
if self.z is not None:
|
||||
raise NotImplementedError()
|
||||
raise NotImplementedError() # which angle?!?!
|
||||
|
||||
dx = target.x - self.x
|
||||
dy = target.y - self.y
|
||||
@ -120,11 +120,18 @@ class Coordinate:
|
||||
|
||||
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)]
|
||||
if self.z is None:
|
||||
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)]
|
||||
else:
|
||||
steps = gcd(diff.x, diff.y, diff.z)
|
||||
step_x = diff.x // steps
|
||||
step_y = diff.y // steps
|
||||
step_z = diff.z // steps
|
||||
return [Coordinate(self.x + step_x * i, self.y + step_y * i, self.z + step_z * i) for i in range(steps + 1)]
|
||||
|
||||
def __add__(self, other: Coordinate) -> Coordinate:
|
||||
if self.z is None:
|
||||
@ -139,5 +146,14 @@ class Coordinate:
|
||||
return Coordinate(self.x - other.x, self.y - other.y, self.z - other.z)
|
||||
|
||||
@staticmethod
|
||||
def generate(from_x: int, to_x: int, from_y: int, to_y: int) -> List[Coordinate]:
|
||||
return [Coordinate(x, y) for x in range(from_x, to_x + 1) for y in range(from_y, to_y + 1)]
|
||||
def generate(from_x: int, to_x: int, from_y: int, to_y: int,
|
||||
from_z: int = None, to_z: int = None) -> List[Coordinate]:
|
||||
if from_z is None and to_z is None:
|
||||
return [Coordinate(x, y) for x in range(from_x, to_x + 1) for y in range(from_y, to_y + 1)]
|
||||
else:
|
||||
return [
|
||||
Coordinate(x, y, z)
|
||||
for x in range(from_x, to_x + 1)
|
||||
for y in range(from_y, to_y + 1)
|
||||
for z in range(from_z, to_z + 1)
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user