waaaay better circles - also for 3d coords

This commit is contained in:
Stefan Harmuth 2022-08-14 13:38:41 +02:00
parent 3c5e27cf36
commit 8e0b28159f

View File

@ -1,11 +1,10 @@
from __future__ import annotations
from dataclasses import dataclass
from enum import Enum
from math import gcd, sqrt, inf, atan2, degrees, floor
from math import gcd, sqrt, inf, atan2, degrees
from .math import round_half_up
from typing import Union, List, Optional
from tools.math import round_half_up
class DistanceAlgorithm(Enum):
MANHATTAN = 0
@ -70,7 +69,6 @@ class Coordinate:
def getCircle(self, radius: int = 1, algorithm: DistanceAlgorithm = DistanceAlgorithm.EUCLIDEAN,
minX: int = -inf, minY: int = -inf, maxX: int = inf, maxY: int = inf,
minZ: int = -inf, maxZ: int = inf) -> list[Coordinate]:
# FIXME: includeDiagonal == True returns way too few coordinates
ret = []
if self.z is None: # mode 2D
for x in range(self.x - radius * 2, self.x + radius * 2 + 1):
@ -89,7 +87,7 @@ class Coordinate:
target = Coordinate(x, y)
if not target.inBoundaries(minX, minY, maxX, maxY, minZ, maxZ):
continue
dist = self.getDistanceTo(target, DistanceAlgorithm.MANHATTAN, includeDiagonals=includeDiagonal)
dist = round_half_up(self.getDistanceTo(target, algorithm=algorithm, includeDiagonals=False))
if dist == radius:
ret.append(target)