Skip to main content

Anchor

Functions to aid in anchor creation when defining custom elements.

border

border() -> vector or none 

Calculates a border anchor at the given angle by testing for an intersection between a line and the given drawables. Returns none if no intersection is found for better error reporting.

center:

The position from which to start the test line.

x-dist:

The furthest distance the test line should go in the x direction.

y-dist:

The furthest distance the test line should go in the y direction.

drawables:

Drawables to test for an intersection against. Ideally should be of type path but all others are ignored.

angle:

The angle to check for a border anchor at.

setup

setup() -> array 

Setup an anchor calculation and handling function for an element. Unifies anchor error checking and calculation of the offset transform.

A tuple of a transformation matrix and function will be returned. The transform is calculated by translating the given transform by the distance between the position of offset-anchor and default. It can then be used to correctly transform an element's drawables. If either are none the calculation won't happen but the transform will still be returned. The function can be used to get the transformed anchors of an element by passing it a string. An empty array can be passed to get the list of valid anchors.

callback:

The function to call to get a named anchor's position. The anchor's name will be passed and it should return a vector (str => vector). If no named anchors exist on the element auto can be given instead of a function.

anchor-names:

A list of valid anchor names. This list will be used to validate an anchor exists before callback is used.

default:

str or none
Default: none

The name of the default anchor, if one exists.

transform:

Default: none

The current transformation matrix to apply to an anchor's position before returning it. If offset-anchor and default is set, it will be first translated by the distance between them.

name:

str or none
Default: none

The name of the element, this is only used in the error message in the event an anchor is invalid.

offset-anchor:

str or none
Default: none

The name of an anchor to offset the transform by.

border-anchors:

Default: false

If true, add border anchors.

path-anchors:

Default: false

If true, add path anchors.

radii:

Default: none

Radius tuple used for border anchor calculation.

path:

Default: none

Path used for path and border anchor calculation.