raimad.Proxy
class
Proxy(
builtins.object,
):
Proxy: transforming and layermapping wrapper around a Compo.
TODO description here.
def __init__(self, compo: 'rai.typing.CompoLike', lmap: 'rai.typing.LMapShorthand' = None, transform: 'rai.typing.Transform | None' = None, _cif_link: bool = False, _autogenned: bool = False, _deepcopied: bool = False):
Create new Proxy.
Do not instantiate Proxies directly unless you have a good reason to. Use `Compo.proxy()` instead.
Parameters
compo
The compo or proxy that the new proxy will point to
lmap
Layer map shorthand for the new proxy
transform:
Transformation for the new proxy (None for identity transform)
def steamroll(self) -> dict[str, list[list[tuple[float | int, float | int]]]]:
Get all geometries of this proxy.
Returns
GeomsS
Returns all geometries (i.e. all raw geometries as well as subcompos) of the CompoLike pointed to by this proxy, as seen through this proxy.
TODO example
def get_flat_transform(self, maxdepth: int = -1) -> 'rai.typing.Transform':
Get flattened transform from tower of proxies.
Parameters
maxdepth
Stop at this many proxies. -1 means no limit.
Returns
rai.typing.Transform
A new transform that is eqiuivalent to applying all transform in this proxy tower.
def get_flat_lmap(self, maxdepth: int = -1) -> raimad.proxy.LMap:
Get flattened layermap from tower of proxies.
Parameters
maxdepth
Stop at this many proxies. -1 means no limit.
Returns
LMap
A new layermap that is eqiuivalent to applying all layermaps in this proxy tower successibely.
def final(self) -> 'rai.typing.Compo':
Return the compo at the bottom of a tower of proxies.
Returns
rai.typing.Compo
The compo at the bottom of a tower of proxies
def final_p(self) -> 'rai.typing.Proxy':
Return the proxy at the bottom of a tower of proxies.
Returns
rai.typing.Compo
The proxy at the bottom of a tower of proxies -- i.e. the second-to-last element in the tower of proxies.
def depth(self) -> int:
Measure depth of a tower of proxies.
Returns
int
0 if called on a compo, 1 if called on a proxy of a compo, 2 if called on a proxy of a proxy of a compo, and so on.
def descend(self) -> 'Iterator[rai.typing.CompoLike]':
Descend a tower of proxies to the compo at the bottom.
Yields
rai.typing.CompoLike
Yields all of the proxies in the tower, and the compo at the very bottom.
def descend_p(self) -> 'Iterator[rai.typing.Proxy]':
Descend a tower of proxies to the lowest proxy.
Yields
rai.typing.Proxy
Yields all of the proxies in the tower, but no the compo at the bottom.
def proxy(self) -> 'rai.typing.Proxy':
Return a new proxy pointing to this proxy.
Returns
rai.typing.Proxy
The new proxy
def walk_hier(self) -> 'Iterator[rai.typing.Proxy]':
Traverse the subcomponent hierarchy of the CompoLike of this proxy.
This method will recursively walk through the entire subcompo hierarchy of the CompoLike pointed to by this proxy. Each node is wrapped in a copy of this proxy. TODO explain better
Yields
rai.typing.Proxy
For every subcomponent in the hierarchy, a copy of this proxy tower (i.e. self.deep_copy_reassign) is returned that points to the subcomponent.
def shallow_copy(self, _autogenned: bool = False, _deepcopied: bool = False) -> 'rai.typing.Proxy':
Make a shallow copy of this proxy.
This function returns a new proxy that is a copy of this proxy. If this proxy points to a different proxy, the target proxy is NOT coppied. In other words, if the current proxy is a proxy tower, only the topmost proxy is copied.
Returns
rai.typing.Proxy
Copy of this proxy
def shallow_copy_reassign(self, new_compo: 'rai.typing.CompoLike', _autogenned: bool = False, _deepcopied: bool = False) -> 'rai.typing.Proxy':
Make a shallow copy of this proxy and reassign to a new CompoLike.
This function returns a new proxy that is a copy of this proxy, but reassigned to `new_compo`. if the current proxy is a proxy tower, the proxies below this one are esentially ignored. The returned proxy is always pointing directly to `new_compo`, and the layermap and transform is exactly the same as this proxy.
Returns
rai.typing.Proxy
Copy of this proxy reassigned to `new_compo`
def deep_copy(self, _autogenned: bool = False) -> 'rai.typing.Proxy':
Make a deep copy of this proxy.
If this proxy is pointing directly to a compo, then this method is identical to `self.shallow_copy`. If, however, this proxy is a proxy tower, then all of the proxies in the tower are copied.
Returns
rai.typing.Proxy
Deep copy of this proxy
def deep_copy_reassign(self, new_compo: 'rai.typing.CompoLike', _autogenned: bool = False, _deepcopied: bool = False) -> 'rai.typing.Proxy':
Make a deep copy of this proxy and reassign to `new_compo`.
If this proxy is pointing directly to a compo, then this method is identical to `self.shallow_copy_reassign`. If, however, this proxy is a proxy tower, then all of the proxies in the tower are copied, and the bottom-most proxy is reassigned to `new_compo`.
Returns
rai.typing.Proxy
Deep copy of this proxy reassigned to `new_compo`.
def transform_point(self, point: raimad.types.Vec2) -> tuple[float | int, float | int]:
Apply this proxies transform to a point, return the transformed point.
A Point (tuple of two floats) is always returned, even if a BoundPoint is passed in.
Parameters
pointrai.typing.PointLike
The point to transform.
Returns
rai.typing.Point
The transformed point.
def __str__(self) -> str:
Return string representation of proxy.
Returns
str
TODO example string
def __repr__(self) -> str:
Return string representation of proxy.
Returns
str
TODO example string
def map(self, lmap_shorthand: 'rai.typing.LMapShorthand') -> Self:
Apply a layermap shorthand to a proxy.
Parameters
lmap_shorthand
The layermap shorthand to apply
Returns
Self
self is returned to allow method chaining.
def snap_left(self, target: Self) -> Self:
Move this proxy so its bbox is to the left of the target proxy.
Parameters
The target proxy
Returns
Self
This proxy is returned to allow method chaining.
def snap_right(self, target: Self) -> Self:
Move this proxy so its bbox is to the right of the target proxy.
Parameters
The target proxy
Returns
Self
This proxy is returned to allow method chaining.
def snap_above(self, target: Self) -> Self:
Move this proxy so its bbox is directly above the target proxy.
Parameters
The target proxy
Returns
Self
This proxy is returned to allow method chaining.
def snap_below(self, target: Self) -> Self:
Move this proxy so its bbox is directly below the target proxy.
Parameters
The target proxy
Returns
Self
This proxy is returned to allow method chaining.
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
anglefloat
Angle to rotate by, in radians.
xfloat
Rotate around this point (x coordinate) default: 0
yfloat
Rotate around this point (y coordinate) default: 0
Returns
Self
This proxy 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
anglefloat
Angle to rotate by, in radians.
pivotVec2S
The point (x, y) to rotate around. Default: origin.
Returns
Self
This proxy 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 proxy 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
xfloat
Move this many units along x axis.
yfloat
Move this many units along y axis.
Returns
Self
This proxy 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 proxy 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 proxy is returned to allow method chaining.
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 proxy 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 proxy 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 proxy 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 proxy 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 proxy 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 proxy 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 proxy 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 floats) 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 floats) around pivot point (two floats).
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 `None` means origin.
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 proxy is returned to allow method chaining.
def __annotate_func__(format, /):
Property geoms
Get the raw geometries as seen through this proxy.
Returns
GeomsS
Returns the raw geometries (i.e. NOT geometries defined in subcompos) defined in the CompoLike pointed to by this Proxy, as seen through this proxy.
Property subcompos
Get subcompos of the CompoLike pointed to by this proxy.
Returns
SubcompoContainer
A special `SubcompoContainer` is returned that is aware that you're looking at it through a proxy, so all of the subcompos will be wrapped in copies of this proxy.
Property marks
Get the marks of the CompoLike pointed to by this proxy.
Returns
ProxiedMarksContainer
A special `ProxiedMarksContainer` is returned which can be used to query the underlying CompoLike's marks as seen through this proxy.
Property bbox
Get a BoundBBox pointing to this proxy.
Returns
rai.BoundBBox
A BoundBBox pointing to this proxy