Surface drainage and earthwork
All calculations in @tilemapper/earthwork are pure, deterministic, and read elevations strictly from the original ground DEM (surface: "original"). Surface features are saved with the project in public.project_surface_features (Plan v3 item 394, finishing Plan v2 item 283) — one row per feature keyed by (project_id, id) with a revision counter for optimistic concurrency — completely separate from scenarios and the subsurface tile network. Features previously kept in browser localStorage move into Postgres once per project on first open, keeping the browser copy intact until the server confirms the batch insert (ON CONFLICT (project_id, id) DO NOTHING), and upgrading pre-item-396 culverts without inventing end levels. Adding or editing any ditch, culvert, graded plane, dam, levee, pad, or measured pile or pit — including a ditch passing through a tile outlet — leaves every subsurface tile result, cover check, fingerprint, and benchmark hash unchanged; accepting a ditch's proposed outlet invert is an explicit, named, undoable edit in the tile network's history that moves the fingerprint (Plan v3 item 401).
Every quantity produced by this module is a preliminary planning estimate and is never construction-ready. Public lidar is typically QL1/QL2 (10 cm vertical RMSEz), which is coarser than the 0.1 ft (3 cm) vertical tolerance required for land-leveling construction staking; every report states the terrain's stated vertical accuracy beside its quantities.
1. Trapezoidal ditches (items 284–286, 289)
A ditch follows a polyline centerline sampled at uniform station increments Δs.
- Geometry: Bottom width
b, symmetric side slopesz:1(horizontal:vertical), minimum depthd_min, and uniform design gradeS ≥ 0falling in the active flow direction (reversible by reversing the centerline). - Design invert: Anchored from the upstream end at
z_inv(0) = min_s(z_ground(s) - d_min + S × s)soz_ground(s) - z_inv(s) ≥ d_mineverywhere while falling at gradeS. Cut depth at stationsish(s) = max(0, z_ground(s) - z_inv(s)). - Top width and excavation:
T(s) = b + 2 × z × h(s)A(s) = (b + z × h(s)) × h(s)- Excavation volume uses the average-end-area prism formula
V = Σ ((A_i + A_(i+1)) / 2) × Δs, converted to cubic yards (1 yd³ = 0.764554857984 m³).
- Manning's capacity: At minimum design depth
y = d_minwith user-entered Manning's roughnessn(USDA NRCS NEH Part 650, Ch. 7; Chow, Open-Channel Hydraulics, 1959):A = (b + z × y) × yP = b + 2 × y × √(1 + z²)R = A / PQ = (1 / n) × A × R^(2/3) × S^(1/2)
- Contributing area (item 286): Upstream drainage area in acres is delineated from the conditioned D8 flow-direction grid at the ditch's downstream outlet.
- Tile outlet into a designed ditch (item 289, finished by plan v3 item 397): An outlet placed within 15 m of a designed ditch shows the designed ditch bed elevation at the outlet's place on the ditch, the nearest point of its line, read off the bed's grade line between the two stations around it (round 7 of plan v4: it had been the bed at the nearest station), and the clearance limit: the tile outlet's invert must sit at least an entered clearance above the ditch bed and at least an entered clearance above normal low water (
z_proposed = max(z_bed + c_bed, z_low_water + c_low_water)). Both clearances are entered values with no default; with either clearance or normal low water missing, no invert is proposed. Where the ditch has missing ground anywhere along its line, nothing is offered. The outlet card always states that the designed ditch is not built yet, and nothing is written to the tile network until the user explicitly accepts the proposed invert as a named edit ("Set outlet invert from designed ditch", throughholdOutletInvert), which updates the outlet invert and arriving pipe grade breaks, is undoable, and changes the design's fingerprint.
Reference case (hand-worked)
- Straight 100 m ditch on flat ground (
z_ground = 300 m),b = 2 m,z = 3,d_min = 1 m,S = 0:- Constant
h = 1 m,T = 2 + 2(3)(1) = 8 m,A = (2 + 3(1))(1) = 5 m². - Excavation
V = 5 × 100 = 500 m³ = 653.975 yd³. - At
S = 0.002,y = 1 m,n = 0.035:P = 2 + 2√10 = 8.324555 m,R = 5 / 8.324555 = 0.600633 m,Q = (1 / 0.035) × 5 × (0.600633)^(2/3) × (0.002)^(1/2) = 4.548 m³/s ≈ 160.6 cfs. - Tile outlet on the designed ditch: Ditch bed
z_bed = 299.00 m. Withz_low_water = 299.20 m, entered bed clearancec_bed = 0.30 m(299.00 + 0.30 = 299.30 m), and entered low-water clearancec_low_water = 0.25 m(299.20 + 0.25 = 299.45 m), the proposed invert ismax(299.30, 299.45) = 299.45 m(governed by normal low water). Withc_bed = 0.60 m(299.60 m) andc_low_water = 0.10 m(299.30 m), the proposed invert is299.60 m(governed by the ditch bed). With either clearance omitted, no invert is proposed. - An outlet between stations: On flat ground at 300 m with
d_min = 1 m, the bed starts at299.00 mand falls atS = 0.02; stations are 5 m apart. An outlet on the line 3 m down the ditch takes the bed there,299.00 - 0.02 × 3 = 298.94 m, not the298.90 mof the station 2 m away. Withc_bed = 0.30 m,c_low_water = 0.10 mand normal low water at298.50 m, the proposed invert ismax(299.24, 298.60) = 299.24 m. An outlet 2 m to one side of the line, 12.5 m along it, is projected square onto it: bed299.00 - 0.25 = 298.75 m, 2 m away.
- Constant
2. Culverts (items 287–288, plan v3 items 395–396)
- Hydrologic routing of ponded water (item 287, finished by plan v3 item 395): A culvert placed across a road or berm drains the 4-connected ponded area containing its inlet through to its outlet on copies of the stored
flow_dirandfill_depthgrids (applyCulvertsToHydrologyin@tilemapper/surface, recomputed in the browser while leaving the stored terrain grids and all subsurface tile calculations untouched; with zero culverts in force, the stored grids are returned unchanged bit for bit):- Storage reduction: Priority-Flood runs inside the inlet's ponded depression down to the entered inlet invert where one is provided, or down to the original DEM ground elevation at the inlet cell where none is entered (stated on the culvert card as a lidar ground reading, not a measured pipe bottom). Fill depth is never raised above the depression's natural spill depth, and internal ridges inside a compound depression are respected.
- Capacity does not limit routing: All water reaching the inlet is passed to the outlet regardless of barrel diameter or headwater; the culvert card states this beside the HDS-5 capacity figure so routing is never read as a claim the pipe can carry the flow.
- Circle refusal: Any culvert whose outlet sits inside or flows back into the inlet's ponded area, the inlet cell, or the culvert corridor (or closes a loop with another culvert) is refused with an explanation, left out of routing, and excluded from
culvertsInForce. - Multiple culverts: Valid culverts are evaluated in a canonical order independent of drawing order (ascending drain elevation, then inlet row, inlet col, outlet row, outlet col, id), and culverts sharing one original depression drain it simultaneously via multi-source Priority-Flood.
- Downstream effects: Raindrop paths, watersheds (with per-cell outside run-on entries), listed low spots and their areas, ditch drainage areas, and the rain comparison on both sides of the road all recompute from the routed grids. See
surface-water.mdsection 4 for the hand-worked six-term balance case.
- Hydraulic capacity (item 288, finished by plan v3 item 396): Computes circular culvert capacity as the lesser of inlet control and outlet control from the elevations at both ends — inlet invert
Z_in, outlet invertZ_out, headwaterEL_hw, tailwaterEL_tw, road crestEL_crest, and the circular inlet edge type — using FHWA Hydraulic Design Series No. 5 (HDS-5), 3rd Edition, April 2012 (FHWA-HIF-12-026) (https://www.fhwa.dot.gov/engineering/hydraulics/pubs/12026/hif12026.pdf). - Guards before computing a figure:
- If any required input (
diameterM,lengthMor endpoint distance,inletEdgeType,manningN,inletInvertM,outletInvertM,headwaterM,tailwaterM,roadCrestM) is missing, the engine returnscomputed: false("not worked out") and no figure. - If headwater sits below the top (crown) of the inlet (
EL_hw - Z_in < D), the inlet is not submerged and the engine returns no full-barrel figure (computed: false; HDS-5 Section 3.3.3, p. 3.24 [PDF p. 106]). - If headwater sits at or below tailwater (
EL_hw ≤ EL_tw), there is no forward driving head and no figure is returned. - If headwater exceeds the road crest (
EL_hw > EL_crest), the result flagsroadOvertops: trueand states the overtopping depth; roadway weir overflow (HDS-5 Eq. 3.9) is not included in the barrel capacity.
- If any required input (
- Unit system: The engine stores culvert geometry and elevations in SI meters and evaluates the HDS-5 equations in their SI form (
K_u = 1.811for inlet control, p. A.2 [PDF p. 191];K_U = 19.63for outlet control, p. 3.10 [PDF p. 92];g = 9.80665 m/s²). An optional{ unitSystem: "US" }mode evaluates the US customary constants (K_u = 1.0,K_U = 29,g = 32.174 ft/s²) and tests verify both forms agree within 0.2% (the rounding of1.811vs√(1/0.3048)and19.63vs29 × 0.3048^(1/3)). - Inlet control (HDS-5 Appendix A, pp. A.1–A.3 & Table A.1, p. A.8 [PDF pp. 190–192, 197]):
- With full barrel area
A = π D² / 4, barrel slopeS = (Z_in - Z_out) / L, headwater depthHW = EL_hw - Z_in, and discharge parameterx = K_u Q / (A D^0.5): - Unsubmerged (Form 1, Eq. A.1, p. A.1 [PDF p. 190]), up to
x = 3.5(Q / (A D^0.5) = 1.93SI):HW_i / D = H_c / D + K x^M + K_s Swhere critical depthd_cand specific headH_c / D = d_c / D + y_h / (2D)come from exact circular geometry solving Eq. (A.4) and Eq. (A.5) (p. A.3 [PDF p. 192]):Q = A_p √(g A_p / T_p). - Submerged (Eq. A.3, p. A.2 [PDF p. 191]), above
x = 4.0(Q / (A D^0.5) = 2.21SI):HW_i / D = c x² + Y + K_s S - Transition zone (
3.5 < x < 4.0, judgment): HDS-5 Section A.2 (p. A.1 [PDF p. 190]) states that NBS research provided only limited information in the transition zone and defines it empirically by "drawing a curve between and tangent to the curves defined by the unsubmerged and submerged equations," while Fig. A.1 (p. A.4 [PDF p. 193]) connects them with a straight line; no closed-form transition equation is published. As a conservative engineering judgment, between(3.5, HW_unsub(3.5))and(4.0, HW_sub(4.0))the engine takesmax(HW_linear(x), HW_hermite_tangent(x))— equivalently the smaller capacity of the straight-line transition and the cubic Hermite tangent curve — and flagsinletRegime: "transition". - Circular inlet edge constants read from Table A.1 (p. A.8 [PDF p. 197]),
K_s(p. A.2 [PDF p. 191]), and Table C.2 (p. C.6 [PDF p. 216]):
- With full barrel area
| Edge type | HDS-5 Table A.1 row (p. A.8) | Form | K |
M |
c |
Y |
K_s (p. A.2) |
K_e (Table C.2, p. C.6) |
|---|---|---|---|---|---|---|---|---|
| Concrete — square edge with headwall | Chart 1, Circular Concrete, Scale 1 | 1 | 0.0098 |
2.0 |
0.0398 |
0.67 |
-0.5 |
0.5 |
| Concrete — groove end with headwall | Chart 1, Circular Concrete, Scale 2 | 1 | 0.0018 |
2.0 |
0.0292 |
0.74 |
-0.5 |
0.2 |
| Concrete — groove end projecting | Chart 1, Circular Concrete, Scale 3 | 1 | 0.0045 |
2.0 |
0.0317 |
0.69 |
-0.5 |
0.2 |
| Corrugated metal — headwall | Chart 2, Circular CM, Scale 1 | 1 | 0.0078 |
2.0 |
0.0379 |
0.69 |
-0.5 |
0.5 |
| Corrugated metal — mitered to slope | Chart 2, Circular CM, Scale 2 | 1 | 0.0210 |
1.33 |
0.0463 |
0.75 |
+0.7 |
0.7 |
| Corrugated metal — projecting | Chart 2, Circular CM, Scale 3 | 1 | 0.0340 |
1.50 |
0.0553 |
0.54 |
-0.5 |
0.9 |
| Circular — 45° beveled ring | Chart 3, Circular, Scale A | 1 | 0.0018 |
2.50 |
0.0300 |
0.74 |
-0.5 |
0.2 |
| Circular — 33.7° beveled ring | Chart 3, Circular, Scale B | 1 | 0.0018 |
2.50 |
0.0243 |
0.83 |
-0.5 |
0.2 |
- Outlet control (HDS-5 Section 3.1.4, Eq. 3.5 & 3.6b, pp. 3.10–3.12 [PDF pp. 92–94]; Section 3.3.3, p. 3.24 [PDF p. 106]):
- Hydraulic radius of a full circular pipe:
R = A / P = D / 4. - Barrel head loss (Eq. 3.5, using Manning's exact exponent
4/3, printed rounded as1.33in HDS-5):H_L = (1 + K_e + (19.63 × n² × L) / R^(4/3)) × V² / (2g) - Energy balance neglecting approach and downstream velocity heads (Eq. 3.6b,
HW_o = TW + H_L - LS):EL_hw = Z_out + h_o + H_L- Drowned outlet (
TW = EL_tw - Z_out ≥ D):h_o = TW, soH_L = EL_hw - EL_twandQ_outlet = A √(2g H_L / (1 + K_e + 19.63 n² L / R^(4/3))). - Free outlet (
TW < D):h_o = max(TW, (d_c(Q) + D) / 2)(HDS-5 pp. 3.12 & 3.24), solved forQ_outletby bisection becaused_c(Q)andH_L(Q)are both strictly increasing inQ.
- Drowned outlet (
- Hydraulic radius of a full circular pipe:
- Governing capacity:
Q = min(Q_inlet, Q_outlet), with the governing control ("inlet"or"outlet") named.
Reference cases (hand-worked)
- Outlet control, drowned outlet (existing worked example): Circular concrete groove end with headwall (
Chart 1 Scale 2:K_e = 0.2,c = 0.0292,Y = 0.74,K_s = -0.5),D = 0.6 m,L = 20 m,n = 0.013,Z_in = 100.0 m,Z_out = 100.0 m(S = 0),EL_tw = 100.6 m(TW = 0.6 m = D, drowned),EL_hw = 101.1 m(H = 0.5 m,HW = 1.1 m > D),EL_crest = 102.0 m:A = π × 0.6² / 4 = 0.282743 m²,R = 0.6 / 4 = 0.15 m,R^(4/3) = 0.079699 m^(4/3)- Friction term:
(19.63 × 0.013² × 20) / 0.079699 = 0.83250; total loss coeff:1 + 0.2 + 0.83250 = 2.03250 V = √(2 × 9.80665 × 0.5 / 2.03250) = 2.19657 m/s→Q_outlet = 0.282743 × 2.19657 = 0.62107 m³/s = 21.93 cfs- Inlet control (Eq. A.3):
HW / D = 1.1 / 0.6 = 1.83333;x = √((1.83333 - 0.74) / 0.0292) = 6.1191(> 4.0, submerged) →Q_inlet = 6.1191 × 0.282743 × √0.6 / 1.811 = 0.74000 m³/s = 26.13 cfs - Governing: outlet control,
21.93 cfs.
- Outlet control, free outlet at the same
0.5 mhead difference: Same culvert withEL_hw = 100.7 m(HW = 0.7 m > D) andEL_tw = 100.2 m(TW = 0.2 m < D, free;EL_hw - EL_tw = 0.5 m):- At
Q_outlet = 0.38862 m³/s(13.72 cfs): critical depth solving Eq. (A.5) isd_c = 0.4085 m, soh_o = max(0.2, (0.4085 + 0.6) / 2) = 0.5042 m,V = 0.38862 / 0.282743 = 1.3745 m/s,H_L = 2.03250 × 1.3745² / (2 × 9.80665) = 0.1958 m, andZ_out + h_o + H_L = 100.0 + 0.5042 + 0.1958 = 100.700 m = EL_hw. - Inlet control is in the transition zone (
16.46 cfs), so outlet control governs at13.72 cfs— substantially less than the21.93 cfsdrowned-outlet figure at the same head difference.
- At
- Inlet control (submerged, Eq. A.3): Circular concrete square edge with headwall (
Chart 1 Scale 1:K_e = 0.5,c = 0.0398,Y = 0.67,K_s = -0.5),D = 0.6 m,L = 10 m,n = 0.013,Z_in = 100.0 m,Z_out = 99.8 m(S = 0.02),EL_hw = 101.2 m(HW = 1.2 m,HW / D = 2.0),EL_tw = 100.0 m(TW = 0.2 m, free),EL_crest = 102.0 m:- Inlet control (Eq. A.3):
2.0 = 0.0398 x² + 0.67 - 0.5(0.02)→0.0398 x² = 1.34→x = √(1.34 / 0.0398) = 5.80244(> 4.0, submerged) →Q_inlet = 5.80244 × 0.282743 × √0.6 / 1.811 = 0.70171 m³/s = 24.78 cfs. - US customary check (
D = 1.96850 ft,A = 3.04342 ft²,K_u = 1.0):Q_inlet = 5.80244 × 3.04342 × √1.96850 = 24.78 cfs. - Outlet control:
K_tot = 1 + 0.5 + 19.63 × 0.013² × 10 / 0.079699 = 1.91625; atQ_outlet = 0.81931 m³/s(28.93 cfs),d_c = 0.5562 m,h_o = 0.5781 m,H_L = 0.8219 m,99.8 + 0.5781 + 0.8219 = 101.200 m = EL_hw. - Governing: inlet control,
24.78 cfs.
- Inlet control (Eq. A.3):
- Shallow headwater guard: Same
0.6 mbarrel withEL_hw = 100.03 m(HW = 0.03 m < D = 0.6 m) → returnscomputed: falseand no full-barrel figure.
3. Land leveling: best-fit planes, cut/fill, and ratio balancing (items 290–294)
- Best-fit plane: Ordinary least squares over original DEM cell centers
(x_i, y_i, z_i)inside the drawn polygon yieldsz_design(x, y) = z_0 + s_x (x - x̄) + s_y (y - ȳ), reported as slope magnitude√(s_x² + s_y²)(in %) and downhill heading (clockwise from north). Both slope and heading can be edited by the user, and(x̄, ȳ)is stored on the feature so the reference point never drifts. - Cut and fill prisms: For each valid cell of area
Δ²inside the polygon,Δz = z_orig - z_design; positive values sum to cut (V_cut) and negative magnitudes sum to fill (V_fill). On a synthetic tilted plane,V_cut = V_fill = 0identically. On a known wedge, volumes match the analytical prism formula. - Cut-to-fill ratio balancing: Soil shrink/swell ratio
R_target = V_cut / V_fillis entered by the user (never assumed as fact). BecauseV_cut(z_0)is strictly decreasing andV_fill(z_0)is strictly increasing inz_0, bisection converges to machine tolerance in 48 iterations. Splitting an area along a line balances each side independently. - Existing and design contours and 3D view (items 293, 299, plan v3 item 400): Marching squares extracts contours down to
0.1 ft (0.03048 m)on either the existing DEM or synthesized design surface. The 3D view (scene-3d.tsx) reads saved surface features directly from the shared project store (useSavedSurfaceFeatures) and draws ditches, culverts, leveling planes, ponds/dams, and contour levees straight away without requiring the Surface earthwork panel to be opened, while substituting the active grading design surface when toggled on in the earthwork panel.
Reference cases (hand-worked)
Both cases below use synthetic (made-up) geometry on a 3 × 3 grid of 10 m cells (Δ = 10 m, cell area Δ² = 100 m², total area 9 × 100 = 900 m² = 0.2224 ac) inside the 30 m × 30 m square (0, 0) to (30, 30). Cell centers lie at x ∈ {5, 15, 25} m (west to east) and y ∈ {25, 15, 5} m (north to south), with centroid (x̄, ȳ) = (15 m, 15 m). Ground elevations z_orig (in meters) are:
Row (y) |
West (x = 5 m) |
Center (x = 15 m) |
East (x = 25 m) |
|---|---|---|---|
North (25 m) |
100.40 |
100.20 |
100.00 |
Middle (15 m) |
100.15 |
100.00 |
99.85 |
South (5 m) |
99.90 |
99.80 |
99.70 |
- Tilted plane cut and fill (and OLS best-fit plane):
- Design plane:
z_0 = 100.05 mat(15, 15), downhill slope1.0%(S = 0.01 m/m) toward heading90°(due east), sos_x = -0.01,s_y = 0, andz_design(x, y) = 100.05 - 0.01 × (x - 15). This givesz_design = 100.15 matx = 5 m,100.05 matx = 15 m, and99.95 matx = 25 m. - Cell-by-cell depths (
Δz = z_orig - z_design):- North (
y = 25 m):+0.25 m,+0.15 m,+0.05 m(three cut cells). - Middle (
y = 15 m):0.00 m(on grade),-0.05 m,-0.10 m(two fill cells). - South (
y = 5 m):-0.25 m,-0.25 m,-0.25 m(three fill cells).
- North (
- Totals:
- Cut depths sum to
0.25 + 0.15 + 0.05 = 0.45 m, soV_cut = 0.45 m × 100 m² = 45.00 m³(45 / 0.764554857984 = 58.86 yd³),maxCut = 0.25 m. - Fill depths sum to
0.05 + 0.10 + 0.25 + 0.25 + 0.25 = 0.90 m, soV_fill = 0.90 m × 100 m² = 90.00 m³(90 / 0.764554857984 = 117.72 yd³),maxFill = 0.25 m. - Cut-to-fill ratio:
V_cut / V_fill = 45.00 / 90.00 = 0.50.
- Cut depths sum to
- Best-fit plane on the same 9 cells: Mean ground elevation is
z_0 = 900.00 / 9 = 100.00 m. WithΣ(x - 15)² = Σ(y - 15)² = 600 m²andΣ(x - 15)(y - 15) = 0:Σ(x - 15)(z - 100) = 10 × (299.55 - 300.45) = -9.0 m², givings_x = -9.0 / 600 = -0.015.Σ(y - 15)(z - 100) = 10 × (300.60 - 299.40) = +12.0 m², givings_y = +12.0 / 600 = +0.020.- Slope magnitude is
√((-0.015)² + (0.020)²) = 0.025 = 2.50%, and downhill heading(-s_x, -s_y) = (+0.015, -0.020)isatan2(0.015, -0.020) = 143.13°clockwise from north.
- Design plane:
- Cut-to-fill ratio balancing (
R_target = 1.25):- Starting from the
1.0%east-tilted plane in case 1 (s_x = -0.01,s_y = 0), subtract the tilt from each cell to get the relative heightsr_i = z_orig,i + 0.01 × (x_i - 15):- North:
100.30, 100.20, 100.10 m; Middle:100.05, 100.00, 99.95 m; South:99.80, 99.80, 99.80 m.
- North:
- At
z_0 = 100.00 m, cut sum is0.65 mand fill sum is0.65 m(ratio1.00). Atz_0 = 99.95 m, cut sum is0.90 mand fill sum is0.45 m(ratio2.00). Therefore the1.25root lies in(99.95, 100.00), where the 5 cells withr_i ≥ 100.00(sum500.65 m) are in cut and the 4 cells withr_i ≤ 99.95(sum399.35 m) are in fill:(500.65 - 5 z_0) = 1.25 × (4 z_0 - 399.35)500.65 - 5 z_0 = 5 z_0 - 499.187510 z_0 = 999.8375, soz_0 = 99.98375 m(lowered by0.06625 mfrom100.05 m, or0.01625 mbelow100.00 m).
- Check:
- Cut depths:
0.31625 + 0.21625 + 0.11625 + 0.06625 + 0.01625 = 0.73125 m, soV_cut = 73.125 m³(95.64 yd³). - Fill depths:
0.03375 + 3 × 0.18375 = 0.58500 m, soV_fill = 58.500 m³(76.52 yd³). - Ratio:
73.125 / 58.500 = 1.25exactly.
- Cut depths:
- Starting from the
4. Ponds, dams, and contour levees (items 295–298)
- Ring and valley dams (item 295): Given crest elevation
z_crest = z_water + freeboard, top widthW_top, and upstream/downstream slopesz_u:1andz_d:1, embankment height at stationsisH(s) = max(0, z_crest - z_ground(s))and cross-section isA(s) = (W_top + ((z_u + z_d) / 2) × H(s)) × H(s). - Stage-storage table (item 296): Integrates original DEM cells inside the pond basin at each water stage from basin floor to the level that is held (section 5), which is normal pool when the dam and the ground contain it, reporting surface area (acres) and storage volume (acre-feet and cubic yards), and comparing available pond excavation against dam embankment fill.
- Safety and permits (item 297, finished by plan v3 item 399): Every dam carries the app's own notice,
DAM_SKETCH_NOTICE("A dam drawn here is a planning sketch with estimated quantities. It cannot be marked ready to build."), which states nothing about what a law, an agency or a profession asks,constructionReady = false, and only permit notes that cite a verified primary source (title,label, andhttps://URL; notes without a source are stripped byhasPermitNoteSourceand rejected by tests):- What federal law counts as a dam: National Dam Safety Program Act — Definitions, 33 U.S.C. § 467(3) and (14), U.S. Government Publishing Office (as amended through January 4, 2025),
https://www.govinfo.gov/link/uscode/33/467(25 ft or more in height or 50 acre-feet or more maximum storage; excludes barriers ≤ 6 ft regardless of storage or ≤ 15 acre-feet regardless of height unless failure threatens life or property; non-Federal dam safety regulated by each state's dam safety agency). - What NRCS asks of an embankment pond: Conservation Practice Standard: Pond (Code 378), USDA Natural Resources Conservation Service (NRCS, NHCP), July 2022, Conditions Where Practice Applies and Criteria (pp. 378-CPS-1–6),
https://www.nrcs.usda.gov/sites/default/files/2022-09/Pond_378_NHCP_CPS_2022.pdf. - Federal and state regional notes: Supplied from
apps/web/src/lib/regional/notes.ts(documented inregional-notes.md), each with its cited statute or agency document and link. Earlier unsourced default claims (water-appropriation permits, a duplicate unsourced Swampbuster/Section 404 bullet, a universal "licensed engineer" statement on the Code 378 note, and a dam notice saying professional engineering design and dam-safety and wetland permits are required) were removed.
- What federal law counts as a dam: National Dam Safety Program Act — Definitions, 33 U.S.C. § 467(3) and (14), U.S. Government Publishing Office (as amended through January 4, 2025),
- Contour levees (item 298): Traces levee alignments along elevation contours separated by a user-entered vertical drop
Δzstarting atz_min + Δzand stepping up strictly belowz_max(capped at100levels, withlevelsCappedflagged if more are needed). Marching squares runs on cell-center quads whose four corners all lie inside the polygon, chains connected segments into polylines, drops pieces shorter than one cell (droppedLines), and replaces each open polyline with its end-to-end chord whenstraightenedis enabled (closed loops stay curved). Because each levee follows a contour at constant heightHabove local ground with top widthW_topand symmetric side slopesz:1, its cross-section isA = (W_top + z × H) × Hand its fill volume isV = L × Afor lengthL. The analysis reportscount, per-levee elevation, length and fill, and totals (totalLengthM,totalLengthFt,totalFillM3,totalFillYd3).
Reference cases (hand-worked)
All three cases below use synthetic (made-up) geometry on 1 m cells.
- Contour levees on a uniform slope: A
13 m × 13 mgrid (1 mcells, origin(0, 13)) with groundz(x, y) = 100.00 + 0.04 × y(4% grade rising north) and an11 m × 11 mlevee polygon from(1, 1)to(12, 12).- Cell centers inside the polygon span
x = 1.5to11.5 m(11 columns,10quad steps of1 m) andy = 1.5to11.5 m(11 rows,121cells total), withz_min = 100.06 m(aty = 1.5 m) andz_max = 100.46 m(aty = 11.5 m). - With vertical drop
Δz = 0.15 m, two contour levels fall strictly below100.46 m:- Level 1:
100.06 + 0.15 = 100.21 m, crossing every east-west quad aty = 5.25 mfromx = 1.5 mto11.5 m, lengthL_1 = 10.00 m. - Level 2:
100.06 + 0.30 = 100.36 m, crossing every east-west quad aty = 9.00 mfromx = 1.5 mto11.5 m, lengthL_2 = 10.00 m.
- Level 1:
- With
W_top = 1.0 m, symmetric side slopesz = 3:1, and constant height above groundH = 0.5 m(base footprint1.0 + 2 × 3 × 0.5 = 4.0 m ≥ 3 × 1 m):- Cross-sectional area:
A = (1.0 + 3 × 0.5) × 0.5 = 2.5 × 0.5 = 1.25 m². - Each levee's fill:
V_1 = V_2 = 10.00 m × 1.25 m² = 12.50 m³(12.50 / 0.764554857984 = 16.35 yd³).
- Cross-sectional area:
- Totals:
count = 2,totalLengthM = 20.00 m(20.00 / 0.3048 = 65.62 ft),totalFillM3 = 25.00 m³(32.70 yd³),levelsCapped = false,droppedLines = 0.
- Cell centers inside the polygon span
- Curved vs straightened contour levee on a symmetric V-draw: Same
13 m × 13 mgrid (1 mcells), polygon(1, 1)to(12, 12), and levee section (A = 1.25 m²), on groundz(x, y) = 100.00 + 0.04 × y + 0.04 × |x - 6.5|withΔz = 0.35 m.- Minimum inside the polygon is
z_min = 100.06 mat(6.5, 1.5); maximum isz_max = 100.66 mat(1.5, 11.5)and(11.5, 11.5). One contour level falls below100.66 m:z = 100.06 + 0.35 = 100.41 m. - Along
z = 100.41 m,y = 10.25 - |x - 6.5|, forming two exact45°legs from(1.5, 5.25)to the apex(6.5, 10.25)and down to(11.5, 5.25):- Curved (
straightened = false):count = 1,L = 5√2 + 5√2 = 10√2 = 14.142 m(46.40 ft),V = 10√2 × 1.25 = 17.678 m³(23.12 yd³). - Straightened (
straightened = true): End-to-end chord from(1.5, 5.25)to(11.5, 5.25):count = 1,L = 10.00 m(32.81 ft),V = 10.00 × 1.25 = 12.50 m³(16.35 yd³).
- Curved (
- Minimum inside the polygon is
- Ring dam embankment fill and stage-storage: A
20 m × 20 mring dam on flat300.000 mground (1 mcells, basin(10, 10)to(30, 30),400cells),waterDepth = 1.0 m,freeboard = 0.5 m,W_top = 3 m, upstream slope3:1, downstream slope2:1(average slope2.5:1):- Perimeter
L = 4 × 20 = 80 m, crest elevation301.500 m, constant embankment heightH = 1.500 m. - Cross-sectional area:
A = (3 + 2.5 × 1.5) × 1.5 = 6.75 × 1.5 = 10.125 m². - Embankment fill:
V = 80 × 10.125 = 810.00 m³(810 / 0.764554857984 = 1,059.44 yd³). - Full-depth storage (contained by the closed ring): the ring's line falls on column 10 and row 10, inside the basin, and on column 30 and row 30, outside it. Water can't stand on the bank's
20 + 19 = 39cells inside the basin, so(400 - 39) × 1 m² × 1.0 m = 361.00 m³(472.17 yd³,0.2927 ac-ft).
- Perimeter
5. What a pond holds (plan v3 item 425)
A basin drawn on the map is where the user expects water. Whether water stays there depends on the ground and the dam, so storage is counted only up to the lowest level at which water gets out.
- The dam as a barrier. Every terrain cell the dam's centerline crosses is treated as standing at the crest. The line is walked in quarter-cell steps, and a step that moves diagonally also marks the two cells beside it, so the marked cells touch edge to edge and water moving through cell corners can't pass between them.
- Where the water stands. The dam can divide the drawn basin into parts that water can't cross between: a ring dam drawn inside the basin's outline leaves a strip outside the ring, and a basin drawn past a dam has a part below it. Each part is worked with its water standing at its own lowest cell, and the pond is the part that holds the most depth, which is the water the dam encloses. Where parts hold the same depth, the one whose lowest cell is lowest is taken; with one part that is the basin's lowest cell the dam doesn't sit on. The pond's floor, from which normal pool and the crest are set, is that part's lowest cell.
- The way out. From where the water stands the search finds the way out of the drawn basin whose highest point is lowest, moving through cells that touch at an edge or a corner and never through the dam. Water is out when it passes the basin's edge over ground the dam doesn't block, or when it reaches the terrain's edge or missing ground while still inside the basin. That highest point is the spill level. This is the pour-point search of a priority flood (Barnes, Lehman and Mulla, 2014, "Priority-flood: an optimal depression-filling and watershed-labeling algorithm for digital elevation models", Computers & Geosciences 62, 117–127), stopped at the first way out.
- Leaving the basin is what counts, not leaving the terrain. A first version asked only whether water could reach the terrain's edge. On rolling ground that called a basin drawn on a ridge "held", because the water it sheds collects in a hollow elsewhere. So the drawn basin is the pond: the dam and ground higher than the water have to close it all the way round. A basin drawn smaller than the pool it would make reads as losing water at its own edge, and the panel says to draw it out to the higher ground.
- What is held. If no route opens below normal pool, the drawn depth is held. Otherwise the held depth is
max(0, z_spill - z_floor), the stage-storage table runs from the floor to that level only, and the panel says where the water gets out. A held depth of zero shows no storage at all. - Which cells count. Storage is summed over the basin's cells that the held water covers: those below the held level that water reaches from the starting cell without crossing the dam. The dam's own cells are left out, since water can't stand where the bank does. A part of the drawn basin beyond the dam, or behind a ridge the water doesn't top, holds none of it and isn't counted. Nothing outside the drawn outline is counted. Each row of the stage-storage table counts the same way at its own level: a cell is under water at a level only if water standing at that level reaches it, so a cell behind a ridge counts only in the rows whose level tops the ridge. The flood from the starting cell works, once, the lowest level at which water reaches each cell (the highest ground on the lowest way there), and each row counts the cells whose level is below its own.
- The terrain's edge. A pool that reaches the edge of the terrain inside the basin counts as getting out there. What holds it beyond can't be seen, and the panel says so.
- Limits. The dam is one cell wide in this search, and only the cells its line crosses are taken out of the storage, not the rest of its crest and side slopes. Within one part of the basin, water stands at its lowest point only: a part drawn over two separate hollows is worked for the lower one. Seepage, a spillway and the outlet works are not modelled. A basin whose every cell lies under the dam's line is too small for the terrain's cells, and no storage is shown for it.
Reference cases (hand-worked)
- Flat ground, 1 m cells, a 6 m square basin. Behind a 4 m bank, or one 12 m away, water at any depth spreads over level ground, so
z_spill = z_floorand the pond holds nothing. Inside a ring dam drawn on the basin's outline, nothing opens below normal pool. The ring's line falls on the basin's west column and north row, 6 + 5 = 11 of its 36 cells, and outside it on the east and south. Water can't stand where the bank does, so at 1 m deep the basin holds(36 - 11) × 1 m² × 1 m = 25 m³. With the ring drawn half a meter outside the basin, it stands on no basin cell, and all 36 hold36 m³. - A ridge. Ground that falls 0.2 m a meter to each side of a ridge, inside a rim 5 m high round the whole terrain. A 6 m basin on the ridge behind a 4 m bank sheds its water down both sides. None of it can leave the terrain, and the pond still holds nothing.
- A pit beside the ring. The same ring dam, with the basin drawn from
(20, 20)to(55, 34), wide enough to take in a pit 4 m square and 0.5 m deep, 19 m away. The ring divides the basin in two. Outside it, water stands in the pit and holds to its rim, 0.5 m. Inside it, the dam holds the drawn 1 m, so that is the pond, and the pit isn't counted. The ring's line falls on columns 20 and 26 and rows 34 and 40, leaving 5 × 5 cells inside it:25 × 1 m² × 1 m = 25 m³. - A ring dam drawn inside its basin. Flat ground, a 10 m basin from
(20, 20)to(30, 30), and a ring dam 1.5 m inside it, on the cell centers of columns and rows 21 and 28. Water in the strip outside the ring runs over the basin's edge at once. Inside the ring nothing opens below normal pool, so the drawn 1 m is held over the 6 × 6 cells inside:36 × 1 m² × 1 m = 36 m³. Neither the ring's own 28 cells nor the 36 cells outside it count. - A ridge inside the ring (round 7 of plan v4). The same 6 m ring on the basin's outline,
(20, 20)to(26, 26), on a flat floor at 100 m, with a one-cell ridge at 100.8 m down column 23 (x = 23to24). Inside the ring are 5 × 5 cells, columns 21 to 25: ten on each side of the ridge and five on it. The drawn 1 m is held. Below 100.8 m the water stands on the ten cells on its own side only: at 0.2 m,10 × 1 m² × 0.2 m = 2 m³, then 4, 6 and 8 m³ at 0.4, 0.6 and 0.8 m (at exactly 100.8 m it reaches the ridge's top but doesn't cover it). At 1 m it tops the ridge:20 × 1 m × 1 m² + 5 × 0.2 m × 1 m² = 21 m³. Counting every cell below each row's level, whether the water reaches it or not, gave 4, 8, 12, 16 and 21 m³, the lower rows twice what is held. - A basin drawn past the dam. The draw below, with the basin drawn from
y = 10instead ofy = 20, across a dam fromx = 5to45. The part below the dam is lower and its water runs away down the draw; the part above holds the drawn depth, with the same floor, pool and storage as the basin drawn to the dam. - A draw,
z = 100 + 0.05 y + 0.1 |x - 25|on 1 m cells, with the dam along the rowy = 19.5. The floor is the cell aty = 20.5,|x - 25| = 0.5:100 + 1.025 + 0.05 = 101.075 m. With 1 m of water, normal pool is102.075 m.- The basin is drawn from
x = 15to35andy = 20to50. A 1 m pool reaches 10.5 m each side of the centerline at its widest and up the draw toy = 40.5, so it lies inside that outline. - A dam from
x = 5to45ends on ground at100.975 + 0.1 × 20.5 = 103.025 m, above the pool, and the ground at the terrain's north edge (y = 59.5) is103.025 m. The drawn depth is held. - A dam from
x = 19to31sits on the cells fromx = 19.5to31.5. Just past its west end, atx = 18.5, the ground is100.975 + 0.1 × 6.5 = 101.625 m. Water above that runs round the end, so0.55 mis held, not1 m.
- The basin is drawn from
6. Missing ground (plan v3 item 426)
A quantity worked over ground that isn't there is not a smaller quantity. It is no quantity.
Areas. For a leveling area, a pond's basin and a levee area, every cell whose center falls inside the drawn outline is counted, off the terrain as well as on it. If any has no elevation, the area, cut, fill, ratio, storage, borrow and levee totals are all withheld, and the panel states the share that's missing.
Lines. For a ditch and a dam's centerline, every cell the line passes through is counted, at the terrain's own cell size (the grid traversal of Amanatides and Woo, 1987, "A fast voxel traversal algorithm for ray tracing", Eurographics '87), not only the cells its stations land in, so a gap narrower than the station step is seen. A line running along a cell edge counts the cells on both sides. Each station along the line takes its ground from the cell its point falls in, so a station exactly on a cell's west or north edge, or on the terrain's east or south edge, reads the cell beyond, which the line only touches; that cell is counted too (round 7 of plan v4). If any has no ground under it, excavation, widths, dam fill and embankment height are withheld. A ditch's bed is a grade line anchored to the ground along its whole length, so with a station missing no bed elevation is given at any station, and no invert is offered to a tile outlet.
Footprints. A ditch's excavation and a dam's fill are worked from their cross-sections, so the ground under the whole section must be there, not only under the line. Once every cell the line crosses has ground, every cell whose center lies within the section's half-width of the line is counted too, square to the line along each stretch and in a circle round each bend, a center exactly on the edge counting as under it. For a ditch the half-width over each cell the line crosses is
b/2 + z × max(0, z_ground - z_bed), from that cell's ground and the bed's grade line there. For a dam it isW_top/2 + max(z_up, z_down) × max(0, z_crest - z_ground): which side is upstream isn't worked out, so the steeper reach is taken on both sides and the base is covered whichever it is. For contour levees it is(W_top + 2 × z × H)/2, since a levee's base can reach past its drawn area. If any of these cells has no elevation, the quantity is withheld and the message says the share missing of the ditch, dam or levees, side slopes included. The open ends of a ditch, a valley dam and a levee are cut square, as their volumes are.A worked case: on a flat 1 m grid at 300 m with column 30 missing, a valley dam or a ditch drawn from
(10, 20.5)to(30, 20.5)passes through columns 10 to 29, all with ground, but its last station, atx = 30, reads column 30. Of the 21 cells read, 1 is missing, about 5%, and no fill, height, excavation or bed elevation is given. Before this was counted, the dam's last section was worked over a ground of zero: a 301.5 m bank and 114,277.5 m³ of fill for a 20 m dam.What still shows. The cut and fill map and the CSV keep the cells that do have terrain, since each is true by itself. The CSV says in its header that no total can be taken from its rows. A ditch's capacity comes from its entered section and grade, not the ground, so it stays.
The share allowed is none. Allowing a share is the owner's decision, recorded in
docs/PLAN_V3.md.
Reference case (hand-worked)
A 20 m square leveling area on a flat 1 m grid at 300 m, with a design plane at 299 m: 400 cells, 400 × 1 m² × 1 m = 400 m³ of cut. With the east half of the grid tagged as missing, 200 of the 400 cells have no elevation. The share missing is 50%, and no cut, fill or area is shown.
7. Volume uncertainty ranges (plan v3 item 398)
Every cut, fill, dam and levee quantity carries a vertical-accuracy range computed by working the quantity again with the original ground DEM uniformly raised and lowered by ±1.96 × σ_z, where σ_z is the terrain's stated vertical accuracy (RMSE_z from the terrain's provenance quality level per USGS Lidar Base Specification 2025 rev. A, Table 4 (absolute vertical accuracy): 0.05 m for QL0, 0.10 m for QL1/QL2, 0.20 m for QL3).
- No default accuracy: When the terrain states no quality level, or is recorded as below specification (
meets_specification = false), no range is worked out and the panel, report and CSV state why. - When the shift cancels: A uniform shift of the ground cancels out identically whenever the design surface is fitted or anchored to that same DEM:
- A grading plane fitted (
fitGradingPlane) or balanced (balanceGradingPlane) to the project DEM shifts with the ground by±1.96 × σ_z, leaving zero spread from a uniform shift. A plane fixed at an entered datum elevation does not move with the ground and carries the full cut and fill range. The plane is moved with the ground, not balanced again on the moved ground: a balanced plane whose slope or heading was changed afterwards is no longer balanced to its ratio, but its elevation still came from this ground, so it still moves with it and has no range from a uniform shift (round 7, finding NC2; before, balancing it again measured the gap between two planes and printed it as a range). For a plane still balanced to its ratio, the two give the same figures.computeCutFillUncertaintygives the figure as both ends andshiftCancels = truefrom that one decision, so its sentence and its ends always agree. - A pond dam whose crest is set from the basin floor (
z_floor + waterDepth + freeboard) on the same DEM shifts with the ground; a dam built to a fixed crest elevation carries the resulting fill range. - Contour levees whose contour levels (
minZ + k × Δz) and heights are measured from the same DEM shift with the ground.
- A grading plane fitted (
- Cell-to-cell noise is not included: Shifting the entire DEM uniformly tests systematic vertical offset only, not spatially varying or cell-to-cell elevation noise. About this data says so beside how the range is worked; the range statements in the panel, the report and the CSV give the range and how far the ground was moved, without the formula or this note, as the owner approved on 2026-11-30 (
labels-and-cautions.md, label 33). - Missing ground: A range never narrows because ground is missing. Whenever a quantity is withheld for missing ground (section 6), its range is withheld as well.
Reference cases (hand-worked)
- Fixed plane on flat ground (signed check case): A 100 m × 100 m area (
10,000 m²) on flat ground at300.000 mwith stated vertical accuracyσ_z = 0.10 m(±1.96 × 0.10 = ±0.196 m), and a plane fixed at300.000 m:- Raised ground (
300.196 m): cut =10,000 × 0.196 = 1,960 m³(2,563.6 yd³), fill =0 m³. - Lowered ground (
299.804 m): cut =0 m³, fill =1,960 m³. - Cut range:
0to1,960 m³; fill range:0to1,960 m³.
- Raised ground (
- Same plane fitted to the ground: Fitted plane shifts to
300.196 mon raised ground and299.804 mon lowered ground, so cut =0to0 m³, fill =0to0 m³,shiftCancels = true, and the statement notes both that the shift cancels and that cell-to-cell noise is not included. - Fixed-crest ring dam: A 20 m × 20 m ring dam (perimeter
80 m,W_top = 3 m, average side slope(3 + 2)/2 = 2.5) on flat300.000 mground withσ_z = 0.10 mand crest fixed at301.500 m:- Raised ground (
300.196 m,H = 1.304 m):A = (3 + 2.5 × 1.304) × 1.304 = 8.16304 m²→V = 80 × 8.16304 = 653.04 m³. - Lowered ground (
299.804 m,H = 1.696 m):A = (3 + 2.5 × 1.696) × 1.696 = 12.27904 m²→V = 80 × 12.27904 = 982.32 m³. - Dam fill range:
653.04to982.32 m³. Anchored to the basin floor (waterDepth + freeboardon the same DEM,H = 1.500 m,A = 10.125 m²,V = 80 × 10.125 = 810.00 m³), the shift cancels (810.00to810.00 m³).
- Raised ground (
8. Terrain cell size and small-feature refusals (plan v3 item 430)
Every earthwork card, report, CSV, and GIS export shows the terrain cell size read from the terrain's record (and a saved feature's recorded cell size when saved on an earlier terrain), or cell size not recorded when absent.
Two judgment thresholds, starting points that are neither cited nor yet measured against results (defined once in packages/surface/src/resolution.ts and proposed in docs/engineering/plan-v3-signoffs.md, Question 4, which no engineer has answered yet) withhold quantities on terrain too coarse for the feature (MIN_FEATURE_WIDTH_CELLS = 3 cells and MIN_BASIN_CELLS = 9 cells):
- Ditch (
checkDitchResolution): Refused when the design top width at minimum depth (bottomWidthM + 2 × sideSlope × minDepthM) is narrower than3cells. Excavation, max top width, station inverts, and tile outlet invert proposals are withheld; Manning's capacity (from entered dimensions and grade alone) remains shown. Ditch drainage area (checkDitchDrainageResolution) is refused when the watershed has fewer than9cells. - Leveling area / Cut & fill (
checkGradingPlaneResolution): Refused when the polygon contains fewer than9cells or its rotation-invariant minimum width is narrower than3cells. Cut, fill, ratio, uncertainty range, map shading, contours, report figures/map snapshot, and CSV cell rows are withheld, with the refusal reason in their place. - Pond / dam (
checkPondDamResolution): Refused when the basin contains fewer than9cells (for example, a6 mbasin on5 mcells), the basin minimum width is narrower than3cells, or the dam crest top width (topWidthM) is narrower than3cells. Dam fill, pond borrow, uncertainty range, containment, and stage-storage are withheld; the sketch notice and permit notes remain shown. - Contour levees (
checkContourLeveeResolution): Refused when the drawn levee area has fewer than9cells or minimum width narrower than3cells, or when each levee's embankment base width (topWidthM + 2 × sideSlope × heightM) is narrower than3cells. Levee count, length, fill, uncertainty range, map lines, and GIS levee lines are withheld. - Culvert (
checkCulvertResolution): Not refused on terrain coarseness. HDS-5 capacity reads no terrain grid, and flow breaching is a one-cell topological link across a barrier rather than a DEM-sampled cross-section. - Drawing and saving stay unblocked: A feature refused for coarse terrain can still be drawn and saved so it evaluates once the terrain is rebuilt at a finer cell size under Elevation data. When no cell size is recorded, nothing is refused on coarseness. See
result-resolution.mdfor the complete table.
9. A building pad: its dirt, its fall and its slope (plan v4 items 470 and 471)
packages/earthwork/src/pad.ts. Everything in this section reads the original ground DEM only (OriginalDemGrid).
The shape
A pad is a rectangle with a center, a width, a length and a rotation (the bearing of its length, clockwise from grid north; its width runs 90° clockwise from that), level at an elevation E, with side slopes out to the ground at m_cut:1 where it cuts into the ground and m_fill:1 where it is built up (horizontal to vertical). Its stored shape, PadFeature, sits beside the other shapes in types.ts. It is part of the SurfaceFeature union and is saved with the project (see "Storing a pad" below).
Starting side slope. A new pad starts at 3:1 in cut and in fill (PAD_SIDE_SLOPE_STARTING_POINT_H_PER_V). That is the slope a contour levee starts at (sideSlopeHPerV: 3) and a pond dam's upstream face starts at (upstreamSlopeHPerV: 3) in finishDrawing in apps/web/src/app/projects/[projectId]/surface-earthwork-panel.tsx. The pond's downstream face starts at 2:1, and a pad takes the levee's 3:1 on both sides. This is a starting point, the same as the app's others, and not a recommendation for any soil. Both slopes are entered.
Cut and fill
This is the unit-area method (also called the borrow-pit or grid method; Ghilani and Wolf, Elementary Surveying: An Introduction to Geomatics, the chapter on volumes), the same prisms as a leveling plane's (section 3), with the design surface carried past the pad's edge on its side slopes. For each cell of side Δ, with ground z at its center and d the horizontal distance from its center to the pad's edge (0 on the pad):
- On the pad (
d = 0): cutmax(0, z − E), fillmax(0, E − z). - Off the pad: cut
max(0, z − E − d / m_cut), fillmax(0, E − d / m_fill − z). At most one is above zero. - Each depth times
Δ²is that cell's volume. Cut and fill are summed apart, and the pad's top and the side slopes are reported apart as well as together. - Where the slope stops. A side slope stops where it first meets the ground. So a cell off the pad counts only when a chain of earthwork cells (4-connected, each no nearer the pad than the one before) joins it to the pad. Ground that dips below the slope's extension past a rise is not counted. The walk outward from the pad is a breadth-first search, so the side slopes' extent comes out of the method, with no reach set in advance.
- Corners.
dis the true distance to the rectangle: square to a side beyond that side, and the distance to the corner beyond a corner. So the side slopes round each corner as a quarter cone. Here is why. The slope is then exactly the entered ratio in every direction away from the pad, with no hip line, so nothing is steeper than what was entered and nothing gentler is hidden in a corner. One rule holds at every rotation, so a turned pad needs no special case. And it is what a dozer leaves. Squared corners, two planes meeting on a hip, would add4 × (m h)² h / 3 − π m² h³ / 3 = (4 − π) m² h³ / 3on flat ground over the four corners together:2.58 m³for case 1 below, 0.34% of it. - The balancing elevation.
cut(E) − R × fill(E)falls asErises, so bisection onEfinds wherecut = R × fill.Ris entered and never assumed (section 3), clamped to0.05to20as a leveling plane's is. The bracket is found from the mean ground on the pad, stepping up when there is too much cut and down when there is too much fill, starting at a quarter of the fall across the pad (at least 0.05 m) and doubling, until the sign changes. A trial elevation whose side slopes run off the ground heights doesn't end the search: the step is halved back toward the last trial that stayed on them, since a level nearer the balance sends the slopes less far. So a pad near the edge of the ground balances whenever its balanced slopes stay on the ground, even though a trial at its lowest or highest ground would not (review round 7, NG4: a 20 by 16 m pad on a 10% slope 8 m from the edge balances at its middle, its slopes reaching 3.8 m). Only when the sign can't change before the slopes leave the ground (the step falls under 0.1 mm) is the balance not given (see "Where the ground runs out"). A level whose figure is exactly balanced, such as a pad at the ground on flat ground, is taken as it is. - One level for every reader. A balanced pad's saved elevation is only the level that last balanced, on whatever ground was in use then. Its card, the earthwork list, the cut and fill download, the site map page, the shared view, the design surface and the dirt balance (section 11) all balance it again on the ground in use, through
padLevelOfandpadLevelOn, never reading the saved elevation as is (review round 7, NG3).
How close the cells come: the tolerance
The sum is the midpoint rule on a depth that is linear between the lines where its gradient changes: the pad's edge, the toe where a slope meets the ground, and the line where the pad's top passes from fill to cut. A cell crossed by such a line, with gradient jump s, is off by at most s Δ³ / 8 for a line square to the cell. Allowing up to twice that for a slanted line, the whole is off by at most
ε ≤ (Δ² / 4) Σ sᵢ ℓᵢ + (Δ² / 24) ∫ |∇² depth| dA
where ℓᵢ is the length of each such line inside cells (a line along a cell edge adds nothing), and the second term is the curvature of the corner cones: |∇² depth| = 1 / (m r) in a corner, on flat or tilted ground, which integrates to (1/m) ∫ R(φ) dφ per corner for toe radius R(φ). Each case below states its ε, and the engine is tested against it.
Reference cases (worked by hand)
All three use 1 m cells (Δ = 1 m) and the pad of pad.test.ts: 30 m east-west (W) by 20 m north-south (L), centered at (40, 40), not turned, so its edges fall on cell edges. Side slopes are 3:1 in cut and fill (m = 3).
- Flat ground at 100 m, the pad at 101 m (
h = 1 mof fill). Cut is zero.- Pad prism:
W × L × h = 30 × 20 × 1 = 600 m³. - Side-slope prisms: each side's section is a triangle
m hwide andhhigh, aream h² / 2 = 1.5 m², along the perimeter2(W + L) = 100 m:150 m³. - Corner pieces: four quarter cones of radius
m h = 3 mand heighth, one whole cone:π (m h)² h / 3 = 3π = 9.425 m³. - Fill
= 759.425 m³(993.29 yd³). The straight toes, 3 m out, fall on cell edges, so only the corner arcs (2π m h = 18.85 m,s = 1/m) count:ε = (1/4)(2π) + (1/24)(2π) = 1.83 m³. - Engine:
759.439 m³, off by0.014 m³. Turned 30°, the pad's edges and toes cross cells:ε = (1/4)(1/3)(100 + 100 + 18.85) + 0.26 = 18.50 m³, and the engine is off by0.10 m³.
- Pad prism:
- The same pad 1 m below flat ground (
E = 99 m). Fill is zero, and cut is the same759.425 m³by the same working withm_cut. The engine is off by0.014 m³. - A 10% plane rising east,
z = 100 + 0.1 (x − 40), the pad at 100 m. Half the pad is in fill (west) and half in cut (east). Withg = 0.1andk = 1/m − g = 0.23333:- On the pad, the fill depth is
−g x′forx′ = x − 40from−15to0:L ∫₀¹⁵ g x′ dx′ = 20 × 0.1 × 15² / 2 = 225 m³. - North and south sides, fill half: beyond these sides the ground doesn't change going north or south, so the section at
x′ism h(x′)² / 2withh = g|x′|. Over both sides:2 ∫₀¹⁵ 3 (0.1 x′)² / 2 dx′ = 3 × 0.01 × 15³ / 3 = 33.75 m³. - West side: the depth at the edge is
h_e = g W / 2 = 1.5 m. Going west a distanced, the ground fallsg dand the slope fallsd / m, so the depth ish_e − k d, reaching zero atd = 1.5 / 0.23333 = 6.43 m. Sectionh_e² / (2k) = 4.8214 m², timesL = 20 m:96.4286 m³. - The two west corners: at angle
φfrom due west toward north (or south), the depth ish_e − r (1/m − g cos φ), so the toe is atR(φ) = h_e / (1/m − g cos φ)and the volume is∫∫ (h_e − r k(φ)) r dr dφ = (h_e³ / 6) ∫₀^{π/2} dφ / (1/m − g cos φ)²per corner. WithA = 1/mandB = −g,∫ dθ / (A + B cos θ)² = −B sin θ / ((A² − B²)(A + B cos θ)) + (A / (A² − B²)) × (2 / √(A² − B²)) atan(√((A − B)/(A + B)) tan(θ/2)). Over0toπ/2it is22.41145. A 2,000-step Simpson's rule gives the same to seven figures. Both corners:2 × (1.5³ / 6) × 22.41145 = 25.2129 m³. - Fill
= 225 + 33.75 + 96.4286 + 25.2129 = 380.391 m³(497.53 yd³). The cut is the same, by the 180° turn about the pad's center that swaps the ground's rise for its fall. With equal side slopes, that symmetry also means the elevation that balances cut and fill atR = 1is exactly 100 m. - Tolerance: the pad's edges and the fill-cut line
x = 40lie on cell edges. The slanted north and south toes (s = √(g² + 1/m²) = 0.348, two of15.66 mfor the fill), the west toe (s = k,20 m) and the two corner arcs (s ≤ 1/m + g,9.09 meach) giveε = 5.86 + 0.25 = 6.11 m³. - Engine: fill and cut each
379.501 m³, off by0.89 m³. On 0.5 m cells it is off by0.12 m³, a quarter as much, as the bound'sΔ²says. The balance atR = 1comes out at100.0000 m, and atR = 1.25the engine's own cut and fill at its balanced elevation are in that ratio to four figures.
- On the pad, the fill depth is
pad.test.ts holds the engine to each of these, within its ε.
Range from the terrain's accuracy
As section 7, with the same code's multiplier, wording and status values (VERTICAL_SHIFT_Z95, volumeRangeFrom, CutFillUncertainty; the formula and the noise note are About this data's, label 33). The method is worked again with the ground raised and lowered by 1.96 σ_z. The ground shift is applied as an offset inside the method rather than by copying the DEM with shiftDem, which gives the same heights without copying a whole terrain on every drag.
- An entered elevation stays fixed while the ground moves, so it carries the full range. Case 1 with
σ_z = 0.10 mgives fill heights of0.804 mand1.196 m:600h + 150h² + 3πh³gives584.3 m³to948.3 m³. Each figure is within its ownε, since the toes no longer fall on cell edges. - A balanced pad moves with the ground, so the uniform shift cancels (
shiftCancels: true), as for a fitted plane. - No stated accuracy, or a terrain below specification: no range, and it says which.
A coarse figure while dragged, the full one at rest
- Full (
padEarthwork): the method on every cell of the terrain. - Coarse (
padEarthworkCoarse): the same method on the ground averaged over blocks off × fcells (coarsenGround), from the same corner, made once per terrain and factor and kept by the worker. A block with any cell missing, or reaching past the edge, is missing: a coarse figure never fills in ground.f(padCoarseFactor) is chosen so the pad's top covers about 400 coarse cells, and never fewer than 4 coarse cells across. A small pad getsf = 1, and then its "coarse" figure is the full one and saysprecision: "full". Otherwise the result saysprecision: "coarse"and the cell size it was worked on. - How far apart they can be. On smooth ground each figure is within the bound above at its own cell size, so they differ by at most the sum of the two bounds. The coarse bound is
f²times the full one: about 4 × 6.11 m³ for case 3 atf = 2, where they differ by 1.97 m³. On rough ground the coarse figure also loses relief smaller than a block, and nothing bounds that in general. On the test ground used for the speed figures below (a 2% and 1% tilt with 0.6 m swells and 0.05 m ripples), a 300 by 200 ft pad atf = 3gave 1,904.8 against 1,910.0 m³ of fill (0.3% apart) and 54.3 against 59.2 m³ of cut (8% apart, on a small cut). The pad's edge also moves by up to half a coarse cell, since cells are counted by their centers. So the coarse figure follows a drag and the full one is the figure to read.
Where the ground runs out
Each of these gives no quantity for the part it can't know and says what is missing. pad.test.ts holds each one.
- The pad partly over missing ground: every cell whose center is on the pad is counted, off the terrain as well as on it. If any has no ground, nothing is given (neither the top nor the total, nor any range), and
padGroundSharecarries the share that has ground: "Ground heights cover 80% of this pad. Move it or draw a larger area." (padGroundStatement, which rounds down, so a pad 99.6% covered never reads 100%.) - Side slopes that run off the built ground before they meet it: when the walk outward reaches a cell with no ground, or the grid's edge, from a cell still in earthwork or from the pad, the total isn't given (
slopesRunOff: true). The dirt under the pad's top is known by itself and is still given aswithinPad. A screen that shows it says it is the top only. The statement: "The side slopes run past the edge of the ground heights before they meet the ground, so the total isn't worked out. Move the pad or draw a larger area." The same pad with ground 4 m out instead of 2 m, past the 3 m toe, gives its total. - A pad narrower than three cells: "This pad is too small to measure at this cell size: 2.5 m across on 1 m cells. Make it at least 3 cells, 3 m, across." This is checked against the cell size the figure is worked on.
- Cells too coarse by plan v3's rule (item 430): against the terrain's recorded cell size, the pad needs nine cells and three cells across (
MIN_BASIN_CELLS,MIN_FEATURE_WIDTH_CELLS), in the words the owner approved for label 36 (labels-and-cautions.md): "This pad is too small to measure on 10 m cells.", with the remedy after it. - A balance that can't be found without a slope leaving the ground heights: no elevation and no quantity, with "No level balances cut and fill for this pad within the ground heights. Enter an elevation, or move the pad or draw a larger area." This is said in place of the side slopes' sentence, since it was a trial level's slopes that ran off, not the pad's.
The fall across a pad and the slope under it (item 470)
padGroundFigures, from the pad's own cells on the original ground: the fall is the highest cell minus the lowest, with both points, and the slope is that of the plane fitted to those cells by least squares (fitPlaneLeastSquares, as section 3 fits a leveling plane), with the way it falls in degrees clockwise from grid north, and no direction when it is level. Missing ground, a pad under three cells across, and plan v3's rule withhold them on the same terms as the dirt. On case 3's plane: a 2.9 m fall between the outer cell centers 29 m apart, a 10% slope, falling at 270° (west).
For one area, the fitted plane's slope is the right single figure. The slope bands of plan v4 item 446 (branch t3/v4-446-slope-numbers, packages/surface/src/slope.ts) work slope per cell by Horn (1981). The two agree exactly on a plane, and they face the same way: atan2(−east, −north). When the two branches meet, the facing formula and the "level faces no way" rule should become one helper in @tilemapper/surface that both call. Since PR 55, the pad's fit is planeFall in @tilemapper/surface (site-ground.ts), the one fit a building site's lay of the land uses too, with its facing and its "level faces no way" rule (slope-and-grade.md, section 8). It gives the same plane as fitPlaneLeastSquares, and the pad's tests are unchanged.
Speed (item 9 of the brief)
Measured on 1 m ground (a 2,000 by 2,000 cell grid of the test ground above), pads turned 20°, with the range worked too (two more evaluations, or two more balances). This was an Apple M5 with 16 GB and Node 26.5 under vitest, during a run of several parallel lanes (load average 6.6 to 12). The two rows for each figure are two runs, and the spread is the machine's load:
| Pad | Coarse factor | Entered: coarse | Entered: full | Balanced: coarse | Balanced: full |
|---|---|---|---|---|---|
| 100 × 60 ft (30.48 × 18.29 m) | 1 | 0.9–2.1 ms | 0.9–2.4 ms | 7.1–16.6 ms | 7.0–18.0 ms |
| 300 × 200 ft (91.44 × 60.96 m) | 3 | 1.1–3.1 ms | 3.5–6.8 ms | 7.8–18.4 ms | 82–266 ms |
Averaging the whole 4 million cell grid for the coarse figure took 78 to 258 ms. That happens once per terrain and factor, not once per move. A dragged pad's coarse figure fits well inside one animation frame, and the full figure at rest takes well under a second. All of it runs in the terrain-calc worker (pad-earthwork task).
Storing a pad (plan v4 item 527)
A pad is a surface feature like the other shapes. Migration 20261130230000_surface_feature_pile_and_pad.sql replaces the check on public.project_surface_features.kind with one that also takes 'pad' and 'pile_or_pit', and leaves the table's RLS, grants and its other checks as they were. duplicate_project copies every row whatever its kind, so a copied project carries pads and piles with no change. PadFeature is in the SurfaceFeature union, and earthwork-invariance.test.ts (plan v3 item 401) saves a pad and a measured pile with the other five kinds and holds every tile result, cover check, fingerprint and hash unchanged. apps/web/src/lib/network/pad-invariance.test.ts still works every pad calculation beside each benchmark's outlet.
A driveway traced to a pad (plan v4 item 472) is kept on the pad itself, as PadFeature.driveway: the line in project coordinates from the road to the pad's edge, and the run and grade the card was left at. Its grades are read again from the original DEM whenever it is opened (slope-and-grade.md, section 4), never stored. A pad has one driveway; tracing again replaces it. A grade line kept from the elevation profile (project_slope_results, one per project) is separate, so a project can keep both. The field is optional, so pads saved before it parse unchanged, and it touches no tile result.
On the screen (plan v4 item 470)
apps/web/src/app/projects/[projectId]/pad-tools.tsx, with its geometry in apps/web/src/lib/terrain/pad-place.ts. A new pad's length starts at about a third of the shorter side of the map's view and its width at about six tenths of that, each rounded to a plain figure in feet (startingPadSize), so it is never a dot or the whole screen; its level starts at the average ground under it, to a tenth of a foot. Both are said on the card as starting points. The fall and slope (padGroundFigures) are worked on the page on every move; the dirt goes to the worker with precision: "coarse" while a handle is held and "full" once it is let go.
10. Water across a pad, counted once (plan v4 item 526)
packages/earthwork/src/pad-water.ts, on delineateAreaWatershed in packages/surface/src/flow.ts. This reads the conditioned flow grid (ConditionedFlowGrid) and the ponding depths (FillDepthGrid), never the original DEM. The pad's dirt reads the original DEM and never these, and the types keep the two apart, as dem-reader.ts does.
- The rule. The land that drains across a pad is the land whose water reaches any of the pad's cells (cells whose centers are on the pad, on the flow grid). That is the union of the cells' D8 watersheds (section 1 of
surface-water.md), never their sum. It is found by one reverse walk of the flow pointers seeded from every pad cell at once, so a cell upstream of two pad cells, or of two paths that join before the pad, is reached once. Land entering from beyond the terrain's edge is added once per cell, as for a single watershed. - "At least." When the union reaches the valid edge of the built ground (
touchesEdge, as for a single watershed), the true area may be larger, and the result carriesatLeast: truefor a screen to read "at least". - Culverts. A culvert changes where water goes by changing the flow grid (plan v3 item 395,
applyCulvertsToHydrology). Pass the flow grid and ponding depths that function returns, whichworkspace-context.tsxalready gives the terrain tools, and the answer moves with it. The terrain-calc worker'spad-watertask reads whichever flow grid the screen has set, the routed one when culverts are in force. - Ground that fills. With the ponding depths given, the result says whether any of the pad's cells fills to the low-spot depth (
LOW_SPOT_MIN_DEPTH_M, 0.10 m, the same rule as the listed low spots), how many, and the deepest. - Where it runs out. A pad with any cell off the flow grid or with no ground gives no acres and says how much of it has ground. An area under nine cells, counting land from beyond the edge, is refused by plan v3's rule (
checkWatershedResolution), as a watershed is.
Reference case (counted by hand)
A 7 by 7 grid of 10 m cells (100 m² each), rows numbered from the north and columns from the west. The outer ring drains off the grid. Inside it, the pointers are:
| Row \ Col | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| 1 | a ↘ | b ↓ | c ↓ | d ↓ | e ↙ |
| 2 | f → | h ↘ | j ↓ | i ↙ | g ← |
| 3 | ↓ | ← | k ↓ | → | ↓ |
| 4 | ↓ | ← | P1 → | P2 ↓ | ↓ |
| 5 | ↓ | ↓ | ↓ | ↓ | ↓ |
The pad covers P1 and P2: 20 m by 10 m, centered on the shared edge of their cells. One path comes from the north-west (a, b and f into h) and one from the north-east (d, e and g into i). They join the middle path (c into j) at k, above the pad, and k drains onto P1. P1 drains onto P2, and P2 drains south off the grid. Counted by hand:
- Draining to P1: P1, k, h, j, i, a, b, c, d, e, f, g, which is 12 cells. Nothing else points into P1, h, j, i or k.
- Draining to P2: P2 and everything that drains to P1, which is 13 cells.
- Draining across the pad, each piece once: those 13 cells,
1,300 m² = 0.3212 ac, of which200 m²is the pad and1,100 m²lies above it. None is on the grid's edge, so it isn't "at least". - A sum of each cell's watershed gives
12 + 13 = 25cells,2,500 m² = 0.6178 ac, nearly twice the area. Everything that drains to P1 is counted again in P2.
pad-water.test.ts holds the engine to the 13 cells, cell by cell, and to the naive sum of 25. It also checks four more things. If the ring cell above b drains onto b, the area reaches the edge and reads at least 1,400 m². A pad with a cell off the ground gives no acres. A pad whose area falls under nine cells is refused. And a culvert moves the answer: on plan v3's road-and-pond grid (section 2 of surface-water.md), a pad below the road takes 9 cells of water until a culvert takes Pond A under the road onto it, and then it takes the pond and the upland west of it too.
11. One dirt balance, each piece of ground once (plan v4 item 528)
packages/earthwork/src/balance.ts, dirtBalance. Its screen is item 480. Every figure it adds up was worked on the original ground DEM.
What it adds up
The shapes a person ticks, in the order of the list. Each is one of three things to the balance:
- Earthwork (a leveling area, a pad, and the sections of a ditch, a dam or a levee): ground taken away is cut, ground built up is fill.
- A pile that has been measured (section 12): its dirt above its base is dirt on hand. It counts only when it is ticked.
- A pit that has been measured: its room below its base is a place for dirt. It counts only when it is ticked.
A pond's storage, the dirt dug to make a pond and dirt on hand in a pile are three different numbers, and the result keeps them in different rows: cut, fill, onHand, room, and storage for the water ponds hold, which is never dirt and never in the balance.
Shared ground: the rule
Where two ticked shapes change the same ground, the one higher in the list sets the ground there, and the other's change on that ground isn't counted. The balance works on the terrain's cells: each shape gives the change it makes on each cell (CellChanges, + for ground taken away and − for ground built up), and the first shape in the list to reach a cell keeps it. Every pair that shares ground comes back in overlaps, with the area and what the dropped shape would have added there, so a screen can say so in a sentence and let the person move the other shape up to keep it there instead.
Why this rule. A surface can only be at one height on one spot, and whatever is built last is what is there. The change counted on a cell is the kept shape's design against the original ground, which is exactly the change from what is there now to what will be there.
- A pad inside a leveled area. The pad is built on the yard, so the pad goes higher in the list. On the pad's cells the pad's own cut and fill against the original ground is the whole change there; the yard's cut under the pad isn't counted again (case 2).
- A ditch through a pad. The ditch is dug through it, so it goes higher. Where the ditch is, its section sets the ground, and the pad's fill under the ditch isn't counted.
- A pond beside a levee built from its dirt. They share no ground. The pond's dig is cut, the levee is fill, and the balance says whether one covers the other.
What it doesn't do. A kept shape's side slopes are worked against the original ground, not against the shape below it, so a pad's slopes inside a yard leveled lower than the original ground meet the original ground, where in the field they would run on down to the yard. The difference is the thin wedge between the two slopes' toes. A screen that wants it can say "side slopes meet the original ground".
Shapes worked by their sections (a ditch, a dam or a levee: sections 1 and 4) come in as a whole figure with the cells their earthwork covers (WholeShapeFigure). One can't be split cell by cell. Above every shape it shares ground with, it is counted whole and the shapes below it give up those cells. Below a shape it shares ground with, it is left out, complete is false, and the sentence says to move it up or untick one.
How each shape worked by its sections maps (plan v4 item 480)
packages/earthwork/src/balance-sections.ts, balanceShapeOf. A leveling area, a pad and a measured pile or pit are worked cell by cell (balanceShapeFor). A pad is worked at its level on the ground in use (padLevelOn, section 9): a balanced pad is balanced again, and when no level balances it is named as missing, "no level balances its cut and fill within the ground heights", with no figure. The other three come in as a WholeShapeFigure, each from its own analysis, with nothing worked anew:
- A ditch (section 1,
analyzeDitch): its excavation is cut, and its fill is zero; the spoil isn't modeled, so it isn't counted anywhere. Its footprint is every cell under its top width, side slopes included, found the way its own ground check finds them (section 6,lineFootprintGroundCoverage, with the half-widthb/2 + z × cutover each cell from the bed's grade line). Its range is the ditch worked again on ground raised and lowered by1.96 σ_z(section 7); since the bed is set from the ground along the ditch, a uniform shift moves the bed with it and the range doesn't widen. - A pond's dam (section 4,
analyzePondDam): the embankment is fill. The pond as drawn digs nothing, so its cut is zero. The dirt its basin could give (basinExcavationM3, "if the basin were dug") is an option on the pond's own card, not part of the sketch, and isn't counted as cut. The water it holds (the last row of its stage-storage table, section 5) is its storage, the balance's own row, never dirt. Its footprint is the dam's base, its crest and the steeper of its two slopes on both sides, as its own ground check finds it; the basin under the water isn't changed by the dam and isn't in it. Its range iscomputePondDamUncertainty's. - Contour levees (section 4,
analyzeContourLevees): their embankments are fill, and they dig nothing. Their footprint is the cells under each levee line's base,top width / 2 + side slope × heighteither side of it. Their range iscomputeContourLeveeUncertainty's.
So a pond's storage, the dirt dug to make something and dirt on hand in a pile never share a row: a pond gives fill and storage, a ditch gives cut, a pile gives dirt on hand. Where any of the three has no figure (ground missing under it, side slopes off the ground heights, or cells too coarse for it), it comes in with missing set to "ground heights are missing under it, or its side slopes run past them" or "the terrain's cells are too coarse for it", and the balance leaves it out and says so.
Case 4, worked by hand: a ditch through a pad. Section 9's pad (above), and a ditch along the cell edge y = 40 from x = 20 to x = 80, 60 m, bottom 2 m, side slopes 2:1, at least 1 m deep, level. On flat ground its bed is at 99 m, its section (2 + 2 × 1) × 1 = 4 m², its cut 4 × 60 = 240 m³, exact, and its top width 2 + 2 × 2 × 1 = 6 m. The cells under it are those whose centers are within 3 m of the line, rows at y = 37.5 to 42.5, six, by the 60 columns from x = 20.5 to 79.5: 360 cells.
- With the ditch higher in the list, it is counted whole and the pad gives up those cells. Under the ditch the pad's top covers 30 columns,
x = 25.5to54.5, so6 × 30 × 1 m = 180 m³of fill isn't counted; on each row its slopes add1 − d/3atd = 0.5, 1.5, 2.5on both sides,2 × 1.5 = 3 m³a row,18 m³. 198 m³ of the pad's fill isn't counted. Cut240 m³; fill759.425 − 198 = 561.425 m³within section 9's1.83 m³. At a ratio of 1.25:240 − 1.25 × 561.425 = −461.78 m³, short.balance-sections.test.tschecks the 198 m³ to a millionth against the engine's own pad, and the rest within the tolerance. - With the pad higher, the ditch sits below a shape it shares ground with and can't be split, so it is left out, the total is incomplete, and the sentence says to move it above Shop pad or untick one.
A dam on flat ground, worked by hand: a ring dam round the square from (30, 30) to (60, 60), water 2 m deep, freeboard 0.5 m, top 3 m, slopes 3:1 and 2:1. Its crest is 2.5 m above the ground, its section (3 + 2.5 × 2.5) × 2.5 = 23.125 m² and its 120 m round, so 2,775 m³ of fill, which the test matches to a millionth; its cut is zero and the water it holds is in the storage row.
The ratio
cut + on hand − ratio × (fill + room): left over when positive, short when negative. The cut to fill ratio is the one section 3 defines (V_cut / V_fill), passed in, never assumed, and the balance gives no left over or short without it. One ratio is applied to all the dirt, dug or on hand. A pile is loose dirt and may shrink differently from bank cut; a person who knows that can say so in the ratio they enter. The ratio is printed whole wherever it is shown, in the balance's sentence and on the map page, never rounded: what is called "as entered" is the number entered and used (formatCutFillRatio; review finding G5, 2026-12-02).
Where a shape has no figure
A ticked shape with no figure (ground missing under it, side slopes that run off the ground heights, cells too coarse, or worked on different ground heights from the others) is named in missing with why, complete is false, and the rows give the rest. The sentence says what was left out: "This leaves out Shop pad: ground heights are missing under it, or its side slopes run past them."
Cells too coarse are decided once per kind, by the shape's own card's check against the same recorded cell size (round 7, findings G2, C4 and NG2), and the balance reads that check rather than one of its own: a leveling area by gradingPlaneResolutionCheck (what evaluateCutFill reads), a pad by padResolutionRefusal (what its card and padGroundFigures read, including a pad under three of the grid's cells across), a pile or pit by pileResolutionCheck (the rule measureVolume measured it by), and a ditch, dam or levees by their own analyses (section 8). A shape any of these refuses comes in with "the terrain's cells are too coarse for it", so it is out of the figures, the ranges, the map page, the shared link and the design surface download alike, since each of those reads the balance's shapes. Before this, a pad 2.5 m wide on 1 m cells, or a leveling area on terrain recorded at 10 m, was withheld on its card and counted in the balance.
Ranges
As section 7: the whole balance is worked again with the ground raised and lowered by 1.96 σ_z, with shared ground counted once the same way at each shift, and each row's range spans the three. A shape's footprint can change with the shift (a fixed pad's toes move), and each shift is resolved on its own cells. A whole-figure shape adds its own range's ends: one uniform shift moves every shape on the same ground together, so the ends add. At each shift a whole-figure shape still keeps the cells of its footprint from the shapes below it in the list, as it does in the figure, so those shapes give up the same ground in the range as in the figure, and each row's range holds its figure (round 7, finding G1: before this, the range was worked with the whole-figure shapes left out of the cell count, and a pad under a ditch took back the ground the ditch kept, so case 4's fill of 561 m³ came with a range of 741 to 778 m³ at σ_z 0.01 m). balance-range.test.ts holds this over case 4 and over many overlapping arrangements. A ticked shape with no range leaves the total with none, and rangeNote names it. Each shape with a figure but no range carries why in noRange, from the same options its range was decided by (noRangeReason): the terrain states no vertical accuracy, it is recorded as below its quality specification, or, with an accuracy, its side slopes run past the ground heights once the ground is moved; the balance lists them in its own noRange, and a shape's range line under it says that reason (round 7, finding NG7). A shape's line gives a range wherever it has one, even where the figure has no cut or no fill: a pad flush with flat ground cuts and fills nothing as drawn, but on ground 0.196 m higher or lower it does. A pile's kept range (section 12) is the volume tool's own and isn't the one the balance uses: in the balance a pile is worked again with the ground shifted, where a base set at its lowest edge or fitted to its edge moves with the ground, so the shift cancels, and an entered base doesn't.
Reference cases (worked by hand)
All three use flat ground at 100 m on 1 m cells (a 120 m square grid) and section 9's pad: 30 m east-west by 20 m north-south, centered at (40, 40), its top at 101 m, side slopes 3:1. By section 9, case 1, its fill is 759.425 m³ with ε = 1.83 m³, and its cut is zero. balance.test.ts holds the engine to each.
- Two shapes apart. A 20 m square leveled at 99.5 m, from (80, 30) to (100, 50):
400 × 1 m² × 0.5 m = 200 m³of cut, exact since its edges lie on cell edges. The pad's toes reach 3 m out, tox = 58, so the two share no ground.- Cut
200 m³(262 yd³), fill759.425 m³(993 yd³) within1.83 m³. The balance is the sum of each. - At a ratio of 1.25:
200 − 1.25 × 759.425 = −749.28 m³, short980 yd³, within1.25 × 1.83 = 2.29 m³. Engine:−749.30 m³. - With
σ_z = 0.10 m: the fixed yard's cut runs400 × 0.304 = 121.6to400 × 0.696 = 278.4 m³, exactly; the pad's fill is section 9's584.3to948.3 m³, each within its ownε.
- Cut
- Two shapes that overlap. A 60 m square leveled at 99.5 m, from (10, 10) to (70, 70), with the pad inside it, higher in the list.
- The yard alone:
3,600 × 0.5 = 1,800 m³of cut. - The cells the pad changes, counted by centers: 600 on its top; under the straight side slopes, the cells whose centers are 0.5, 1.5 and 2.5 m out (fill
1 − d/3 > 0), three deep along2 × (30 + 20) = 100 m, 300; in each corner, the cells whose centers are under 3 m from the corner:(0.5, 0.5),(0.5, 1.5)and(1.5, 0.5),(1.5, 1.5)at 2.12 m,(0.5, 2.5)and(2.5, 0.5)at 2.55 m,(1.5, 2.5)and(2.5, 1.5)at 2.92 m, but not(2.5, 2.5)at 3.54 m: 8 each, 32. 932 cells. - Counted once: the yard's cut on those cells,
932 × 0.5 = 466 m³, isn't counted. Cut1,800 − 466 = 1,334 m³(1,745 yd³), exact. Fill759.425 m³within1.83 m³. - The naive sum is larger by 466 m³ (610 yd³) of cut:
1,800against1,334 m³. The test checks that the two differ, so a balance that went back to adding each shape's figure would fail. - At a ratio of 1.25:
1,334 − 949.28 = 384.72 m³left over (503 yd³) within2.29 m³; the naive sum would say850.72 m³. Engine:384.70 m³. - With the yard higher in the list instead, it keeps all 932 cells: cut
1,800 m³, fill zero, and the overlap says the pad's759.4 m³of fill wasn't counted. - With
σ_z = 0.10 m, shared ground counted once at each shift: on raised ground the pad's fill is0.804 mand its toe2.412 mout, so it changes600 + 200 + 4 × 4 = 816cells and the cut is3,600 × 0.696 − 816 × 0.696 = 1,937.66 m³. On lowered ground the fill is1.196 m, the toe3.588 mout,600 + 400 + 4 × 11 = 1,044cells, and the cut is(3,600 − 1,044) × 0.304 = 777.02 m³. Engine: the same to the cubic centimeter.
- The yard alone:
- A pile on hand against a fill. A 10 m square of dirt 2 m high, from (80, 80) to (90, 90), measured from a 14 m outline (78, 78) to (92, 92) with its base at the lowest edge, 100 m:
100 × 2 = 200 m³(262 yd³) on hand, exact. The pad is the fill.- Unticked, at a ratio of 1.25: short
1.25 × 759.425 = 949.28 m³(1,242 yd³). - Ticked: short
949.28 − 200 = 749.28 m³(980 yd³), within2.29 m³. Engine:749.30 m³. The pile shows as dirt on hand, never as cut. - A pit of the same size 1 m deep, from a base at 100 m, gives
100 m³of room, and against no cut at a ratio of 1,100 m³short.
- Unticked, at a ratio of 1.25: short
12. A measured pile or pit, kept (plan v4 item 527)
The volume tool (measureVolume, surface-water.md section 3) measures dirt above a base and room below it inside an outline. Keeping the measurement makes a surface feature, MeasuredPileFeature (kind pile_or_pit), from keptPileFromVolume in packages/earthwork/src/pile.ts:
- The base outline and the base as the tool formed it: level at the lowest edge cell, level at an entered elevation, or a plane fitted to the edge cells by least squares, with its heights resolved, so the base is known without the ground.
- The volume above and below the base, the area, and the range the tool shows (stated vertical accuracy × area), or none when the terrain states no accuracy.
- The ground it was measured on, as every kept result records it (plan v3 item 429).
It is a pile when there's more dirt above the base than room below it, and a pit otherwise (pileOrPit), and the list says which in plain words: "Pile, 262 yd³ of dirt" or "Pit, room for 131 yd³". Its figure is the one measured; nothing is worked again on opening the project. In a balance (section 11), its cells are worked again on the ground the balance reads (pileCellChanges), so shared ground can be counted once.
13. A work budget, for a shared link (round 7 of plan v4, findings C5 and NC1)
A shared link works a project's saved shapes on the app's server for anyone who opens it, so each shape's work there is bounded by a count the engine keeps itself (packages/earthwork/src/budget.ts), never by a clock. balanceShapeOf takes an optional budget; any analysis can be run under one with withinWorkBudget. Every loop of the analyses above charges what it is about to do before it runs, in one unit (a cell tested against one side of an outline, with weights for other steps, UNITS), and every list that grows with the shape charges its bytes before it is made and gives them back when it is dropped (BYTES). When a charge would pass either limit, the analysis stops there and the shape comes back with no figure and budgetSpent, its missing set to "it's too large to work out here" (a link says its own sentence instead).
No figure changes. With no budget in force every charge returns at once, and every result, figure and range is bit for bit what it was: the project's screens pass none. Two internal changes came with it, each with the same results: the pond's way-out search (findEscape, section 4) keeps one set of arrays the size of the terrain for all of a basin's parts, putting back only the cells each search touched, where it made a fresh set for each part; and a pad lists only its cells on the terrain, counting those off it, where it listed both (padCellsOf, section 9). The tests: budget.test.ts ("gives every kind of shape exactly the result it gives with no budget", on every kind and a site link's pad card), and every other test in this package unchanged.
The same input and budget, the same outcome. A count is deterministic: the same shape on the same ground with the same budget stops at the same place with the same count (budget.test.ts, "gives the same outcome, at the same count, every time"), and a seeded generator of odd shapes (huge and broken coordinates, thousands of points, self-crossing rings, lines of no length, extreme slopes and widths) never runs past its budget or its memory and keeps time with its count (budget.test.ts, "odd shapes from a seeded generator").
The figures a link uses and how they were timed are in sharing-security-review.md, "R1 again: what one saved shape may cost a link".