Skip to main content

Standard library

The std module is written in Argon itself. Call its functions with the std:: prefix.

std::max

std::max(x0: Float, x1: Float) -> Float

Returns the greater of two floats.

ArgumentTypeRequirementDescription
x0FloatRequiredFirst value.
x1FloatRequiredSecond value.

Returns Float. x1 when x0 < x1; otherwise x0.

std::min

std::min(x0: Float, x1: Float) -> Float

Returns the lesser of two floats.

ArgumentTypeRequirementDescription
x0FloatRequiredFirst value.
x1FloatRequiredSecond value.

Returns Float. x0 when x0 < x1; otherwise x1.

std::intersection

std::intersection(rect1: Rect, rect2: Rect) -> Rect

The overlap of two rectangles, as a construction rectangle.

ArgumentTypeRequirementDescription
rect1RectRequiredFirst rectangle.
rect2RectRequiredSecond rectangle.

Returns Rect. A construction rectangle whose lower edges are the larger of the two inputs' and whose upper edges are the smaller.

If the rectangles don't overlap, the result is inverted rather than empty: this computes edge expressions and doesn't test for overlap.

std::union

std::union(rect1: Rect, rect2: Rect) -> Rect

The smallest construction rectangle containing both inputs.

ArgumentTypeRequirementDescription
rect1RectRequiredFirst rectangle.
rect2RectRequiredSecond rectangle.

Returns Rect. A construction rectangle from the smaller lower edges and the larger upper edges.

std::array

std::array(r: Rect, n: Int, xpitch: Float, ypitch: Float) -> Rect

Draws a row of rectangles and returns its bounds.

ArgumentTypeRequirementDescription
rRectRequiredTemplate. Each copy has its layer, width, and height.
nIntRequiredNumber of copies. Below one, the result is a zero-size rectangle.
xpitchFloatRequiredx pitch between copies.
ypitchFloatRequiredy pitch between copies.

Returns Rect. A construction rectangle around the row.

std::array2

std::array2(r: Rect, nx: Int, ny: Int, xpitch: Float, ypitch: Float) -> Rect

Draws a grid of rectangles and returns its bounds.

ArgumentTypeRequirementDescription
rRectRequiredTemplate, copied at every position.
nxIntRequiredNumber of columns.
nyIntRequiredNumber of rows.
xpitchFloatRequiredx pitch.
ypitchFloatRequiredy pitch.

Returns Rect. A construction rectangle around the grid.

std::max_array

std::max_array(r: Rect, w: Float, h: Float, xpitch: Float, ypitch: Float) -> Rect

Draws the largest grid of rectangles that fits in a given width and height.

ArgumentTypeRequirementDescription
rRectRequiredTemplate.
wFloatRequiredAvailable width.
hFloatRequiredAvailable height.
xpitchFloatRequiredx pitch.
ypitchFloatRequiredy pitch.

Returns Rect. The bounds from std::array2, or a zero-size rectangle if nothing fits.

std::eq_rect

std::eq_rect(r1: Rect, r2: Rect) -> ()

Constrains two rectangles to coincide.

ArgumentTypeRequirementDescription
r1RectRequiredFirst rectangle.
r2RectRequiredSecond rectangle.

Returns (). Nothing; four edge constraints are added.

std::center_rects

std::center_rects(r1: Rect, r2: Rect) -> ()

Constrains two rectangles to share a center.

ArgumentTypeRequirementDescription
r1RectRequiredFirst rectangle.
r2RectRequiredSecond rectangle.

Returns (). Nothing; two center constraints are added.

std::crect2rect

std::crect2rect(r: Rect) -> Rect

Draws a rectangle with the same layer and edges as a construction rectangle.

ArgumentTypeRequirementDescription
rRectRequiredThe construction rectangle. It must have a layer.

Returns Rect. The drawn rectangle.

std::Option

enum Option<T> {
Some(T),
None,
}

A value that may be absent. Option, Some, and None are in scope in every module without a use. A cell parameter typed Option<Int> with a None default is optional, and a struct field typed Option<Node> lets a struct contain itself. Take an Option apart with match:

fn count(n: Option<Int>) -> Int {
match n {
Some(value) => value,
None => 1,
}
}

std::is_some

std::is_some<T>(o: Option<T>) -> Bool

Whether an option holds a value.

ArgumentTypeRequirementDescription
oOption<T>RequiredThe option to test.

Returns Bool. true for Some, false for None.

std::is_none

std::is_none<T>(o: Option<T>) -> Bool

Whether an option is empty.

ArgumentTypeRequirementDescription
oOption<T>RequiredThe option to test.

Returns Bool. true for None, false for Some.

std::unwrap_or

std::unwrap_or<T>(o: Option<T>, default: T) -> T

The value inside an option, or a default.

ArgumentTypeRequirementDescription
oOption<T>RequiredThe option to unwrap.
defaultTRequiredThe value returned for `None`.

Returns T. The payload of Some, or default.

std::first

std::first<T>(items: [T]) -> Option<T>

Returns the first element of a sequence, if it has one.

ArgumentTypeRequirementDescription
items[T]RequiredAny sequence.

Returns Option<T>. Some of the first element, or None for an empty sequence.

std::last

std::last<T>(items: [T]) -> T

Returns the last element of a sequence.

ArgumentTypeRequirementDescription
items[T]RequiredA non-empty sequence.

Returns T. The last element, with the sequence's element type.

std::range

std::range(stop: Int) -> [Int]

Returns the integers from 0 up to stop.

ArgumentTypeRequirementDescription
stopIntRequiredExclusive upper bound.

Returns [Int]. Integers from zero up to, but not including, stop.

for index in std::range(4) {
// index is 0, 1, 2, then 3
}