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.
Returns Float. x1 when x0 < x1; otherwise x0.
std::min
std::min(x0: Float, x1: Float) -> Float
Returns the lesser of two floats.
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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
rect1 | Rect | Required | First rectangle. |
rect2 | Rect | Required | Second 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
rect1 | Rect | Required | First rectangle. |
rect2 | Rect | Required | Second 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
r | Rect | Required | Template. Each copy has its layer, width, and height. |
n | Int | Required | Number of copies. Below one, the result is a zero-size rectangle. |
xpitch | Float | Required | x pitch between copies. |
ypitch | Float | Required | y 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
r | Rect | Required | Template, copied at every position. |
nx | Int | Required | Number of columns. |
ny | Int | Required | Number of rows. |
xpitch | Float | Required | x pitch. |
ypitch | Float | Required | y 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
r | Rect | Required | Template. |
w | Float | Required | Available width. |
h | Float | Required | Available height. |
xpitch | Float | Required | x pitch. |
ypitch | Float | Required | y 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.
Returns (). Nothing; four edge constraints are added.
std::center_rects
std::center_rects(r1: Rect, r2: Rect) -> ()
Constrains two rectangles to share a center.
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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
r | Rect | Required | The 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
o | Option<T> | Required | The 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
o | Option<T> | Required | The 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
o | Option<T> | Required | The option to unwrap. |
default | T | Required | The 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
items | [T] | Required | Any 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
items | [T] | Required | A 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.
| Argument | Type | Requirement | Description |
|---|---|---|---|
stop | Int | Required | Exclusive 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
}