construction.concrete-volume
Concrete for slabs, strip footings, pads and round columns: volume to the litre and an order rounded up to 0.1 m³.
1.0.0 · published 2026-10-03 by charlie · Anterra
Pinned by 19 tests, run in TypeScript, Python and Rust.
What it does
How much concrete a set of pours needs, and how much to order from the ready-mix plant. Each element is a slab, strip footing or pad (a rectangular box: length × width × depth) or a round column (π d² / 4 × height), with a count for identical ones.
## How it is worked out
For example
concrete_volume(elements ×1, 0%)→ element cubic metres 2, cubic metres 2, order cubic metres 2 a 5 by 4 metre slab 100 mm thick is 2 cubic metresconcrete_volume(elements ×1, 5%)→ element cubic metres 2.592, cubic metres 2.592, order cubic metres 2.8 a garage slab with 5 percent wastage orders up to the next tenthconcrete_volume(elements ×1, 0%)→ element cubic metres 1.688, cubic metres 1.688, order cubic metres 1.7 a strip footing lands on half a litre and rounds half up
The function
The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.
pub fn concrete_volume(elements: &[ConcreteElement], wastage_basis_points: i64) -> ConcreteVolume
| elements | ConcreteElement[] | the pours; at least one |
| wastage_basis_points | int | spillage, over-dig and uneven sub-base, 500 = 5%; 0 to 10000 |
| returns | ConcreteVolume | exact volume, and what to order from the plant |
The types it declares, generated into your project
// ConcreteElementKind is a string in Rust, one of: "slab", "strip-footing", "pad", "column".
// Parameters take it as &str and results hold it as String.
/// One pour, or several identical ones. Dimensions in metres, taken to the nearest millimetre.
#[derive(Debug, Clone, PartialEq)]
pub struct ConcreteElement {
pub kind: String,
/// slab, strip-footing, pad: length
pub length: Option<f64>,
/// slab, strip-footing, pad: width
pub width: Option<f64>,
/// slab, strip-footing, pad: thickness or depth
pub depth: Option<f64>,
/// column: diameter
pub diameter: Option<f64>,
/// column: height
pub height: Option<f64>,
/// how many identical elements, 1 or more
pub count: i64,
}
/// The volume, element by element, and the order quantity.
#[derive(Debug, Clone, PartialEq)]
pub struct ConcreteVolume {
/// each element times its count, to the nearest litre (3 dp)
pub element_cubic_metres: Vec<f64>,
/// the total, to the nearest litre (3 dp)
pub cubic_metres: f64,
/// with wastage, rounded up to the next 0.1 m³
pub order_cubic_metres: f64,
}
Your code names it in one line, in the file that uses it
fune!(construction.concrete-volume@^1); // then call concrete_volume(…)
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
use super::funejson::Value; ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
use super::math_round_div::round_div; ← from math.round-div ^1.0.0 · built alongside by fune
use super::math_round_float::round_float; ← from math.round-float ^1.0.0 · built alongside by fune
const MAX_SAFE: i128 = 9_007_199_254_740_991;
const MM3_PER_LITRE: i64 = 1_000_000;
const PI: f64 = 3.141592653589793;
fn millimetres(element: usize, name: &str, value: Option<f64>) -> i64 {
let v = match value {
Some(v) if v.is_finite() && v > 0.0 && v <= 1000.0 => v,
Some(v) => panic!(
"element {}: {} must be a finite number greater than 0 and at most 1000 metres, received {}",
element, name, v
),
None => panic!(
"element {}: {} must be a finite number greater than 0 and at most 1000 metres, received null",
element, name
),
};
let mm = (round_float(v, 3) * 1000.0).round() as i64;
if mm < 1 {
panic!("element {}: {} must be at least 1 millimetre, received {}", element, name, v);
}
mm
}
fn too_large() -> ! {
panic!("the total volume is too large (more than 9 million cubic metres)");
}
/// Concrete volume for a set of pours, and the quantity to order.
///
/// Dimensions are taken to the nearest millimetre and rectangular volumes are
/// exact integers of cubic millimetres; a round column is pi d^2 / 4 h in
/// floating point, rounded to a whole cubic millimetre. Working in metres and
/// rounding up the float is the naive way: 3 x 1 x 0.1 is 0.30000000000000004,
/// which orders 0.4 m3.
///
/// # Panics
/// Panics on an empty list, a missing or out-of-range dimension, a count
/// below 1, wastage outside 0..=10000, or a total beyond 2^53 - 1 mm3.
pub fn concrete_volume(elements: &[ConcreteElement], wastage_basis_points: i64) -> ConcreteVolume {
if elements.is_empty() {
panic!("elements must not be empty");
}
if !(0..=10000).contains(&wastage_basis_points) {
panic!("wastageBasisPoints must be a whole number from 0 to 10000, received {}", wastage_basis_points);
}
let mut volumes: Vec<f64> = Vec::with_capacity(elements.len());
let mut total: i128 = 0;
for (i, el) in elements.iter().enumerate() {
let n = i + 1;
if el.count < 1 {
panic!("element {}: count must be a whole number of at least 1, received {}", n, el.count);
}
let one: i128 = match el.kind.as_str() {
"slab" | "strip-footing" | "pad" => {
if el.length.is_none() || el.width.is_none() || el.depth.is_none() {
panic!("element {}: {} needs length, width and depth", n, el.kind);
}
millimetres(n, "length", el.length) as i128
* millimetres(n, "width", el.width) as i128
* millimetres(n, "depth", el.depth) as i128
}
"column" => {
if el.diameter.is_none() || el.height.is_none() {
panic!("element {}: column needs diameter and height", n);
}
let d = millimetres(n, "diameter", el.diameter) as f64;
let h = millimetres(n, "height", el.height) as f64;
round_float(((PI * d * d) / 4.0) * h, 0) as i128
}
other => panic!("element {}: unknown kind \"{}\"", n, other),
};
// i128 could carry on, but TypeScript cannot, and all three must agree.
if one > MAX_SAFE {
too_large();
}
let volume = one * el.count as i128;
if volume > MAX_SAFE {
too_large();
}
total += volume;
if total > MAX_SAFE {
too_large();
}
volumes.push(round_div(volume as i64, MM3_PER_LITRE, "half-up") as f64 / 1000.0);
}
let total = total as i64;
// Up to the whole litre, add the wastage, then up to the next 100 litres.
let litres_up = round_div(total, MM3_PER_LITRE, "up");
let tenths = round_div(litres_up * (10000 + wastage_basis_points), 100 * 10000, "up");
ConcreteVolume {
element_cubic_metres: volumes,
cubic_metres: round_div(total, MM3_PER_LITRE, "half-up") as f64 / 1000.0,
order_cubic_metres: tenths as f64 / 10.0,
}
}
fn optional_float(v: &Value) -> Option<f64> {
if v.is_null() {
None
} else {
Some(v.as_f64())
}
}
pub fn concrete_element_from_value(v: &Value, index: usize) -> ConcreteElement {
if let Value::Float(f) = v.get("count") {
panic!("element {}: count must be a whole number of at least 1, received {}", index + 1, f);
}
ConcreteElement {
kind: v.get("kind").as_str().to_string(),
length: optional_float(v.get("length")),
width: optional_float(v.get("width")),
depth: optional_float(v.get("depth")),
diameter: optional_float(v.get("diameter")),
height: optional_float(v.get("height")),
count: v.get("count").as_i64(),
}
}
pub fn concrete_volume_to_value(c: &ConcreteVolume) -> Value {
Value::obj(vec![
("elementCubicMetres", Value::Arr(c.element_cubic_metres.iter().map(|&v| Value::Float(v)).collect())),
("cubicMetres", Value::Float(c.cubic_metres)),
("orderCubicMetres", Value::Float(c.order_cubic_metres)),
])
}
pub fn fune_vector(args: &[Value]) -> Value {
let elements: Vec<ConcreteElement> = args[0]
.as_arr()
.iter()
.enumerate()
.map(|(i, v)| concrete_element_from_value(v, i))
.collect();
if let Value::Float(f) = &args[1] {
panic!("wastageBasisPoints must be a whole number from 0 to 10000, received {}", f);
}
concrete_volume_to_value(&concrete_volume(&elements, args[1].as_i64()))
}Install
fune build
With that line in your source, in a Rust project (language rust in fune.project), fune build resolves it and its 2 dependencies, pins them in fune.lock, downloads only the Rust package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. A crate’s build.rs runs it before every compile. Or pin a range in fune.project and build in one step:
fune add construction.concrete-volume
The manifest, vectors and README with only the Rust implementation. Install it without the registry with fune add ./construction.concrete-volume-1.0.0-rust.fune, or fetch it from a terminal with fune pull construction.concrete-volume@1.0.0:rust.
The whole function, every language, is one file too: construction.concrete-volume-1.0.0.fune, 28,439 bytes, sha256 7bd20fa333b6f2473a9d63e4ad8ae997aa56a8f1d89f9c2115c7f5506c054920. It installs into a project of any language.
Customise it in your app
The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.
before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.
// fune: before construction.concrete-volume
after — your function gets the result and the arguments, and returns the final result.
// fune: after construction.concrete-volume
replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.
// fune: replace math.round-div in construction.concrete-volume
// fune: replace math.round-float in construction.concrete-volume
step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show construction.concrete-volume --steps.
// fune: step construction.concrete-volume after <n|label>
Tests
A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.
| Case | Arguments | Expected | |
|---|---|---|---|
| a 5 by 4 metre slab 100 mm thick is 2 cubic metres | elements ×1, 0% | → | element cubic metres 2, cubic metres 2, order cubic metres 2 |
| a garage slab with 5 percent wastage orders up to the next tenth | elements ×1, 5% | → | element cubic metres 2.592, cubic metres 2.592, order cubic metres 2.8 |
| a strip footing lands on half a litre and rounds half up | elements ×1, 0% | → | element cubic metres 1.688, cubic metres 1.688, order cubic metres 1.7 |
| four identical pads | elements ×1, 0% | → | element cubic metres 2, cubic metres 2, order cubic metres 2 |
| a 300 mm round column 3 m high | elements ×1, 0% | → | element cubic metres 0.212, cubic metres 0.212, order cubic metres 0.3 |
| a slab and four columns, with 10 percent wastage | elements ×2, 10% | → | element cubic metres 0.9, 0.471, cubic metres 1.371, order cubic metres 1.6 |
| 3 by 1 by 0.1 is 0.3 exactly, not the 0.4 a float ceiling orders | elements ×1, 0% | → | element cubic metres 0.3, cubic metres 0.3, order cubic metres 0.3 |
| exactly a tenth orders a tenth | elements ×1, 0% | → | element cubic metres 0.1, cubic metres 0.1, order cubic metres 0.1 |
| a litre over a tenth orders the next tenth | elements ×1, 0% | → | element cubic metres 0.101, cubic metres 0.101, order cubic metres 0.2 |
| dimensions are taken to the nearest millimetre | elements ×2, 0% | → | element cubic metres 2.001, 2, cubic metres 4.001, order cubic metres 4.1 |
Show the other 9 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| 100 percent wastage doubles the order | elements ×1, 100% | → | element cubic metres 0.54, cubic metres 0.54, order cubic metres 1.1 |
| an empty list is an error | , 0% | → | error: elements must not be empty |
| a slab without a width is an error | elements ×1, 0% | → | error: element 1: slab needs length, width and depth |
| a column without a height is an error | elements ×2, 0% | → | error: element 2: column needs diameter and height |
| a negative depth is an error | elements ×1, 0% | → | error: element 1: depth must be a finite number greater than 0 and at most 1000 metres |
| a dimension under half a millimetre is an error | elements ×1, 0% | → | error: element 1: depth must be at least 1 millimetre |
| a count of zero is an error | elements ×1, 0% | → | error: element 1: count must be a whole number of at least 1 |
| negative wastage is an error | elements ×1, -0.01% | → | error: wastageBasisPoints must be a whole number from 0 to 10000 |
| a volume beyond 2^53 cubic millimetres is an error | elements ×1, 0% | → | error: the total volume is too large |
More from the author
1. Every dimension, given in metres, is taken to the nearest millimetre. 2. A rectangular element is an exact integer of cubic millimetres. A column is `π × d × d / 4 × h` in floating point, evaluated in that order in every language and rounded to a whole cubic millimetre (`math.round-float`). Then times the count. 3. `elementCubicMetres` and `cubicMetres` are those, and their total, to the nearest litre (half up), shown in m³ to 3 decimal places. The total is rounded once, not summed from the rounded elements. 4. The order: the total rounded **up** to a whole litre, plus wastage, then **up** to the next 0.1 m³, the smallest step most plants sell in.
Working in metres and rounding the float up is the naive way and orders too much: 3 × 1 × 0.1 is 0.30000000000000004 in floating point, which a ceiling to the tenth turns into 0.4 m³.
## What it does not do
It does not add wastage for you (typically 5-10% for foundations poured into trenches, less for formed slabs; that is the caller's call), deduct reinforcement, work out the trench volume for an uneven formation, or know a plant's minimum load. Other shapes (a stepped footing, a ramp) are several rectangular elements.
Limits: each dimension more than 0 and at most 1000 m, and at least 1 mm after rounding; count 1 or more; wastage 0 to 10,000 basis points; the total at most 2^53 − 1 mm³ (about 9 million m³), beyond which JavaScript integers stop being exact and the calculation is refused. A slab, footing or pad needs length, width and depth; a column needs diameter and height; other fields are ignored.
Files
| Path | Bytes |
|---|---|
| README.md | 1,923 |
| impl/python.py | 3,891 |
| impl/rust.rs | 5,650 |
| impl/typescript.ts | 3,715 |
| vectors.json | 8,185 |