inkex.transforms module

Provide transformation parsing to extensions

class inkex.transforms.BoundingBox(other=None)[source]
class inkex.transforms.BoundingBox(x, y)

Bases: object

Some functions to compute a rough bbox of a given list of objects.

BoundingBox(other) BoundingBox(x, y) BoundingBox((x1, x2), (y1, y2))

static anchor_distance(x: float, y: float, direction: Union[int, str] = 0, selbox: Optional[inkex.transforms.BoundingBox] = None) float[source]

Using the x,y returns a single sortable value based on direction and angle

direction - int/float (custom angle), tb/bt (top/bottom), lr/rl (left/right), ri/ro (radial) selbox - The bounding box of the whole selection for radial anchors

property area
property bottom
property center

Returns the middle of the bounding box

property center_x
property center_y
get_anchor(xanchor: str, yanchor: str, direction: Union[int, str] = 0, selbox: Optional[inkex.transforms.BoundingBox] = None) float[source]

Calls get_distance with the given anchor options

property height
property left
property maximum

Return the maximum x,y coords

property minimum

Return the minimum x,y coords

property right
property top
property width
class inkex.transforms.DirectedLineSegment[source]
class inkex.transforms.DirectedLineSegment(other)
class inkex.transforms.DirectedLineSegment(start, end)

Bases: object

A directed line segment

DirectedLineSegment(((x0, y0), (x1, y1)))

property angle

Get the angle of the line created by this segment

distance_to_point(x: float, y: float) Optional[Union[inkex.transforms.DirectedLineSegment, float]][source]

Get the distance to the given point (x, y)

dot(other: inkex.transforms.DirectedLineSegment) float[source]

Get the dot product with the segment with another

property dx
property dy
end = Vector2d(0, 0)
intersect(other: inkex.transforms.DirectedLineSegment) Optional[inkex.transforms.Vector2d][source]

Get the intersection between two segments

property length

Get the length of the line segment

parallel(x: float, y: float) inkex.transforms.DirectedLineSegment[source]

Create parallel Segment

perp_distance(x: float, y: float) Optional[float][source]

Perpendicular distance to the given point

point_at_length(length: float) Tuple[float, float][source]

Get the point as the length along the line

point_at_ratio(ratio: float) Tuple[float, float][source]

Get the point at the given ratio along the line

start = Vector2d(0, 0)
property vector

The vector of the directed line segment.

The vector of the directed line segment represents the length and direction of segment, but not the starting point.

property x0
property x1
property y0
property y1
class inkex.transforms.ImmutableVector2d[source]
class inkex.transforms.ImmutableVector2d(v)
class inkex.transforms.ImmutableVector2d(x, y)

Bases: object

Represents an immutable element of 2-dimensional Euclidean space

static _parse(point: Union[inkex.transforms.ImmutableVector2d, Tuple[float, float], str]) Tuple[float, float][source]
_x = 0.0
_y = 0.0
property angle

The angle of the vector when represented in polar coordinates

cross(other: Union[inkex.transforms.ImmutableVector2d, Tuple[float, float]]) float[source]

Z component of the cross product of the vectors extended into 3D

dot(other: Union[inkex.transforms.ImmutableVector2d, Tuple[float, float]]) float[source]
is_close(other: Union[inkex.transforms.ImmutableVector2d, Tuple[float, float], str], rtol: float = 1e-05, atol: float = 1e-08) float[source]
property length
to_polar_tuple() Tuple[float, Optional[float]][source]

A tuple of the vector’s magnitude and direction

to_tuple() Tuple[float, float][source]
property x
property y
class inkex.transforms.Transform(matrix: Optional[Union[str, Tuple[Tuple[float, float, float], Tuple[float, float, float]], Tuple[float, float, float, float, float, float], inkex.transforms.Transform]] = None, callback: Optional[Callable[[inkex.transforms.Transform], inkex.transforms.Transform]] = None, **extra)[source]

Bases: object

A transformation object which will always reduce to a matrix and can then be used in combination with other transformations for reducing finding a point and printing svg ready output.

Use with svg transform attribute input:

tr = Transform(“scale(45, 32)”)

Use with triad matrix input (internal representation):

tr = Transform(((1.0, 0.0, 0.0), (0.0, 1.0, 0.0)))

Use with hexad matrix input (i.e. svg matrix(…)):

tr = Transform((1.0, 0.0, 0.0, 1.0, 0.0, 0.0))

Once you have a transformation you can operate tr * tr to compose, any of the above inputs are also valid operators for composing.

TRM = re.compile('(translate|scale|rotate|skewX|skewY|matrix)\\s*\\(([^)]*)\\)\\s*,?')
_is_URT(exactly: bool = False) bool[source]

Checks that transformation can be decomposed into product of Uniform scale (U), Rotation around origin (R) and translation (T)

Returns

decomposition as U*R*T is possible

_set_matrix(matrix: Union[str, Tuple[Tuple[float, float, float], Tuple[float, float, float]], Tuple[float, float, float, float, float, float], inkex.transforms.Transform]) None[source]

Parse a given string as an svg transformation instruction.

property a
absolute_tolerance: float = 1e-05
add_kwargs(**kwargs)[source]

Add translations, scales, rotations etc using key word arguments

add_matrix(a)[source]
add_matrix(a, b, c, d, e, f)
add_matrix(a, b)

Add matrix in order they appear in the svg hexad

add_rotate(deg, center)[source]
add_rotate(deg, center_x, center_y)
add_rotate(deg)
add_rotate(deg, a)
add_rotate(deg, a, b)

Add rotation to this transformation

add_scale(sc_x, sc_y=None)[source]

Add scale to this transformation

add_skewx(deg: float) inkex.transforms.Transform[source]

Add skew x to this transformation

add_skewy(deg: float) inkex.transforms.Transform[source]

Add skew y to this transformation

add_translate(dr)[source]
add_translate(tr_x, tr_y=0.0)
apply_to_point(point: Union[inkex.transforms.ImmutableVector2d, Tuple[float, float]]) inkex.transforms.Vector2d[source]

Transform a tuple (X, Y)

property b
property c
property d
property e
property f
interpolate(other: inkex.transforms.Transform, fraction: float) inkex.transforms.Transform[source]

Interpolate with another Transform.

is_rotate(exactly: bool = False) bool[source]

Returns True if this transformation is ONLY rotate

is_scale(exactly: bool = False) bool[source]

Returns True if this transformation is ONLY scale

is_translate(exactly: bool = False) bool[source]

Returns True if this transformation is ONLY translate

rotation_degrees() float[source]

Return the amount of rotation in this transform

to_hexad() Iterator[float][source]

Returns the transform as a hexad matrix (used in svg)

class inkex.transforms.Vector2d[source]
class inkex.transforms.Vector2d(v)
class inkex.transforms.Vector2d(x, y)

Bases: inkex.transforms.ImmutableVector2d

Represents an element of 2-dimensional Euclidean space

assign(x, y)[source]
assign(other)
static from_polar(radius: float, theta: Optional[float]) Optional[inkex.transforms.Vector2d][source]

Creates a Vector2d from polar coordinates

None is returned when theta is None and radius is not zero.

property x
property y