gdpc.transform

Provides the Transform class and related functions


class Transform

Represents a transformation of space.

When applied to a vector, flip is applied first, rotation second, and translation third.

Note that only the four 90-degree rotations in the XZ-plane are supported. Hence, rotation should be 0, 1, 2 or 3. A rotation of 1 rotates (1,0,0) to (0,0,1). In Minecraft’s coordinate system, this is clockwise.

__init__(translation: Vec3iLike = ivec3(0, 0, 0), rotation: int = 0, flip: Vec3bLike = bvec3(0, 0, 0))

Constructs a Transform with the given properties.

property translation : ivec3

The translation component of this transform

property rotation : int

The rotation component of this transform

property flip : bvec3

The flip component of this transform

apply(vec: Vec3iLike) ivec3

Applies this transform to vec.

Equivalent to self * vec.

invApply(vec: Vec3iLike) ivec3

Applies the inverse of this transform to vec.

Faster version of ~self * vec.

compose(other: Transform) Transform

Returns a transform that applies self after other.

Equivalent to self @ other.

invCompose(other: Transform) Transform

Returns a transform that applies ~self after other.

Faster version of ~self @ other.

composeInv(other: Transform) Transform

Returns a transform that applies self after ~other.

Faster version of self @ ~other.

push(other: Transform) None

Adds the effect of other to this transform.

Equivalent to self @= other.

pop(other: Transform) None

The inverse of push. Removes the effect of other from this transform.

Faster version of self @= ~other.

inverted() Transform

Returns the inversion of this transform.

Equivalent to ~self.

invert() None

Inverts this transform.

Faster version of self = ~self.

__matmul__(other: Transform) Transform

@ operator. Returns a transform that applies self after other

Equivalent to self.compose(other)

__mul__(vec: Vec3iLike) ivec3

* operator. Applies this transform to vec

Equivalent to self.apply(vec)

__imatmul__(other: Transform) Transform

@= operator. Adds the effect of other to this transform.

Equivalent to self.push(other)

__hash__ = None
__invert__() Transform

~ operator. Returns the inversion of this transform.

Equivalent to self.inverted().

__match_args__ = ('_translation', '_rotation', '_flip')
TransformLike

A class is a TransformLike if it is a Transform or a Vec3iLike, the latter being interpreted as a translation.

alias of Union[Transform, Vec3iLike]

toTransform(transformLike: TransformLike) Transform

Converts transformLike to a Transform, interpreting a vector as a translation.

This function is mainly for internal use in GDPC, but may also be useful in user programs.

Functions that take a Transform parameter are very often called with just a translation. By taking a TransformLike pararameter instead and using this converter, calling such a function with just a translation becomes slightly easier. This does however cost a bit of performance (for an isinstance call).

rotatedBoxTransform(box: Box, rotation: int) Transform

Returns a transform that maps the box ((0,0,0), size) to box under rotation, where size == vector_tools.rotateSize3D(box.size, rotation).

rotatedBoxTransformAndSize(box: Box, rotation: int) tuple[Transform, ivec3]

Returns (transform, size) such that transform maps the box ((0,0,0), size) to box, under rotation.

flippedBoxTransform(box: Box, flip: Vec3bLike) Transform

Returns a transform that maps the box ((0,0,0), box.size) to box under flip.