Skip to main content

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.

transform:

The 4×44 \times 4 transformation matrix or a function that accepts and returns a vector.

..vecs:

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

transform:

Transformation matrix

Vector to be transformed

line-pt

line-pt() -> vector 

Linearly interpolates between two points and returns its position

Start point

End point

Position on the line [0,1][0, 1]

line-normal

line-normal() -> vector 

Get orthogonal vector to line

Start point

End point

circle-arclen

circle-arclen() -> float 

Calculates the arc-length of a circle or arc

radius:

Circle or arc radius

angle:

Default: 360deg

The angle of the arc.

ellipse-point

ellipse-point() -> vector 

Get point on an ellipse for an angle

center:

Center

radius:

Radius or tuple of x/y radii

angled:

Angle to get the point at

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.

Point 1

Point 2

Point 3

resolve-number

resolve-number() -> float 

Converts a number to "canvas units"

The current context object.

The number to resolve.

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.

Dictionary a

Dictionary b

overwrite:

Default: true

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.

The current context object.

The content to measure.

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.

The current canvas context object

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.

size:

I'm not sure what this does.

sort-points-by-distance

sort-points-by-distance() -> array 

Sorts an array of vectors by distance to a common position.

base:

The position to measure the distance of the other vectors from.

The array of vectors to sort.

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.

stroke:

The stroke to resolve.

assert-body

assert-body(
body: ,
)

Asserts whether a "body" has the correct type.