Skip to main content

rect

rect() 

Draws a rectangle between two coordinates.

Styling

Root: rect

Anchors

Supports border and path anchors. It’s default is the "center" anchor.

// Draw a rect from A(0, 0) to B(1, 1)
rect((0, 0), (1, 1))

// Show the points
set-style(content: (frame: "circle", padding: 1pt, fill: white))
content((0, 0), [A]); content((1, 1), [B])
rect((0,0), (rel: (1,1)), radius: 0)
rect((2,0), (rel: (1,1)), radius: 25%)
rect((4,0), (rel: (1,1)), radius: (north: 50%))
rect((6,0), (rel: (1,1)), radius: (north-east: 50%))
rect((8,0), (rel: (1,1)), radius: (south-west: 0, rest: 50%))
rect((10,0), (rel: (1,1)), radius: (rest: (20%, 50%)))

Coordinate of the bottom left corner of the rectangle.

Coordinate of the top right corner of the rectangle. You can draw a rectangle with a specified width and height by using relative coordinates for this parameter (rel: (width, height)).

name:

none or str

anchor:

none or str

..style:

radius:

Default: 0

The rectangle’s corner radius. If set to a single number, that radius is applied to all four corners of the rectangle. If passed a dictionary you can set the radii per corner. The following keys support either a type:number, type:ratio or an array of type:number or type:ratio for specifying a different x- and y-radius: north, east, south, west, north-west, north-east, south-west and south-east. To set a default value for remaining corners, the rest key can be used. Ratio values are relative to the rectangle’s width and height.