raimad.Transform
class
Transform(
builtins.object,
):
Transformation: container for affine matrix.
def __init__(self) -> None:
Initialize a new Transform as an identity transform.
def crotate(self, angle: float | int | SupportsFloat, x: float | int | SupportsFloat = 0, y: float | int | SupportsFloat = 0) -> Self:
Rotate around a point given by x and y coordinate.
Parameters
angleNum
Angle to rotate by, in radians.
xNum
Rotate around this point (x coordinate) default: 0
yNum
Rotate around this point (y coordinate) default: 0
Returns
Self
This transform is returned to allow chaining methods.
def protate(self, angle: float | int | SupportsFloat, pivot: raimad.types.Vec2 = (0, 0)) -> Self:
Rotate around a reference point given as an (x, y) tuple.
Parameters
angleNum
Angle to rotate by, in radians.
pivotVec2
The point (x, y) to rotate around. Default: origin.
Returns
Self
This transform is returned to allow chaining methods.
def rotate(self, angle: float | int | SupportsFloat, /, a: float | int | SupportsFloat | raimad.types.Vec2 | None = None, b: float | int | SupportsFloat | None = None) -> Self:
Rotate around a pivot point (overload).
This is an overloaded method that can take the position of the pivot point either as two separate x and y arguments, or as a single tuple of two values.
Parameters
angleNum
Angle to rotate by, in radians.
aNum | Vec2
Either the X coordinate, the entire pivot point, or None
bNum | None
Either the Y coordinate or None
Returns
Self
This transform is returned to allow chaining methods.
def cmove(self, x: float | int | SupportsFloat = 0, y: float | int | SupportsFloat = 0) -> Self:
Translate by x and y.
Parameters
xNum
Move this many units along x axis.
yNum
Move this many units along y axis.
Returns
Self
This transform is returned to allow chaining methods.
def pmove(self, offset: raimad.types.Vec2) -> Self:
Translate by x and y, given as a tuple.
Parameters
offsetVec2
A tuple of two values (x, y).
Returns
Self
This transform is returned to allow chaining methods.
def move(self, /, a: float | int | SupportsFloat | raimad.types.Vec2, b: float | int | SupportsFloat | None = None) -> Self:
Translate vertically and horizontally (overload).
This is an overloaded method that can take the X and Y offsets either as two separate x and y arguments, or as a single tuple of two values.
Parameters
aNum | Vec2
X offset or tuple of offsets
bNum | None
Y offset or None
Returns
Self
This transform is returned to allow chaining methods.
def movex(self, x: float | int | SupportsFloat = 0) -> Self:
Move along x axis.
Parameters
xNum
Move this many units along x axis.
Returns
Self
This transform is returned to allow chaining methods.
def movey(self, y: float | int | SupportsFloat = 0) -> Self:
Move along y axis.
Parameters
yNum
Move this many units along y axis.
Returns
Self
This transform is returned to allow chaining methods.
def cflip(self, x: float | int | SupportsFloat = 0, y: float | int | SupportsFloat = 0) -> Self:
Flip (mirror) along both horizontal and vertical axis.
Parameters
xNum
Flip around this point (x coordinate)
yNum
Flip around this point (y coordinate)
Returns
Self
This transform is returned to allow chaining methods.
def pflip(self, pivot: raimad.types.Vec2) -> Self:
Flip (mirror) along both horizontal and vertical axis (tuple).
Parameters
pivot: Vec2
Tuple representing x and y coordinates of lines to mirror against
Returns
Self
This transform is returned to allow chaining methods.
def flip(self, /, a: float | int | SupportsFloat | raimad.types.Vec2, b: float | int | SupportsFloat | None = None) -> Self:
Flip (mirror) along both horizontal and vertical axis.
This is an overloaded method that can take the X and Y intercepts of the two mirroring lines either as two separate x and y arguments, or as a single tuple of two values.
Parameters
aNum | Vec2
Either the x-intercept or a tuple of the two intercepts.
bNum | None
Either the y-intercept or None
Returns
Self
This transform is returned to allow chaining methods.
def vflip(self, y: float | int | SupportsFloat = 0) -> Self:
Flip (mirror) along horizontal axis.
Parameters
yNum
Flip around this horizontal line (y coordinate)
Returns
Self
This transform is returned to allow chaining methods.
def hflip(self, x: float | int | SupportsFloat = 0) -> Self:
Flip (mirror) along vertical axis.
Parameters
xNum
Flip around this vertical line (x coordinate)
Returns
Self
This transform is returned to allow chaining methods.
def cpscale(self, x: float | int | SupportsFloat, y: float | int | SupportsFloat, pivot: raimad.types.Vec2 = (0, 0)) -> Self:
Scale width and height (two Nums) around pivot point (tuple).
Parameters
xNum
Factor to scale by along the x axis
yNum
Factor to scale by along the y axis.
pivotVec2
Use this point as origin for the scale. Default: origin
Returns
Self
This transform is returned to allow chaining methods.
def ccscale(self, x: float | int | SupportsFloat, y: float | int | SupportsFloat, px: float | int | SupportsFloat = 0, py: float | int | SupportsFloat = 0) -> Self:
Scale width and height (two Nums) around pivot point (two Nums).
Parameters
xNum
Factor to scale by along the x axis
yNum
Factor to scale by along the y axis.
pxNum
X coordinate of origin of the scale (default: 0)
pyNum
Y coordinate of origin of the scale (default: 0)
Returns
Self
This transform is returned to allow chaining methods.
def ppscale(self, scale: raimad.types.Vec2, pivot: raimad.types.Vec2 = (0, 0)) -> Self:
Scale width and height (tuple) around pivot point (tuple).
Parameters
scaleVec2
The x and y scale factors
pivotVec2
Use this point as origin for the scale. Default: origin
Returns
Self
This transform is returned to allow chaining methods.
def pcscale(self, scale: raimad.types.Vec2, px: float | int | SupportsFloat = 0, py: float | int | SupportsFloat = 0) -> Self:
Scale width and height (tuple) around pivot point (two Nums).
Parameters
scaleVec2
The x and y scale factors
pxNum
X coordinate of origin of the scale (default: 0)
pyNum
Y coordinate of origin of the scale (default: 0)
Returns
Self
This transform is returned to allow chaining methods.
def apscale(self, factor: float | int | SupportsFloat, pivot: raimad.types.Vec2 = (0, 0)) -> Self:
Scale both width and height by same factor around pivot (tuple).
Parameters
factorNum
Factor to scale by.
pivotVec2
Use this point as origin for the scale. Default: origin
Returns
Self
This transform is returned to allow chaining methods.
def acscale(self, factor: float | int | SupportsFloat, px: float | int | SupportsFloat = 0, py: float | int | SupportsFloat = 0) -> Self:
Scale both width and height by same factor around pivot (two Nums).
Parameters
factorNum
Factor to scale by.
pxNum
X coordinate of origin of the scale (default: 0)
pyNum
Y coordinate of origin of the scale (default: 0)
Returns
Self
This transform is returned to allow chaining methods.
def scale(self, /, a: float | int | SupportsFloat | raimad.types.Vec2, b: float | int | SupportsFloat | raimad.types.Vec2 | None = None, c: float | int | SupportsFloat | raimad.types.Vec2 | None = None, d: float | int | SupportsFloat | None = None) -> Self:
Scale width and height around a pivot point (overload).
This is an overloaded function. It can take: - single scale factor - `self.scale(5)` - single scale factor and pivot point (tuple) - `self.scale(5, (1, 1))` - single scale factor and pivot point (separate values) - `self.scale(5, 1, 1)` - x, y scale factors (separate values) - `self.scale(5, 4)` - x, y scale factors (tuple) - `self.scale((5, 4))` - x, y scale factors (separate values) and pivot (tuple) - `self.scale(5, 4, (1, 1))` - x, y scale factors (tuple) and pivot (tuple) - `self.scale((5, 4), (1, 1))` - x, y scale factors (separate values) and pivot (separate values) - `self.scale(5, 4, 1, 1)` - x, y scale factors (tuple) and pivot (separate values) - `self.scale((5, 4), 1, 1)`
Returns
Self
This transform is returned to allow method chaining.
def get_translation(self) -> tuple[float | int, float | int]:
Return how much this transform translates the coordinate plane.
Returns
tuple[float, float]
The first item is how much the plane is moved along the x axis. The second item is how much the plane is moved along the y axis.
def get_rotation(self) -> float | int:
Return how much this transform rotates the coordinate plane.
Returns
float
The angle by which this transform rotates the coordinate plane (radians, in the positive orientation)
def get_shear(self) -> float | int:
Return a how much this transform shears the coordinate plane.
Returns
float
A number representing the shear.
def get_scale(self) -> tuple[float | int, float | int]:
Return how much this transform scales the x and y axis.
Returns
tuple[float, float]
The first float is the scaling factor along the x axis. The second float is the scaling factor along the y axis.
def does_translate(self) -> bool:
Check whether this transform applies a translation.
Returns
bool
True if the transform translates. False otherwise.
def does_rotate(self) -> bool:
Check whether this transform applies a rotation.
Returns
bool
True if the transform rotates. False otherwise.
def does_shear(self) -> bool:
Check whether this transform applies a shear.
Returns
bool
True if the transform shears. False otherwise.
def does_scale(self) -> bool:
Check whether this transform applies a scale.
Returns
bool
True if the transform scales. False otherwise.
def reset(self) -> None:
Reset this transform to be an identity transform.
def transform_poly(self, poly: collections.abc.Sequence[raimad.types.Vec2]) -> list[tuple[float | int, float | int]]:
Apply transformation to poly and return new transformed poly.
Parameters
polyPolyS
The Poly to transform
Returns
PolyS
The new, transformed, Poly
def transform_point(self, point: raimad.types.Vec2) -> tuple[float | int, float | int]:
Apply this transform to a point, and return the transformed point.
A Point (tuple of two floats) is always returned, even if a BoundPoint is passed in.
Parameters
pointVec2
The point to transform.
Returns
Vec2S
The transformed point.
def compose(self, transform: Self) -> Self:
Apply a different transform to this transform.
Parameters
transformSelf
The other transform to apply to this one
Returns
Self
This transform is returned to allow method chaining.
def __repr__(self) -> str:
Return string representation of transform.
Returns
str
A representation of this transform.
def copy(self) -> Self:
Duplicate transform.
Returns
Self
The copied transform.