Automated layout
packages/layout generates drainage layouts for someone to look at, change and accept. It's pure and repeatable: the same inputs and seed always give the same layouts, with no clocks or unseeded randomness, and everything it makes goes through the same checks as a pipe drawn by hand. New pipes and junctions get IDs from the seed, passing over any that something kept already has.
It runs in the engine worker (see worker-deploy.md). What a layout is worked out from travels with its job, so nothing it reads can change underneath it except the terrain.
The main
A main should run along low ground from the outlet to the far end of where water gathers, since that's where it's cheapest to get water to it and it needs the least digging.
- The surface is averaged into larger cells, at least 5 m and up to about 40,000 across the area. Finding a valley doesn't need 1 m cells, and an average shrugs off a ditch or a rut. Elevations and cover are still worked out from the original surface afterward.
- Where water gathers comes from flooding the surface inward from its edges. Each cell drains to the one that reached it, which always leads out, even across a pit or a flat. This only decides where a main is drawn to. It changes no elevations that are used for anything else.
- The route is the least-cost path from the outlet, by Dijkstra over eight neighbors. A step costs its length, more on high ground and less where water gathers, plus the ground it falls heading upstream, since a pipe would have to dig through that.
- The far end isn't decided here. Routes go to the farthest point it can reach that gathers at least 3% of what the most does, and to the farthest in each of 12 directions, leaving out anything nearly the same as another, or too short to reach much.
Choosing among them
Each route gets the laterals that suit it, and they're ranked by how much digging they all take beyond the preferred depth, keeping the least grade from the head of each drain to its end. An estimate is enough here, since it only compares layouts. Each line that can't be connected counts as a lot of digging, since draining the land is the point. The best three go through the full engine and are offered. This is what keeps a main from running across a side slope, which would look fine and leave half the laterals running uphill to it.
The estimate doesn't have the last word on their order. Once the engine has worked each one out, a main that works is listed ahead of one that only works by going too deep, and that ahead of one with problems. Within each of those they stay in the estimate's order. The pumped layout is made from whichever comes first.
No-tile zones can't be entered, and neither can anything within a cell's width of one. Crossing a road, utility, easement or waterway costs the same as 60 m of going around.
These weights are judgment, not engineering. They're all named at the top of corridor.ts, and no standard gives them. They only decide which route gets looked at. They can't make an unsound design pass, since the result is checked the same as anything else.
Laterals
Laterals are parallel lines across the fields at the narrowest spacing any soil there calls for, the first half a spacing in from the edge, since a drain serves half a spacing on either side. Each stays 3 m back at its ends from a field's edge and from anything kept out, which is our choice so that a machine can turn. Anything shorter than a spacing is left out as not worth its fittings. They're kept out of no-tile zones and land with no soil to drain.
Direction is searched, every 15 degrees. Each direction scores by the share of its length where the ground falls the way its water runs, by at least the grade that gets the smallest pipe to the slowest velocity the standard allows. That counts for most of the score, since a lateral with the ground on its side needs less digging. The share that reaches the main directly counts for the rest, and being square to the main settles a tie.
Where soils differ, each soil can have its own spacing. The best way for the main is offered again with each line set by what it runs through: the narrowest soil that's at least a fifth of that line, so a sliver of something else doesn't set the spacing for all of it. Each spacing gets a block of its own. Because a line runs across soils, land under a line set by a wider soil can get less drainage than it calls for, which "Meets the target water table" shows. The narrowest-everywhere layouts are there to compare.
Each line then goes as far from the last as the ground between them allows, every bit of it being within half its own soil's spacing of one line or the other. Going from 30 m soil into 12 m soil, the last wide line reaches 6 m into the tight soil, and the first tight line is 6 m past that. Going the other way, the last tight line reaches 15 m into the wide soil. The first line is half its own soil's spacing in from the edge.
- Stepping by the last line's own spacing, as it used to, put a line 30 m on even when 12 m soil began partway there, leaving up to 10 m of that soil beyond its 6 m reach.
- Stepping by the narrower of the two lines' spacings would close that, but lays a line more than is needed at every change of soil, and still misses a band of tight soil that lies between two lines with neither in it.
- So the ground between is looked at every half of the narrowest spacing, and where what it calls for changes, the place is found to the nearest millimeter. A band of soil narrower than that half spacing can fall between two looks and be missed.
That leaves no land farther from a lateral than half the spacing of the soil it's in, apart from three places: within 3 m of a line's ends, where lines stop short; within half a spacing of the far edge, where the last line is laid inside the field like any other; and a soil that's under a fifth of the lines through it. A test holds it to that within 1 cm, on fields of two and three soils in strips.
A block can be laid again. Selecting a lateral shows its block's spacing and direction. Changing either lays that block's laterals again over the ground it already covers, connecting to whatever main or submain they cross, or to the nearest within one and a half spacings, unless reaching it would cross ground that isn't a field's. New laterals take the size the old ones had until someone sizes them again. Locked laterals stay as they are, and it's one step of undo.
- A locked main or submain takes the new laterals too. It's divided where each one joins, the same way a new layout divides a kept pipe, with every part staying locked and keeping its name, size, grade line and depth limit. Before this, a locked main refused every tee, so a new spacing under one deleted every lateral and laid none.
- If none of the new lines can be laid, nothing changes, and it says why: how many were too far from a main or submain, how many could only reach one across ground outside the fields, and how many were turned down where they'd connect, as at a locked node. If only some can't be, the rest are laid and it says the same about those left out.
- Junctions the old laterals leave behind are taken out. Where an old lateral met a pipe and no new one does, the junction has one pipe in and one out, which is one pipe in two parts. The two are joined back where they're alike, with the corner and grade point at the joint dropped if the pipe runs straight and on one grade through it. Without that, each change of spacing cut the mains into more pieces: 11 became 22 after four changes. Two locked parts are joined the same way and stay locked. Parts that differ stay apart, as where a main changes size or only one side is locked, and so does anything at a locked node or a tie-in.
Connecting them
A lateral that meets the main splits there, with both sides running to it. The main breaks into pipes at each connection, so flow adds up along it the same as a drawn one.
What doesn't reach the main gets a submain. Neighboring lines form a group, which breaks wherever they're more than one and a half spacings apart. A submain runs square across a group from the nearest point on the main, and each lateral runs into it from whichever sides have at least a spacing of room. If a no-tile zone is in the way, the lines beyond it gather along their ends nearest the main instead, and that submain takes the shortest way around. Only what can't get around at all is left out, and the explanation says how many. A line that ends within half a meter of where its submain would join the main has its laterals join there instead, since a pipe that short isn't one.
Staying inside the fields
Ground outside every field is someone else's, or a road, or a yard. A field with a notch in its edge, such as a U around a farmstead, has ground like that between two parts of itself, and the shortest way from one part to the other is across it. No generated pipe goes that way.
- Laterals are cut to the fields to begin with. Under a wet spot, whose outline can reach past an edge, they're cut again.
- A submain's straight run stops at any line it could only reach by leaving the fields. It carries on to the next line it can reach, and the lines it passed over gather along their ends nearest the main, the same as beyond a no-tile zone. Lines the same distance across can be on either side of a notch, so each joins whichever run it can reach.
- A submain's way around, and a main, are found over cells of ground, where a step that goes out of the fields from inside them costs more than any way around could. So a route only leaves where nothing else gets there. Each step is checked against the fields' real edges, not the cells, so a route can't cut the corner of a notch either, and straightening a route afterward isn't allowed to pull it out.
- A submain joins the main where the main is in a field, not where it has run on past the edge to an outlet.
What still leaves a field, and should:
- A main reaching an outlet placed outside the fields. An outlet within 3 m of an edge counts as on it, since nobody places one to the meter, and its main comes to it from inside. Further out than that, the main is free to come in from the outlet however is cheapest, which can be across a notch if the outlet is in one.
- The one main between fields too far apart to lay out together, and a pipe across the gap between fields near enough to be laid out together, such as a road. There's no other way between them.
- Anything on the far side of a no-tile zone that cuts a field in two, which can only be reached around the outside.
Where the terrain's cells are too coarse to find a way through a neck of a field narrower than a cell or two, a route treats that as no way through and crosses outside instead. Cells are 5 m at the smallest.
Depth, grade and whether gravity works
A generated network goes through the same engine as a drawn one: service areas, flow, sizing from the catalog (including the criteria's single-drain length limits, which travel with the layout job), then grades and inverts from the original surface, then every check. Nothing about it is held to different rules, and nothing about the depths or grades is stored beyond what a drawn pipe would have, so it recalculates the same way once accepted.
A layout is "feasible" only when the design's own checks raise no problem on the pipes it lays (plan v3 item 435): every pipe has fall, meets the least grade, carries its flow, stays within the slowest and fastest allowed velocities, has its cover, stays within the criteria's single-drain length limit for its size, has ground data and roughness, stays connected to an outlet without a junction mismatch or network error, clears no-tile zones and crossing cover/depth limits, keeps its hydraulic gradeline below ground, satisfies any lift-station pump checks, and satisfies any locked control-structure crest checks. Being too deep is a caution rather than a problem, as with any pipe, since a narrower trench or heavy-duty tubing can allow it.
A feasible layout that goes too deep isn't a plain pass. Each layout keeps a count of its pipes past NRCS's trench depth for standard tubing. With any, its badge reads "Gravity works, but deep" or "Works with a pump, but deep" in the caution color, and the outlet table says the same. It can still be used. A layout saved before that count was kept is judged by its own first line, which says the same thing in words.
This can't say the outlet works, because a layout job only receives each outlet's lowest allowed invert (from surveyed invert or normal low water, when entered), not its separate surveyed-invert tolerance, tailwater, or receiving-capacity measurements. So it can catch a main arriving below a recorded outlet invert or low-water level, and says how far below the ground the main reaches the outlet for someone to compare, while full outlet checks (and any tailwater effect on gradeline or pumping head) run once a layout is accepted.
Choosing one
What a job comes up with is listed best first, each saying whether gravity works and why it came out as it did. "Show on map" draws one over the design without changing it. "Use this layout" takes it into the scenario as one step of undo, after asking if that would replace pipes already there. The outlet keeps its ID, so what's been measured there stays with it.
The outlet is the design's own, not a new one in the same place. Every outlet travels with the job, locked or not, and a layout to one uses it as it is, so the engine works to its invert if it has one. Taking a layout keeps the outlet as it is at that moment, with its name and invert, in case either was set after the layout was made. An outlet the layout doesn't drain to isn't in it.
The list shows the latest job's layouts, which are kept with the scenario, so they're still there after a reload. A job's layouts are saved in one transaction, each with the job and its place in the list, so a failure part way leaves what was there before. A job can run twice, when its worker stops after saving and before marking it done, and the second run replaces what the first saved rather than adding to it, which had shown every layout twice. Saving a job's layouts also removes earlier jobs' for the scenario, since only the latest are shown and the one taken is copied into the design. A list that can't be read says so with Retry.
Wet spots
Where the ground holds water, each outlet also gets a layout with tile only under those spots. A spot is somewhere water would stand: at least 0.1 m below where it would spill out, the same as the terrain's low spots, and at least about a quarter acre, which is our judgment of what's worth tile of its own. The twelve that hold the most are used. A main runs from the biggest to the outlet—or, when a locked or existing main already reaches that outlet, that trunk stays as the main—laterals go in at the soil's spacing over each spot while staying clear of any locked lateral (at least half a spacing away), and submains bring the others back.
It costs far less and leaves the rest of the field as it is, which "Meets the target water table" will show.
Comparing outlets
Every outlet in the design gets its own layouts, up to three each. Asking for it also tries the two lowest points along the fields' edges, at least a fifth of the field's size apart and away from outlets already being tried. Nothing here knows if there's a ditch at a low point. It's a suggestion to compare, and accepting one still needs its outlet checked in the field.
When there's more than one to compare, a table shows the best layout for each: whether gravity works, how deep it goes, and what it comes to at the current prices. Each layout also says how much pipe it takes, the share meeting the target water table and how much lateral per acre, and the cost says if it's using placeholder prices.
What's locked
Whatever's locked stays exactly as it is in every layout, and the rest is laid out around it.
- A locked run of main or submain that reaches an outlet is the main. Nothing else is tried, including for "wet spots only" and standalone targeted layouts (
planWetSpotsuses the locked trunk rather than routing a second main;packages/layout/src/generate.test.ts). Only that outlet gets layouts, and any other says why it didn't. - New laterals have to join it somewhere, so a kept pipe is divided there, the same way drawing a lateral onto it would. The part above keeps the pipe's ID. Every part keeps its name, size, material, cover, depth limit, phase and lock. Grade points and inflows go with the part they're on, with a grade point added at the cut so the grade line is the same as before. Land held in reserve stays whole on the part above, so it's counted once. A pipe with nothing joining it isn't touched.
- A locked lateral stays, and no new line is laid within half a spacing of it, since it already drains that ground—across whole-field patterns, split zones, standalone targeted layouts, and "wet spots only" alike (
packages/layout/src/generate.test.ts). - Anything else locked stays too, even if it doesn't connect to anything new, which then shows up in "Review conflicts".
Pumped layouts
Where gravity can't reach an outlet, or might not, the best layout for that outlet is offered again with a lift station. The gravity pipes stay as they were, since a pump at the end doesn't change how far they have to fall, and a force main takes the water the last 15 m to the outlet, with anything else that reached the outlet going to the station instead. If going straight there would cut across a corner of the field, it goes by way of where the outlet is. That distance is our choice, to stand off a ditch bank, and it can be moved like anything else.
- With the outlet's level measured, from its invert or low water, a main arriving below that fails by gravity, and says by how much. That's what NRCS means by a site "where the outlet is at an elevation that does not permit gravity flow from drains located at depths required for adequate drainage". A main arriving above it isn't offered a pump at all.
- With nothing measured, nobody knows how deep the outlet is. So the pumped one is offered once a main arrives more than about a foot and a half deeper than the drains, also our choice, since a main always arrives a little deep, and it says it's for if the outlet isn't that deep.
It picks the project's pump that does the job with the least to spare, since none come built in. With none entered, or none that will do, it says so and states what the pump has to do, and it can be chosen once the layout's accepted.
On long flat ground, mains can run out of grade at the depth NRCS gives for its widest trench, 6.2 ft, even with depth shared along the run. Then, with no outlet left to reach by gravity, depth is what there is to give, so a pumped main may go to 8.9 ft for its grade, and the layout says so. That's from NRCS's Figure 14-41, which allows 8.9 to 9.2 ft for 10 to 12 in at 1.3 ft wide, "based on limited research". Going past 6.2 ft stays a caution. The table stops short of larger sizes at that width, so they need their own strength check, as any pipe past 15 in does here.
Several stations along a long main could keep it shallower, at the cost of more pumps. This doesn't try that.
Several fields
Fields within three lateral spacings of each other, across a road or a fence line, are laid out together. Fields further apart each get a main of their own, with laterals in whichever direction suits that field, running across to the main nearest the outlet and joining it where they come closest. So there's one pipe across the gap rather than a run of submains side by side, and the mains below the join are sized for both fields. If a field can't be reached that way, the layout says so.
Terrain has to reach between fields for that. The area worked out for elevation data and soils adds a strip 200 m wide along the shortest line between fields that are apart, so a project doesn't need a hull covering everything between them. Past about 3 miles apart, nobody runs one main between them, and no strip is added. Both of those are our choices. A main that wanders outside the strip has no ground to work from, and comes up as a gap in the data like any other pipe. Terrain built before this doesn't have the strip, so it needs building again.
Selecting a pipe that drains more than one field says how much of each, from every pipe above it.
A layout that leaves land out (plan v3 items 432 and 428)
Whether a layout works is about the pipes it lays: grade, cover and capacity within their limits. It says nothing of how much of the land asked for it reaches or serves.
Each layout is checked in two ways, both using the signed geometric definition of served land (see question 5 of plan-v3-signoffs.md):
- Whole fields left out (item 432): A field counts as reached when any lateral has a corner, or the middle of one of its stretches, inside it. A field with only a main through it is not reached. A layout that leaves any field out is marked partial beside its verdict, naming each field and its acres, and its first design note says so.
- Unserved drainable land (item 428): Drainable land is the ground inside the requested fields outside no-tile zones and land with no soil to drain. A point of drainable land counts as served when it lies within half its soil's own spacing of at least one lateral (never measured as pipe length times spacing, so served acres can never exceed drainable acres). Measured deterministically on a regular square grid (
measureCoverageinpackages/layout/src/coverage.ts, targeting 45,000 samples across the fields' bounding boxes at 1 m to 4 m resolution, capped at one-sixth of the narrowest soil spacing), any layout that leaves more than 0.10 of drainable land unserved (PARTIAL_UNSERVED_SHARE_LIMIT, a judgment) is marked partial beside its verdict for every pattern—including targeted wet-spot layouts—and names each field with its unserved acres.
Marking a layout partial is a label beside its verdict, never in place of it, and changes no ranking or choice of layout.
Trying options
"Try options" runs the generator across combinations of spacing, drainage coefficient, pipe line and outlet, as one job on the engine worker, up to 40 layouts at a time. Its runs are saved whole and once, the same way as layouts, under the job's own ID, and replace the scenario's earlier sweeps. For each it keeps the cheapest layout that works, or else the cheapest, so one that can't work is there to see. Each is priced like anything else, using the prices entered so far: a pipe line's products at their own prices where they have them, and at the price for their size where they don't (see costing.md). Until a line's products are priced, two lines differ in cost only by the sizes each needs. Wet spots aren't in it, since draining part of a field isn't comparable.
- Spacing goes as a share of what each soil calls for. A wider spacing costs less but its line reaches further on paper than the soil allows, so "meets the target" is worked out from the soil's own spacing, not what the line is laid at. That's what makes wider spacing show up as less land meeting the target rather than as a saving for nothing.
- Coefficient changes the flow every pipe is sized for, and so what can be carried.
- Phasing adds a version with the mains and the nearer half of the laterals first, and the rest later. It costs the same in total and less up front. Mains are sized for everything either way.
The trade-off table picks out what nothing else beats: no other run that works costs less without meeting the target on less land or having less capacity. These are judged on cost, the share meeting the target and the achieved coefficient. Phasing isn't one of them, since going in later isn't simply better. Only runs that work can be picked out, and none is called best, since which of them is right depends on what someone values.
Pattern and direction choices (Plan v2 PR 42; Plan v3 PR 49, items 390–393 and 428)
When no pattern or direction rule is specified, the generator runs the automatic 15° orientation search described above so existing designs and benchmark hashes stay identical. When a user explicitly selects a pattern or direction rule:
- Direction rules (Across slope, Down slope, Set angle, Parallel to edge): Across slope and Down slope estimate the field's area-weighted mean downhill gradient from the original DEM; Set angle uses the entered bearing clockwise from north; Parallel to edge aligns laterals with a picked field edge or drawn reference line.
- Reaching zones and separate fields away from the main (item 392): When a split zone or a separate field is away from the first main, every explicit pattern uses the same routing steps as the automatic layout (
nearestApproach,routerAroundandmainCorridors, tied into the main viajoinBranch): a"submain"into an unreached zone of the same field, or a"main"into a separate field cluster. If routing fails, the layout names which step failed—routing across to the main, routing inside the region, fitting laterals at the chosen spacing, or joining the main—in words a user can act on. - Herringbone: Laterals join both sides of the main (or branch collector) at a user-adjustable join angle (default 45°, allowed 15°–85°). Station spacing along the main is
spacing / sin(angle)so perpendicular spacing between adjacent runs matches the target drain spacing. - Curved laterals (item 390): Built to the five-point rule in question 5 of plan-v3-signoffs.md:
- Across the slope, slightly off contour: Laterals fall toward their collector at a target ground fall of
max(0.3%, leastGrade)(CURVED_TARGET_GRADE = 0.003, never flatter than the criteria's minimum grade for the lateral's size). - Parallel curves per block: One guide curve is traced across the slope on each side of the collector, and the block's remaining laterals are laid as parallel offset curves beside it at the target spacing, phase-aligned half a spacing inside the edge. Because adjacent curves stay parallel, no land between two neighbors in a block is farther than half its soil's spacing from one of them, and the old 1.35× divergence-infill limit is removed. The 0.65× convergence limit (
CURVED_MIN_SPACING_SHARE) stays: a lateral ends where it converges within 0.65 of a spacing of a neighbor or an earlier block's lateral. - Submains on the steep ground: Laterals that reach the low-ground main join it directly. Unserved regions on each side of the main get submains routed up the slope by item 392's routing, each with its own block of curved laterals off both sides, stopping once geometric coverage is within
CURVED_COVERAGE_SHORTFALL_LIMITof parallel on the same field, main and spacing, or when another submain no longer improves coverage withinCURVED_TWICE_SERVED_EXCESS_LIMIT. - Bend radius: Every vertex on every curved lateral honors the user-entered minimum plow bend radius (never assumed by the software), checked after polyline resampling with no under-radius slack. Every intermediate curve vertex is stored on the
NetworkEdgeso curved laterals pass through the exact same hydraulic, cover, grade, sizing and profile calculations as straight runs. - Falling short: A curved layout that still trails parallel by more than
CURVED_COVERAGE_SHORTFALL_LIMIT(or leaves more thanPARTIAL_UNSERVED_SHARE_LIMITunserved) states the geometric share it serves in its design notes and is marked partial like any other layout. - What curved-run tests hold (item 391):
packages/layout/src/curved-runs.test.tsandapps/web/src/lib/network/profile-run.test.tsverify that a curved lateral's length matches the hand sum of its segments (strictly longer than its chord); that a curved lateral and an equal-length straight lateral on equal-fall ground get the same grade, Manning capacity, velocity, cover (to the outside top) and checks within stated chord-vs-arc and grid-cell tolerances; that a dip or rise under the curve midpoint changes cover or trench depth while the same feature under the straight chord does not; that a curved line whose arc length exceeds a single-drain limit (even when its chord is under the limit) triggerstoo_longand sizes up by the same Minnesota and Iowa rules as a straight run; that no generated curved lateral tighter than the entered bend radius reaches the checks; and thatbuildProfileRunandprofileSvgdraw stations and cover-violation bands along the curved path's true length. Note thatcheckDesignitself has no bend-radius check kind yet, so manually dragging a curved lateral's vertex tighter than its block'sminBendRadiusMis not flagged bycheckDesign.
- Across the slope, slightly off contour: Laterals fall toward their collector at a target ground fall of
- Targeted: Runs the wet-spot generator directly as a pattern choice beside Parallel, Herringbone, and Curved.
- Split zones and block memory: A field can be divided along a drawn line using Sutherland-Hodgman half-plane clipping so each side receives its own pattern, direction, and spacing. Each
LateralBlockrecords its pattern parameters so regenerating a block preserves its style while leaving locked pipes and other blocks untouched.
What is judgment in patterns and coverage
No published drainage standard read for plan-v3-signoffs.md question 5 gives numeric tolerances for curved-lateral coverage, double drainage or partial layouts. Every one of these values is a judgment, named as an exported constant in packages/layout so an engineer can adjust it in one edit:
CURVED_TARGET_GRADE = 0.003(patterns.ts): 0.3% target uphill tilt off contour, floored at the criteria's minimum grade.CURVED_MIN_SPACING_SHARE = 0.65(patterns.ts): minimum spacing share before a converging curved lateral terminates.CURVED_COVERAGE_SHORTFALL_LIMIT = 0.05(coverage.ts): how far short of parallel's served share a curved layout may fall on the same field, main, spacing and kept-out ground.CURVED_TWICE_SERVED_EXCESS_LIMIT = 0.10(coverage.ts): how much more drainable land than parallel a curved layout may serve by two different laterals.PARTIAL_UNSERVED_SHARE_LIMIT = 0.10(coverage.ts): share of drainable land left unserved above which any layout is marked partial beside its verdict.- Submain loop guards (
MAX_CURVED_SUBMAINS = 8,MIN_CURVED_SUBMAIN_GAIN = 0.015inpatterns.ts) and coverage grid target (TARGET_SAMPLES = 45,000,1 mto4 mstep incoverage.ts) are implementation choices that bound runtime and discretization error without changing any hydraulic calculation. - Candidate curved-submain ranking weights in
planCurvedWithSubmains(patterns.ts:gain - 0.35 * extraTwice - 0.00005 * pathLength) and curvature-relaxation parameters (1.02radius margin inpatterns.ts; relaxation step weightmin(0.45, 0.5 * (1 - radius / minRadiusM) + 0.05)for up to60iterations incurvature.ts) are implementation judgment choices that select submains and keep every resampled vertex at or above the user-entered minimum bend radius.
Pattern regression matrix (item 393)
packages/layout/src/pattern-matrix.test.ts runs all four explicit patterns (parallel, herringbone, curved at a 23 m minimum bend radius, and targeted) across seven deterministic offline fixtures—the three real test fields plus four synthetic fixtures—and compares all 28 cells against packages/layout/src/pattern-matrix-table.ts:
- Real test fields (12 cells): Offline 3 m average-resampled USGS 1 m DEM (NAVD88) and SSURGO soil fixtures in
packages/layout/fixtures/real-test-fields/(fetched by hand withfetch_real_test_fields.py; tests never touch the network), picked by one repeatable public-data rule near eachcheck_marks.pytest point:fargo-nd(T138N R49W Sec 9 NW 1/4, 156.96 ac, 1.33 m relief, 4 Fargo silty clay map units, ND NRCS 606 2024),mankato-mn(T108N R26W Sec 29 SW 1/4, 158.31 ac, 10.89 m relief, 14 glacial-till and muck map units, MN NRCS 606 2023), andbrookings-sd(T110N R50W Sec 15 NW 1/4, 159.35 ac, 6.03 m relief, 10 Barnes/Swenoda/Badger/alluvial map units, SD NRCS 606 2024 with user-entered 3/8 in/day coefficient andmaxVelocityMS: null). Soil spacings are computed at test time from the SSURGO attributes via@tilemapper/soilandzoneSpacing, outlets are placed bylowPointsOnEdge, and pipes use the generic NRCS corrugated plastic catalog (3–18 in). - Synthetic fixtures kept alongside them (16 cells):
flat-two-soil(dead-flat 400×400 m field with 20 m clay and 40 m loam),valley(item 390 V-valley, 18 m loam),wet-spots(sloping 400×400 m field with two depressions and a 40×40 m no-tile zone), andtwo-field(clusters.test.ts, 43.00 ac across a 150 m gap, 30 m spacing). These stay in the matrix to pin isolated edge cases that the single-quarter real fields do not cover individually: an interior no-tile keep-out zone, a symmetric V-valley for curved-vs-parallel checks, a sharp two-soil strip boundary, and the 150 m two-field cluster gap. - What the table records and enforces: For each of the 28
(field × pattern)cells, the table holds the 36-characternetwork-6fingerprint (recorded afresh fromnetwork-5for item 405, with nothing else in the row moving), feasibility and partial flags, pipe and per-field lateral counts, per-category{ passed, cautioned, failed }check tallies covering all 19DesignCheckkinds plus gradeline, constraints, and connections, and geometric served shares overall, by field, and by soil (or the"no_alternative"note when a field has no closed wet spots fortargeted). The test fails if served acres ever exceed drainable acres (overall, by field, by soil, or in hydraulicserviceAreas), if explicitparallelorherringbonefails to lay laterals in both fields oftwo-field, if any curved lateral violates the entered 23 m bend radius, or if running a pattern twice produces a different hash. Partial layouts and real-field capacity or velocity findings (such as 18 in NRCS corrugated plastic running over capacity on full ~158-acre quarter sections, or steep pipes on Mankato exceeding 12 ft/s) are recorded honestly as they stand rather than tuned away.
Wizard preview and depth choice (plan v3 items 388 and 389)
The pattern wizard draws what generateLayouts will lay rather than an approximate stand-in:
- One source of geometry and cost:
buildLayoutEngineInputsandpriceLayoutAlternativeinapps/web/src/lib/network/layout-preview.tsbuild the exact engine inputs and cost estimate for both the wizard preview and thelayout.generatejob. The wizard keeps one deterministic seed per session and passes that seed to Generate so the previewed alternative matches the top-ranked generated layout in network fingerprint, footage, and price (verified inapps/web/src/lib/network/layout-preview.test.ts). Even the four small pattern cards rungenerateLayoutson a tiny synthetic grid once and cache the result. - Same terrain as the engine worker: The browser reads the full original DEM once through the shared tile cache (
demReader.readGrid()), maps no-data cells toNaN, and appliesadjustGridwith the project's adopted survey differences—the same stepsservices/engine-worker/src/handlers.tsruns before callinggenerateLayouts. Without terrain, an outlet, or a pipe product, the wizard withholds the preview and says what is needed instead of approximating. - Off the main thread:
apps/web/src/lib/network/layout-preview.worker.tsrunsgenerateLayoutsin a web worker, managed byLayoutPreviewClient(apps/web/src/lib/network/layout-preview-client.ts). The elevation grid is uploaded once per worker and reused across edits while idle. When wizard choices change mid-run, the busy worker is terminated immediately so stale work stops and late replies are ignored, and the newest choices start on a fresh worker. Worker errors, crashes, timeouts, and terrain read failures surface plainly with Try again. - Drain depth on the spacing step (item 389): Step 3 lets the user edit the drain depth in feet, states where the value in use came from (the project's saved Drain spacing or the user's entry in the wizard, alongside the active standard's cited minimum cover—never inventing a regional default depth), validates it the same way the criteria and spacing forms do, and recalculates per-soil spacing figures and layout
SpacingZone[]throughspacingInputsandsoilZoneSpacings(apps/web/src/lib/network/wizard-depth.ts). Nothing is persisted while editing in the wizard; pressing Generate saves the changed depth viasaveSpacingSettingsand sends the matching depth and recalculated zones tolayout.generate.