gdpc.vector_tools

Various vector utilities.

This module contains, roughly in order:

  • Protocols for vector-like classes.

  • Helpful vector constants.

  • General vector utilities.

  • The Rect and Box classes.

  • Generators for various geometrical shapes.


class Vec2iLike

Protocol for a vector that contains two integers.

A class is a Vec2iLike if it contains two integers, which can be accessed with both indexing and iteration.

__getitem__(_Vec2iLike__i: int) int
__len__() int
__iter__() Iterator[int]
__init__(*args, **kwargs)
class Vec3iLike

Protocol for a vector that contains three integers.

A class is a Vec3iLike if it contains three integers, which can be accessed with both indexing and iteration.

__getitem__(_Vec3iLike__i: int) int
__len__() int
__iter__() Iterator[int]
__init__(*args, **kwargs)
class Vec2bLike

Protocol for a vector that contains two bools.

A class is a Vec2iLike if it contains two bools, which can be accessed with both indexing and iteration.

__getitem__(_Vec2bLike__i: int) bool
__len__() int
__iter__() Iterator[bool]
__init__(*args, **kwargs)
class Vec3bLike

Protocol for a vector that contains three bools.

A class is a Vec3iLike if it contains three bools, which can be accessed with both indexing and iteration.

__getitem__(_Vec3bLike__i: int) bool
__len__() int
__iter__() Iterator[bool]
__init__(*args, **kwargs)
ZERO_2D = ivec2( 0, 0 )
X_2D = ivec2( 1, 0 )
Y_2D = ivec2( 0, 1 )
XY_2D : ivec2 = ivec2( 1, 1 )
EAST_2D : ivec2 = ivec2( 1, 0 )
WEST_2D : ivec2 = ivec2( -1, 0 )
SOUTH_2D : ivec2 = ivec2( 0, 1 )
NORTH_2D : ivec2 = ivec2( 0, -1 )
NORTHWEST_2D : ivec2 = ivec2( -1, -1 )
NORTHEAST_2D : ivec2 = ivec2( 1, -1 )
SOUTHEAST_2D : ivec2 = ivec2( 1, 1 )
SOUTHWEST_2D : ivec2 = ivec2( -1, 1 )
CARDINALS_2D : FrozenSet[ivec2] = frozenset({ivec2( 0, -1 ), ivec2( 1, 0 ), ivec2( 0, 1 ), ivec2( -1, 0 )})
INTERCARDINALS_2D : FrozenSet[ivec2] = frozenset({ivec2( -1, -1 ), ivec2( 1, -1 ), ivec2( 1, 1 ), ivec2( -1, 1 )})
CARDINALS_AND_DIAGONALS_2D : FrozenSet[ivec2] = frozenset({ivec2( -1, 0 ), ivec2( -1, -1 ), ivec2( 1, 0 ), ivec2( 1, -1 ), ivec2( 0, -1 ), ivec2( 1, 1 ), ivec2( 0, 1 ), ivec2( -1, 1 )})
DIAGONALS_2D = frozenset({ivec2( -1, -1 ), ivec2( 1, -1 ), ivec2( 1, 1 ), ivec2( -1, 1 )})
ORDERED_CARDINALS_2D : Tuple[ivec2, ...] = (ivec2( 1, 0 ), ivec2( 0, 1 ), ivec2( -1, 0 ), ivec2( 0, -1 ))
ORDERED_INTERCARDINALS_2D : Tuple[ivec2, ...] = (ivec2( 1, 1 ), ivec2( -1, 1 ), ivec2( -1, -1 ), ivec2( 1, -1 ))
ORDERED_CARDINALS_AND_DIAGONALS_2D : Tuple[ivec2, ...] = (ivec2( 1, 0 ), ivec2( 1, 1 ), ivec2( 0, 1 ), ivec2( -1, 1 ), ivec2( -1, 0 ), ivec2( -1, -1 ), ivec2( 0, -1 ), ivec2( 1, -1 ))
ZERO_3D = ivec3( 0, 0, 0 )
X_3D = ivec3( 1, 0, 0 )
Y_3D = ivec3( 0, 1, 0 )
Z_3D = ivec3( 0, 0, 1 )
XY_3D : ivec3 = ivec3( 1, 1, 0 )
XZ_3D : ivec3 = ivec3( 1, 0, 1 )
YZ_3D : ivec3 = ivec3( 0, 1, 1 )
XYZ_3D : ivec3 = ivec3( 1, 1, 1 )
UP_3D : ivec3 = ivec3( 0, 1, 0 )
DOWN_3D : ivec3 = ivec3( 0, -1, 0 )
EAST_3D : ivec3 = ivec3( 1, 0, 0 )
WEST_3D : ivec3 = ivec3( -1, 0, 0 )
SOUTH_3D : ivec3 = ivec3( 0, 0, 1 )
NORTH_3D : ivec3 = ivec3( 0, 0, -1 )
NORTHEAST_3D : ivec3 = ivec3( 1, 0, -1 )
NORTHWEST_3D : ivec3 = ivec3( -1, 0, -1 )
SOUTHWEST_3D : ivec3 = ivec3( -1, 0, 1 )
SOUTHEAST_3D : ivec3 = ivec3( 1, 0, 1 )
CARDINALS_3D : FrozenSet[ivec3] = frozenset({ivec3( 0, 0, 1 ), ivec3( 1, 0, 0 ), ivec3( -1, 0, 0 ), ivec3( 0, 0, -1 )})
INTERCARDINALS_3D : FrozenSet[ivec3] = frozenset({ivec3( -1, 0, 1 ), ivec3( 1, 0, 1 ), ivec3( 1, 0, -1 ), ivec3( -1, 0, -1 )})
CARDINALS_AND_DIAGONALS_3D : FrozenSet[ivec3] = frozenset({ivec3( -1, 0, 0 ), ivec3( -1, 0, 1 ), ivec3( 1, 0, 0 ), ivec3( 1, 0, 1 ), ivec3( 0, 0, -1 ), ivec3( 0, 0, 1 ), ivec3( 1, 0, -1 ), ivec3( -1, 0, -1 )})
ORDERED_CARDINALS_3D : Tuple[ivec3, ...] = (ivec3( 1, 0, 0 ), ivec3( 0, 0, 1 ), ivec3( -1, 0, 0 ), ivec3( 0, 0, -1 ))
ORDERED_INTERCARDINALS_3D : Tuple[ivec3, ...] = (ivec3( 1, 0, 1 ), ivec3( -1, 0, 1 ), ivec3( -1, 0, -1 ), ivec3( 1, 0, -1 ))
ORDERED_CARDINALS_AND_DIAGONALS_3D : Tuple[ivec3, ...] = (ivec3( 1, 0, 0 ), ivec3( 1, 0, 1 ), ivec3( 0, 0, 1 ), ivec3( -1, 0, 1 ), ivec3( -1, 0, 0 ), ivec3( -1, 0, -1 ), ivec3( 0, 0, -1 ), ivec3( 1, 0, -1 ))
DIRECTIONS_3D : FrozenSet[ivec3] = frozenset({ivec3( -1, 0, 0 ), ivec3( 1, 0, 0 ), ivec3( 0, 1, 0 ), ivec3( 0, 0, 1 ), ivec3( 0, -1, 0 ), ivec3( 0, 0, -1 )})
EDGE_DIAGONALS_3D : FrozenSet[ivec3] = frozenset({ivec3( 0, 1, 1 ), ivec3( -1, 0, 1 ), ivec3( 0, 1, -1 ), ivec3( 1, 0, 1 ), ivec3( 0, -1, -1 ), ivec3( 1, 1, 0 ), ivec3( 0, -1, 1 ), ivec3( -1, 1, 0 ), ivec3( -1, -1, 0 ), ivec3( 1, -1, 0 ), ivec3( 1, 0, -1 ), ivec3( -1, 0, -1 )})
DIRECTIONS_AND_EDGE_DIAGONALS_3D : FrozenSet[ivec3] = frozenset({ivec3( -1, 0, 0 ), ivec3( -1, -1, 0 ), ivec3( 0, 1, -1 ), ivec3( 0, 1, 0 ), ivec3( -1, 0, 1 ), ivec3( 0, -1, -1 ), ivec3( 1, 1, 0 ), ivec3( 0, 0, -1 ), ivec3( 0, 0, 1 ), ivec3( 0, -1, 0 ), ivec3( 0, -1, 1 ), ivec3( 1, 0, -1 ), ivec3( 1, 0, 1 ), ivec3( 1, 0, 0 ), ivec3( 1, -1, 0 ), ivec3( 0, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( -1, 0, -1 )})
CORNER_DIAGONALS_3D : FrozenSet[ivec3] = frozenset({ivec3( -1, -1, 1 ), ivec3( 1, -1, 1 ), ivec3( -1, 1, 1 ), ivec3( 1, 1, -1 ), ivec3( -1, 1, -1 ), ivec3( 1, 1, 1 ), ivec3( 1, -1, -1 ), ivec3( -1, -1, -1 )})
DIRECTIONS_AND_ALL_DIAGONALS_3D : FrozenSet[ivec3] = frozenset({ivec3( -1, 0, 0 ), ivec3( -1, -1, 0 ), ivec3( 0, 1, -1 ), ivec3( 0, 1, 0 ), ivec3( -1, -1, 1 ), ivec3( 1, 1, -1 ), ivec3( -1, 0, 1 ), ivec3( 0, -1, -1 ), ivec3( 1, 1, 0 ), ivec3( 0, 0, -1 ), ivec3( 0, 0, 1 ), ivec3( 0, -1, 0 ), ivec3( 0, -1, 1 ), ivec3( 1, 1, 1 ), ivec3( 1, -1, -1 ), ivec3( 1, 0, -1 ), ivec3( 1, -1, 1 ), ivec3( 1, 0, 1 ), ivec3( 1, 0, 0 ), ivec3( 1, -1, 0 ), ivec3( -1, 1, 1 ), ivec3( 0, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( -1, 1, -1 ), ivec3( -1, -1, -1 ), ivec3( -1, 0, -1 )})
DIAGONALS_3D = frozenset({ivec3( 0, 1, 1 ), ivec3( -1, -1, 0 ), ivec3( 0, 1, -1 ), ivec3( -1, -1, 1 ), ivec3( 1, 1, -1 ), ivec3( -1, 0, 1 ), ivec3( 0, -1, -1 ), ivec3( 1, 1, 0 ), ivec3( 0, -1, 1 ), ivec3( 1, 1, 1 ), ivec3( 1, -1, -1 ), ivec3( 1, 0, -1 ), ivec3( 1, -1, 1 ), ivec3( 1, 0, 1 ), ivec3( 1, -1, 0 ), ivec3( -1, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( -1, 1, -1 ), ivec3( -1, -1, -1 ), ivec3( -1, 0, -1 )})
ORDERED_EDGE_DIAGONALS_3D : Tuple[ivec3, ...] = (ivec3( 1, 1, 0 ), ivec3( 0, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( 0, 1, -1 ), ivec3( 1, 0, 1 ), ivec3( -1, 0, 1 ), ivec3( -1, 0, -1 ), ivec3( 1, 0, -1 ), ivec3( 1, -1, 0 ), ivec3( 0, -1, 1 ), ivec3( -1, -1, 0 ), ivec3( 0, -1, -1 ))
ORDERED_DIRECTIONS_AND_EDGE_DIAGONALS_3D : Tuple[ivec3, ...] = (ivec3( 0, 1, 0 ), ivec3( 1, 1, 0 ), ivec3( 0, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( 0, 1, -1 ), ivec3( 1, 0, 0 ), ivec3( 1, 0, 1 ), ivec3( 0, 0, 1 ), ivec3( -1, 0, 1 ), ivec3( -1, 0, 0 ), ivec3( -1, 0, -1 ), ivec3( 0, 0, -1 ), ivec3( 1, 0, -1 ), ivec3( 1, -1, 0 ), ivec3( 0, -1, 1 ), ivec3( -1, -1, 0 ), ivec3( 0, -1, -1 ), ivec3( 0, -1, 0 ))
ORDERED_CORNER_DIAGONALS_3D : Tuple[ivec3, ...] = (ivec3( 1, 1, 1 ), ivec3( -1, 1, 1 ), ivec3( -1, 1, -1 ), ivec3( 1, 1, -1 ), ivec3( 1, -1, 1 ), ivec3( -1, -1, 1 ), ivec3( -1, -1, -1 ), ivec3( 1, -1, -1 ))
ORDERED_DIRECTIONS_AND_ALL_DIAGONALS_3D : Tuple[ivec3, ...] = (ivec3( 0, 1, 0 ), ivec3( 1, 1, 0 ), ivec3( 1, 1, 1 ), ivec3( 0, 1, 1 ), ivec3( -1, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( -1, 1, -1 ), ivec3( 0, 1, -1 ), ivec3( 1, 1, -1 ), ivec3( 1, 0, 0 ), ivec3( 1, 0, 1 ), ivec3( 0, 0, 1 ), ivec3( -1, 0, 1 ), ivec3( -1, 0, 0 ), ivec3( -1, 0, -1 ), ivec3( 0, 0, -1 ), ivec3( 1, 0, -1 ), ivec3( 1, -1, 0 ), ivec3( 1, -1, 1 ), ivec3( 0, -1, 1 ), ivec3( -1, -1, 1 ), ivec3( -1, -1, 0 ), ivec3( -1, -1, -1 ), ivec3( 0, -1, -1 ), ivec3( 1, -1, -1 ), ivec3( 0, -1, 0 ))
ORDERED_DIAGONALS : Tuple[ivec3, ...] = (ivec3( 1, 1, 0 ), ivec3( 1, 1, 1 ), ivec3( 0, 1, 1 ), ivec3( -1, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( -1, 1, -1 ), ivec3( 0, 1, -1 ), ivec3( 1, 1, -1 ), ivec3( 1, 0, 1 ), ivec3( -1, 0, 1 ), ivec3( -1, 0, -1 ), ivec3( 1, 0, -1 ), ivec3( 1, -1, 0 ), ivec3( 1, -1, 1 ), ivec3( 0, -1, 1 ), ivec3( -1, -1, 1 ), ivec3( -1, -1, 0 ), ivec3( -1, -1, -1 ), ivec3( 0, -1, -1 ), ivec3( 1, -1, -1 ))
ZERO : ivec3 = ivec3( 0, 0, 0 )
X : ivec3 = ivec3( 1, 0, 0 )
Y : ivec3 = ivec3( 0, 1, 0 )
Z : ivec3 = ivec3( 0, 0, 1 )
XY : ivec3 = ivec3( 1, 1, 0 )
XZ : ivec3 = ivec3( 1, 0, 1 )
YZ : ivec3 = ivec3( 0, 1, 1 )
XYZ : ivec3 = ivec3( 1, 1, 1 )
UP : ivec3 = ivec3( 0, 1, 0 )
DOWN : ivec3 = ivec3( 0, -1, 0 )
EAST : ivec3 = ivec3( 1, 0, 0 )
WEST : ivec3 = ivec3( -1, 0, 0 )
SOUTH : ivec3 = ivec3( 0, 0, 1 )
NORTH : ivec3 = ivec3( 0, 0, -1 )
NORTHEAST : ivec3 = ivec3( 1, 0, -1 )
NORTHWEST : ivec3 = ivec3( -1, 0, -1 )
SOUTHWEST : ivec3 = ivec3( -1, 0, 1 )
SOUTHEAST : ivec3 = ivec3( 1, 0, 1 )
CARDINALS : FrozenSet[ivec3] = frozenset({ivec3( 0, 0, 1 ), ivec3( 1, 0, 0 ), ivec3( -1, 0, 0 ), ivec3( 0, 0, -1 )})
INTERCARDINALS : FrozenSet[ivec3] = frozenset({ivec3( -1, 0, 1 ), ivec3( 1, 0, 1 ), ivec3( 1, 0, -1 ), ivec3( -1, 0, -1 )})
CARDINALS_AND_DIAGONALS : FrozenSet[ivec3] = frozenset({ivec3( -1, 0, 0 ), ivec3( -1, 0, 1 ), ivec3( 1, 0, 0 ), ivec3( 1, 0, 1 ), ivec3( 0, 0, -1 ), ivec3( 0, 0, 1 ), ivec3( 1, 0, -1 ), ivec3( -1, 0, -1 )})
EDGE_DIAGONALS : FrozenSet[ivec3] = frozenset({ivec3( 0, 1, 1 ), ivec3( -1, 0, 1 ), ivec3( 0, 1, -1 ), ivec3( 1, 0, 1 ), ivec3( 0, -1, -1 ), ivec3( 1, 1, 0 ), ivec3( 0, -1, 1 ), ivec3( -1, 1, 0 ), ivec3( -1, -1, 0 ), ivec3( 1, -1, 0 ), ivec3( 1, 0, -1 ), ivec3( -1, 0, -1 )})
CORNER_DIAGONALS : FrozenSet[ivec3] = frozenset({ivec3( -1, -1, 1 ), ivec3( 1, -1, 1 ), ivec3( -1, 1, 1 ), ivec3( 1, 1, -1 ), ivec3( -1, 1, -1 ), ivec3( 1, 1, 1 ), ivec3( 1, -1, -1 ), ivec3( -1, -1, -1 )})
DIRECTIONS : FrozenSet[ivec3] = frozenset({ivec3( -1, 0, 0 ), ivec3( 1, 0, 0 ), ivec3( 0, 1, 0 ), ivec3( 0, 0, 1 ), ivec3( 0, -1, 0 ), ivec3( 0, 0, -1 )})
DIRECTIONS_AND_EDGE_DIAGONALS : FrozenSet[ivec3] = frozenset({ivec3( -1, 0, 0 ), ivec3( -1, -1, 0 ), ivec3( 0, 1, -1 ), ivec3( 0, 1, 0 ), ivec3( -1, 0, 1 ), ivec3( 0, -1, -1 ), ivec3( 1, 1, 0 ), ivec3( 0, 0, -1 ), ivec3( 0, 0, 1 ), ivec3( 0, -1, 0 ), ivec3( 0, -1, 1 ), ivec3( 1, 0, -1 ), ivec3( 1, 0, 1 ), ivec3( 1, 0, 0 ), ivec3( 1, -1, 0 ), ivec3( 0, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( -1, 0, -1 )})
DIRECTIONS_AND_ALL_DIAGONALS : FrozenSet[ivec3] = frozenset({ivec3( -1, 0, 0 ), ivec3( -1, -1, 0 ), ivec3( 0, 1, -1 ), ivec3( 0, 1, 0 ), ivec3( -1, -1, 1 ), ivec3( 1, 1, -1 ), ivec3( -1, 0, 1 ), ivec3( 0, -1, -1 ), ivec3( 1, 1, 0 ), ivec3( 0, 0, -1 ), ivec3( 0, 0, 1 ), ivec3( 0, -1, 0 ), ivec3( 0, -1, 1 ), ivec3( 1, 1, 1 ), ivec3( 1, -1, -1 ), ivec3( 1, 0, -1 ), ivec3( 1, -1, 1 ), ivec3( 1, 0, 1 ), ivec3( 1, 0, 0 ), ivec3( 1, -1, 0 ), ivec3( -1, 1, 1 ), ivec3( 0, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( -1, 1, -1 ), ivec3( -1, -1, -1 ), ivec3( -1, 0, -1 )})
ORDERED_CARDINALS : Tuple[ivec3, ...] = (ivec3( 1, 0, 0 ), ivec3( 0, 0, 1 ), ivec3( -1, 0, 0 ), ivec3( 0, 0, -1 ))
ORDERED_INTERCARDINALS : Tuple[ivec3, ...] = (ivec3( 1, 0, 1 ), ivec3( -1, 0, 1 ), ivec3( -1, 0, -1 ), ivec3( 1, 0, -1 ))
ORDERED_CARDINALS_AND_DIAGONALS : Tuple[ivec3, ...] = (ivec3( 1, 0, 0 ), ivec3( 1, 0, 1 ), ivec3( 0, 0, 1 ), ivec3( -1, 0, 1 ), ivec3( -1, 0, 0 ), ivec3( -1, 0, -1 ), ivec3( 0, 0, -1 ), ivec3( 1, 0, -1 ))
ORDERED_EDGE_DIAGONALS : Tuple[ivec3, ...] = (ivec3( 1, 1, 0 ), ivec3( 0, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( 0, 1, -1 ), ivec3( 1, 0, 1 ), ivec3( -1, 0, 1 ), ivec3( -1, 0, -1 ), ivec3( 1, 0, -1 ), ivec3( 1, -1, 0 ), ivec3( 0, -1, 1 ), ivec3( -1, -1, 0 ), ivec3( 0, -1, -1 ))
ORDERED_CORNER_DIAGONALS : Tuple[ivec3, ...] = (ivec3( 1, 1, 1 ), ivec3( -1, 1, 1 ), ivec3( -1, 1, -1 ), ivec3( 1, 1, -1 ), ivec3( 1, -1, 1 ), ivec3( -1, -1, 1 ), ivec3( -1, -1, -1 ), ivec3( 1, -1, -1 ))
ORDERED_DIRECTIONS : Tuple[ivec3, ...] = (ivec3( 0, 1, 0 ), ivec3( 1, 0, 0 ), ivec3( 0, 0, 1 ), ivec3( -1, 0, 0 ), ivec3( 0, 0, -1 ), ivec3( 0, -1, 0 ))
ORDERED_DIRECTIONS_AND_EDGE_DIAGONALS : Tuple[ivec3, ...] = (ivec3( 0, 1, 0 ), ivec3( 1, 1, 0 ), ivec3( 0, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( 0, 1, -1 ), ivec3( 1, 0, 0 ), ivec3( 1, 0, 1 ), ivec3( 0, 0, 1 ), ivec3( -1, 0, 1 ), ivec3( -1, 0, 0 ), ivec3( -1, 0, -1 ), ivec3( 0, 0, -1 ), ivec3( 1, 0, -1 ), ivec3( 1, -1, 0 ), ivec3( 0, -1, 1 ), ivec3( -1, -1, 0 ), ivec3( 0, -1, -1 ), ivec3( 0, -1, 0 ))
ORDERED_DIRECTIONS_AND_ALL_DIAGONALS : Tuple[ivec3, ...] = (ivec3( 0, 1, 0 ), ivec3( 1, 1, 0 ), ivec3( 1, 1, 1 ), ivec3( 0, 1, 1 ), ivec3( -1, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( -1, 1, -1 ), ivec3( 0, 1, -1 ), ivec3( 1, 1, -1 ), ivec3( 1, 0, 0 ), ivec3( 1, 0, 1 ), ivec3( 0, 0, 1 ), ivec3( -1, 0, 1 ), ivec3( -1, 0, 0 ), ivec3( -1, 0, -1 ), ivec3( 0, 0, -1 ), ivec3( 1, 0, -1 ), ivec3( 1, -1, 0 ), ivec3( 1, -1, 1 ), ivec3( 0, -1, 1 ), ivec3( -1, -1, 1 ), ivec3( -1, -1, 0 ), ivec3( -1, -1, -1 ), ivec3( 0, -1, -1 ), ivec3( 1, -1, -1 ), ivec3( 0, -1, 0 ))
DIAGONALS : FrozenSet[ivec3] = frozenset({ivec3( 0, 1, 1 ), ivec3( -1, -1, 0 ), ivec3( 0, 1, -1 ), ivec3( -1, -1, 1 ), ivec3( 1, 1, -1 ), ivec3( -1, 0, 1 ), ivec3( 0, -1, -1 ), ivec3( 1, 1, 0 ), ivec3( 0, -1, 1 ), ivec3( 1, 1, 1 ), ivec3( 1, -1, -1 ), ivec3( 1, 0, -1 ), ivec3( 1, -1, 1 ), ivec3( 1, 0, 1 ), ivec3( 1, -1, 0 ), ivec3( -1, 1, 1 ), ivec3( -1, 1, 0 ), ivec3( -1, 1, -1 ), ivec3( -1, -1, -1 ), ivec3( -1, 0, -1 )})
dropDimension(vec: Vec3iLike, dimension: int) ivec2

Returns vec without its dimension-th component

addDimension(vec: Vec2iLike, dimension: int, value: int = 0) ivec3

Inserts value into vec at dimension and returns the resulting 3D vector

dropY(vec: Vec3iLike) ivec2

Returns vec without its y-component (i.e., projected on the XZ-plane)

addY(vec: Vec2iLike, y: int = 0) ivec3

Returns a 3D vector (vec[0], y, vec[1])

setY(vec: Vec3iLike, y: int = 0) ivec3

Returns vec with its y-component set to y

trueMod2D(vec: Vec2iLike, modulus: int) ivec2

Returns v modulo modulus.

Some libraries (notably, pyGLM), define vector classes with a % operator that behaves differently than Python-s built-in integer modulo when negative numbers are involved. This function is a workaround for that: it always performs vector modulo in the same way as Python’s built-in modulo.

trueMod3D(vec: Vec3iLike, modulus: int) ivec3

Returns v modulo modulus.

Some libraries (notably, pyGLM), define vector classes with a % operator that behaves differently than Python-s built-in integer modulo when negative numbers are involved. This function is a workaround for that: it always performs vector modulo in the same way as Python’s built-in modulo.

perpendicular(vec: Vec2iLike) ivec2

Returns the vector perpendicular to vec that points to the right of vec and has the same length.

rotate2D(vec: Vec2iLike, rotation: int) ivec2

Returns vec, rotated by rotation

rotate3D(vec: Vec3iLike, rotation: int) ivec3

Returns vec, rotated in the XZ-plane by rotation

rotate2Ddeg(vec: Vec2iLike, degrees: int) ivec2

Returns vec, rotated by rotation degrees.

degrees must be a multiple of 90.

rotate3Ddeg(vec: Vec3iLike, degrees: int) ivec3

Returns vec, rotated in the XZ-plane by rotation degrees.

degrees must be a multiple of 90.

flipRotation2D(rotation: int, flip: Vec2bLike) int

Returns rotation such that applying rotation after flip is equivalent to applying flip after rotation.

flipRotation3D(rotation: int, flip: Vec3bLike) int

Returns rotation such that applying rotation after flip is equivalent to applying flip after rotation

rotateSize2D(size: Vec2iLike, rotation: int) ivec2

Returns the effective size of a rect of size size that has been rotated in the XZ-plane by rotation.

rotateSize3D(size: Vec3iLike, rotation: int) ivec3

Returns the effective size of a box of size size that has been rotated in the XZ-plane by rotation.

flipToScale2D(flip: Vec2bLike) ivec2

Returns a vector with a 1 where flip is False, and -1 where flip is True

flipToScale3D(flip: Vec3bLike) ivec3

Returns a vector with a 1 where flip is False, and -1 where flip is True

scaleToFlip2D(scale: Vec2iLike) bvec2

Returns whether scale flips space in each axis

scaleToFlip3D(scale: Vec3iLike) bvec3

Returns whether scale flips space in each axis

toAxisVector2D(vec: Vec2iLike) ivec2

Returns the axis-aligned unit vector closest to vec

directionToRotation(direction: Vec2iLike) int

Returns the rotation that rotates (0,-1) closest to direction

length(vec: Vec2iLike | Vec3iLike) float

Returns the length of vec

length2(vec: Vec2iLike | Vec3iLike) int

Returns the squared length of vec

distance(vecA: Vec2iLike | Vec3iLike, vecB: Vec2iLike | Vec3iLike) float

Returns the distance between vecA and vecB

distance2(vecA: Vec2iLike | Vec3iLike, vecB: Vec2iLike | Vec3iLike) int

Returns the squared distance between vecA and vecB

l1Norm(vec: Vec2iLike | Vec3iLike) int

Returns the L1 norm of vec

l1Distance(vecA: Vec2iLike | Vec3iLike, vecB: Vec2iLike | Vec3iLike) int

Returns the L1 norm distance between vecA and vecB.

vecA and vecB must be both Vec2iLike or both Vec3iLike.

orderedCorners2D(corner1: Vec2iLike, corner2: Vec2iLike) tuple[ivec2, ivec2]

Returns two corners of the rectangle defined by corner1 and corner2, such that the first corner is smaller than the second corner in each axis

orderedCorners3D(corner1: Vec3iLike, corner2: Vec3iLike) tuple[ivec3, ivec3]

Returns two corners of the box defined by corner1 and corner2, such that the first corner is smaller than the second corner in each axis

getDimensionality(corner1: Vec2iLike | Vec3iLike, corner2: Vec2iLike | Vec3iLike) tuple[int, list[int]]

Determines the number of dimensions for which corner1 and corner2 are in general position, i.e. the number of dimensions for which the volume they define is not flat.

Returns (dimensionality, list of indices of dimensions for which the volume is flat). For example: (2, [0,2]) means that the volume is flat in the x and z axes.

class Rect

A rectangle, defined by an offset and a size

__init__(offset: Vec2iLike = (0, 0), size: Vec2iLike = (0, 0))
__hash__() int

Returns the hash of this Rect

__iter__() Generator[ivec2, None, None]

Yields all points contained in this Rect

property offset : ivec2

This Rect’s offset

property size : ivec2

This Rect’s size

property begin : ivec2

Equivalent to .offset. Setting will modify offset.

property end : ivec2

Equivalent to .offset + .size. Setting will modify size.

property last : ivec2

Equivalent to .offset + .size - 1. Setting will modify size.

property middle : ivec2

This Rect’s middle point, rounded down

property center : ivec2

Equivalent to middle

property area : int

This Rect’s surface area

property corners : Generator[ivec2, None, None]

Yields this Rect’s corner points

contains(vec: Vec2iLike) bool

Returns whether this Rect contains vec

collides(other: Rect) bool

Returns whether this Rect and other have any overlap

squaredDistanceToVec(vec: Vec2iLike) int

Returns the squared distance between this Rect and vec

distanceToVec(vec: Vec2iLike) float

Returns the distance between this Rect and vec

translated(translation: Vec2iLike | int) Rect

Returns a copy of this Rect, translated by translation

dilate(dilation: int = 1) None

Morphologically dilates this rect by dilation

dilated(dilation: int = 1) Rect

Returns a copy of this Rect, morphologically dilated by dilation

erode(erosion: int = 1) None

Morphologically erodes this rect by erosion

eroded(erosion: int = 1) Rect

Returns a copy of this Rect, morphologically eroded by erosion

centeredSubRectOffset(size: Vec2iLike) ivec2

Returns an offset such that Rect(offset, <size>).middle == self.middle

centeredSubRect(size: Vec2iLike) Rect

Returns a rect of size size with the same middle as this rect

static between(cornerA: Vec2iLike, cornerB: Vec2iLike) Rect

Returns the Rect between cornerA and cornerB (inclusive), which may be any opposing corners.

static bounding(points: Iterable[Vec2iLike]) Rect

Returns the smallest Rect containing all points

toBox(offsetY: int = 0, sizeY: int = 0) Box

Returns a corresponding Box

property outline : Generator[ivec2, None, None]

Yields this Rect’s outline points

__match_args__ = ('_offset', '_size')
class Box

A box, defined by an offset and a size

__init__(offset: Vec3iLike = (0, 0, 0), size: Vec3iLike = (0, 0, 0))
__hash__() int

Returns the hash of this Box

__iter__() Generator[ivec3, None, None]

Yields all points contained in this Box

property offset : ivec3

This Box’s offset

property size : ivec3

This Box’s size

property begin : ivec3

Equivalent to .offset. Setting will modify offset.

property end : ivec3

Equivalent to .offset + .size. Setting will modify size.

property last : ivec3

Equivalent to .offset + .size - 1. Setting will modify size.

property middle : ivec3

This Box’s middle point, rounded down

property center : ivec3

Equivalent to .middle

property volume : int

This Box’s volume

property corners : list[ivec3]

Yields this Box’s corner points

contains(vec: Vec3iLike) bool

Returns whether this Box contains vec

collides(other: Box) bool

Returns whether this Box and other have any overlap

squaredDistanceToVec(vec: Vec3iLike) int

Returns the squared distance between this Box and vec

distanceToVec(vec: Vec3iLike) float

Returns the distance between this Box and vec

translated(translation: Vec3iLike | int) Box

Returns a copy of this Box, translated by translation

dilate(dilation: int = 1) None

Morphologically dilates this box by dilation

dilated(dilation: int = 1) Box

Returns a copy of this Box, morphologically dilated by dilation

erode(erosion: int = 1) None

Morphologically erodes this box by erosion

eroded(erosion: int = 1) Box

Returns a copy of this Box, morphologically eroded by erosion

centeredSubBoxOffset(size: Vec3iLike) ivec3

Returns an offset such that Box(offset, size).middle == self.middle

centeredSubBox(size: Vec3iLike) Box

Returns an box of size size with the same middle as this box

static between(cornerA: Vec3iLike, cornerB: Vec3iLike) Box

Returns the Box between cornerA and cornerB (both inclusive), which may be any opposing corners

static bounding(points: Iterable[Vec3iLike]) Box

Returns the smallest Box containing all points

toRect() Rect

Returns this Box’s XZ-plane as a Rect

property shell : Generator[ivec3, None, None]

Yields all points on this Box’s surface

property wireframe : Generator[ivec3, None, None]

Yields all points on this Box’s edges

__match_args__ = ('_offset', '_size')
rectSlice(array: ndarray[tuple[int, ...], dtype[Any]], rect: Rect) ndarray[tuple[int, ...], dtype[Any]]

Returns the slice from array defined by rect

setRectSlice(array: ndarray[tuple[int, ...], dtype[Any]], rect: Rect, value: Any) None

Sets the slice from array defined by rect to value

boxSlice(array: ndarray[tuple[int, ...], dtype[Any]], box: Box) ndarray[tuple[int, ...], dtype[Any]]

Returns the slice from array defined by box

setBoxSlice(array: ndarray[tuple[int, ...], dtype[Any]], box: Box, value: Any) None

Sets the slice from array defined by box to value

loop2D(begin: Vec2iLike, end: Vec2iLike | None = None) Generator[ivec2, None, None]

Yields all points between begin and end (end-exclusive).

If end is not given, yields all points between (0,0) and begin.

loop3D(begin: Vec3iLike, end: Vec3iLike | None = None) Generator[ivec3, None, None]

Yields all points between begin and end (end-exclusive).

If end is not given, yields all points between (0,0,0) and begin.

cuboid2D(corner1: Vec2iLike, corner2: Vec2iLike) Generator[ivec2, None, None]

Yields all points in the rectangle between corner1 and corner2 (inclusive).

cuboid3D(corner1: Vec3iLike, corner2: Vec3iLike) Generator[ivec3, None, None]

Yields all points in the box between corner1 and corner2 (inclusive).

filled2DArray(points: Iterable[Vec2iLike], seedPoint: Vec2iLike, boundingRect: Rect | None = None, includeInputPoints: bool = True) ndarray[tuple[int, ...], dtype[int64]]

Fills the shape defined by points, starting at seedPoint and returns a (n,2) numpy array containing the resulting points.

boundingRect should contain all points. If not provided, it is calculated.

filled2D(points: Iterable[Vec2iLike], seedPoint: Vec2iLike, boundingRect: Rect | None = None, includeInputPoints: bool = True) Generator[ivec2, None, None]

Fills the shape defined by points, starting at seedPoint and yields the resulting points.

boundingRect should contain all points. If not provided, it is calculated.

filled3DArray(points: Iterable[Vec3iLike], seedPoint: Vec3iLike, boundingBox: Box | None = None, includeInputPoints: bool = True) ndarray[tuple[int, ...], dtype[int64]]

Fills the shape defined by points, starting at seedPoint and returns a (n,3) numpy array containing the resulting points.

boundingBox should contain all points. If not provided, it is calculated.

filled3D(points: Iterable[Vec3iLike], seedPoint: Vec3iLike, boundingBox: Box | None = None, includeInputPoints: bool = True) Generator[ivec3, None, None]

Fills the shape defined by points, starting at seedPoint and yields the resulting points.

boundingBox should contain all points. If not provided, it is calculated.

line2DArray(begin: Vec2iLike, end: Vec2iLike, width: int = 1) ndarray[tuple[int, ...], dtype[int64]]

Returns (n,2) numpy array of points on the line between begin and end (inclusive)

line2D(begin: Vec2iLike, end: Vec2iLike, width: int = 1) Generator[ivec2, None, None]

Yields the points on the line between begin and end (inclusive)

line3Darray(begin: Vec3iLike, end: Vec3iLike, width: int = 1) ndarray[tuple[int, ...], dtype[int64]]

Returns (n,3) numpy array of points on the line between begin and end (inclusive)

line3D(begin: Vec3iLike, end: Vec3iLike, width: int = 1) Generator[ivec3, None, None]

Yields the points on the line between begin and end (inclusive)

lineSequence2D(points: Iterable[Vec2iLike], closed: bool = False) Generator[ivec2, None, None]

Yields all points on the lines that connect points

lineSequence3D(points: Iterable[Vec3iLike], closed: bool = False) Generator[ivec3, None, None]

Yields all points on the lines that connect points

circle(center: Vec2iLike, diameter: int, filled: bool = False) Generator[ivec2, None, None]

Yields the points of the specified circle.

If diameter is even, center will be the bottom left center point.

fittingCircle(corner1: Vec2iLike, corner2: Vec2iLike, filled: bool = False) Generator[ivec2, None, None]

Yields the points of the largest circle that fits between corner1 and corner2.

The circle will be centered in the larger axis.

ellipse(center: Vec2iLike, diameters: Vec2iLike, filled: bool = False) Generator[ivec2, None, None]

Yields the points of the specified ellipse.

If diameter[axis] is even, center[axis] will be the lower center point in that axis.

fittingEllipse(corner1: Vec2iLike, corner2: Vec2iLike, filled: bool = False) Generator[ivec2, None, None]

Yields the points of the largest ellipse that fits between corner1 and corner2.

cylinder(baseCenter: Vec3iLike, diameters: Vec2iLike | int, length: int, axis: int = 1, tube: bool = False, hollow: bool = False) Generator[ivec3, None, None]

Yields the points from the specified cylinder.

If a diameter is even, center will be the lower center point in that axis.

tube has precedence over hollow.

fittingCylinder(corner1: Vec3iLike, corner2: Vec3iLike, axis: int = 1, tube: bool = False, hollow: bool = False) Generator[ivec3, None, None]

Yields the points of the largest cylinder that fits between corner1 and corner2.

tube has precedence over hollow.

ellipsoid(center: Vec3iLike, diameters: Vec3iLike, hollow: bool = False) Generator[ivec3, None, None]

Yields the points of an ellipsoid centered on center with diameters diameters.

If diameter[axis] is even, center[axis] will be the lower center point in that axis.

fittingEllipsoid(corner1: Vec3iLike, corner2: Vec3iLike, hollow: bool = False) Generator[ivec3, None, None]

Yields the points of the largest ellipsoid that fits between corner1 and corner2.

sphere(center: Vec3iLike, diameter: int, hollow: bool = False) Generator[ivec3, None, None]

Yields the points of a sphere centered on center with diameter diameter.

If diameter is even, center will be the lower center point in every axis.

fittingSphere(corner1: Vec3iLike, corner2: Vec3iLike, hollow: bool = False) Generator[ivec3, None, None]

Yields the points of the largest sphere that fits between corner1 and corner2.

The circle will be centered in the non-minimum axes.

neighbors2D(point: Vec2iLike, boundingRect: Rect, diagonal: bool = False, stride: int = 1) Generator[ivec2, None, None]

Yields the neighbors of point within bounding_rect.

Useful for pathfinding.

neighbors3D(point: Vec3iLike, boundingBox: Box, diagonal: bool = False, stride: int = 1) Generator[ivec3, None, None]

Yields the neighbors of point within bounding_box.

Useful for pathfinding.