Util
apply-transform
apply-transform() -> vector or array or dictionary
Multiplies vectors by a transformation matrix. If multiple vectors are given they are returned as an array, if only one vector is given only one will be returned, if a dictionary is given they will be returned in the dictionary with the same keys.
The transformation matrix or a function that accepts and returns a vector.
Vectors to get transformed. Only the positional part of the sink is used. A dictionary of vectors can also be passed and all will be transformed.
revert-transform
revert-transform() -> vector
Reverts the transform of the given vector
line-pt
line-pt() -> vector
Linearly interpolates between two points and returns its position
line-normal
line-normal() -> vector
Get orthogonal vector to line
circle-arclen
circle-arclen() -> float
Calculates the arc-length of a circle or arc
ellipse-point
ellipse-point() -> vector
Get point on an ellipse for an angle
calculate-circle-center-3pt
calculate-circle-center-3pt() -> vector
Calculates the center of a circle from 3 points. The z coordinate is taken from point a.
resolve-number
resolve-number() -> float
Converts a number to "canvas units"
resolve-radius
resolve-radius() -> array
Ensures that a radius has an x
and y
component.
min
min(..a: ,) -> float
Finds the minimum of a set of values while ignoring none values.
max
max() -> float
Finds the maximum of a set of values while ignoring none values.
merge-dictionary
merge-dictionary() -> dictionary
Merges dictionary b
onto dictionary a
. If a key does not exist in a
but does in b
, it is inserted into a
with b
's value. If a key does exist in a
and b
, the value in b
is only inserted into a
if the overwrite
argument is true
. If a key does exist both in a
and b
and both values are of type dictionary they will be recursively merged with this same function.
a:
Dictionary a
b:
Dictionary b
Whether to override an entry in a
that also exists in b
with the value in b
.
measure
measure() -> vector
Measures the size of some content in canvas coordinates.
as-padding-dict
as-padding-dict() -> dictionary
Get a padding/margin dictionary with keys (top, left, bottom, right)
from a padding value.
Type of padding
:
- none: All sides padded by 0
- number: All sides are padded by the same value
- array: CSS like padding:
(y, x)
,(top, x, bottom)
or(top, right, bottom, left)
- dictionary: Converts a Typst padding dictionary (top, left, bottom, right, x, y, rest) to a dictionary containing top, left, bottom and right.
padding:
Padding specification
as-corner-radius-dict
as-corner-radius-dict() -> dictionary
Creates a corner-radius dictionary with keys north-east
, north-west
, south-east
and south-west
with values of a two element array of the radius in the x
and y
direction. Returns none if all radii are zero or none.
radii:
The radius specification. A number will cause all corners to have the same radius. An array with two items will cause all corners to have the same rx and ry radius. A dictionary can be given where the key specifies the corner and the value specifies the radius. The value can be either number for a circle radius or array for an x and y radius. The keys north
, south
, east
and west
targets both corners in that cardinal direction e.g. south
sets the south west and south east corners. The keys north-east
, north-west
, south-east
and south-west
targets the corresponding corner. The key rest
targets all other corners that have not been target by other keys.
sort-points-by-distance
sort-points-by-distance() -> array
Sorts an array of vectors by distance to a common position.
resolve-stroke
resolve-stroke() -> dictionary
Resolves a stroke into a usable dictionary with all fields that are missing or auto set to their Typst defaults.
assert-body
assert-body(body: ,)
Asserts whether a "body" has the correct type.