Grid.isWithinBoundaries(): allow for boundary padding

This commit is contained in:
Stefan Harmuth 2023-12-14 09:55:51 +01:00
parent c4b9b10b71
commit f22c3bd798

View File

@ -204,15 +204,18 @@ class Grid:
def isCorner(self, pos: Coordinate) -> bool: def isCorner(self, pos: Coordinate) -> bool:
return pos in self.getCorners() return pos in self.getCorners()
def isWithinBoundaries(self, pos: Coordinate) -> bool: def isWithinBoundaries(self, pos: Coordinate, pad: int = 0) -> bool:
if self.mode3D: if self.mode3D:
return ( return (
self.minX <= pos.x <= self.maxX self.minX + pad <= pos.x <= self.maxX - pad
and self.minY <= pos.y <= self.maxY and self.minY + pad <= pos.y <= self.maxY - pad
and self.minZ <= pos.z <= self.maxZ and self.minZ + pad <= pos.z <= self.maxZ - pad
) )
else: else:
return self.minX <= pos.x <= self.maxX and self.minY <= pos.y <= self.maxY return (
self.minX + pad <= pos.x <= self.maxX - pad
and self.minY + pad <= pos.y <= self.maxY - pad
)
def getActiveCells( def getActiveCells(
self, x: int = None, y: int = None, z: int = None self, x: int = None, y: int = None, z: int = None