Skip to main content

Constraint built-ins

Constraints relate Float expressions; the solver finds geometry that satisfies them.

float

float() -> Float

Creates a new solver variable.

Use it for a value you want to name now and constrain later.

Returns Float. A variable with no constraints on it yet.

let center = float();
eq(center, (bounds.x0 + bounds.x1) / 2.);

eq

eq(left: Float, right: Float) -> ()

Constrains two linear expressions to be equal.

ArgumentTypeRequirementDescription
leftFloatRequired, positionalOne side of the equality: a literal, parameter, geometry field, or linear combination of them.
rightFloatRequired, positionalThe other side.

Returns (). Nothing; the constraint is added to the current cell.

eq(inner.x0, outer.x0 + inset);
eq(inner.w, outer.w - 2. * inset);

Conflicting constraints are reported when the cell runs.

dimension

dimension(p: Float, n: Float, value: Float, coord: Float, pstop: Float, nstop: Float, horizontal: Bool) -> ()

Adds an equality constraint together with the dimension label the GUI draws for it.

ArgumentTypeRequirementDescription
pFloatRequired, positionalCoordinate on the positive side of the measurement.
nFloatRequired, positionalCoordinate on the negative side.
valueFloatRequired, positionalThe constraint: p - n must equal this.
coordFloatRequired, positionalWhere the dimension line sits, on the perpendicular axis.
pstopFloatRequired, positionalWhere the extension line on the positive side ends.
nstopFloatRequired, positionalWhere the extension line on the negative side ends.
horizontalBoolRequired, positionaltrue for a horizontal measurement, false for vertical.

Returns (). Nothing; the constraint and its label are added to the current cell.

Prefer the GUI for dimensions

The Dimension tool fills in the orientation and label-placement arguments from the edges you click. In hand-written source, use eq unless you want a visible dimension.