/**
 * California at state scale: the whole corridor, Los Angeles to San Francisco.
 *
 * This is the **default board** — the first frame an anonymous visitor sees —
 * and for a long while it was the weakest thing in the product: a pale sand
 * lozenge with a few soft brown smudges where the ranges should be and no
 * cities on it at all. Everything below is the answer to *why*, and the three
 * answers are worth writing down because they are not obvious and none of them
 * is a bug in the engine.
 *
 * ### 1. Relief is measured in metres and this board is measured in kilometres
 *
 * `latScale: 58` puts one scene unit at **1,919 m**, against Southern
 * California's 391 and San Francisco's 94. Relief does not scale with the
 * board: the Sierra is 4 km high whether you are looking at 100 km of coast or
 * 600. So the number that decides whether a board has mountains is not the
 * exaggeration on its own, it is **scene units of height per metre of ground**
 * — `verticalExaggeration / metresPerUnit`:
 *
 * | board | m/unit | exaggeration | units per metre |
 * | --- | --- | --- | --- |
 * | San Francisco | 94 | 3.6 | 0.0382 |
 * | Southern California | 391 | 3.4 | 0.0087 |
 * | California, before | 1,919 | 2.25 | **0.0012** |
 * | California, now | 1,919 | 13 | 0.0068 |
 *
 * At 0.0012 a 3,000 m range stood 1.6 units off a board 284 units tall — half
 * of one percent, which is a stain and not a mountain. 13 puts this board
 * within striking distance of SoCal's vertical scale, so the two read as the
 * same landscape at two zooms rather than as two different planets.
 *
 * ### 2. Ground colour saturates at 150 m, so the *parks* carry the ranges
 *
 * `terrain.ts` ramps `flats → upland` over the first 150 m and then stops: a
 * 4,000 m summit and a 200 m hill are painted exactly the same colour. That is
 * the right call for a city — see the comment there about Nob Hill — and it
 * means a statewide board cannot get its structure from altitude. It has to get
 * it from **land use**, which is what `parks` is: the Coast Ranges, the
 * Transverse Ranges and the Sierra forest belt are drawn as wildland and come
 * out green, the Central Valley stays farmed gold, and the crest above the tree
 * line and the desert east of it are left out of the parks and come out rock.
 * Southern California already works this way — its green San Gabriels are
 * `ANGELES_FOREST`, not a height ramp.
 *
 * ### 3. A lot is a unit of the picture, not of the ground
 *
 * `blocks.ts` holds a fixed 0.42-unit lot, which is 40 m in San Francisco, 164 m
 * in Southern California and **806 m here**. That is not a mistake to be
 * corrected: the three boards are 1003, 308 and 284 units across and are all
 * looked at from a comparable standoff, so a lot that is legible on one is
 * legible on the others. What it does mean is that San Francisco *proper* is
 * thirteen lots wide and can never be a dense settlement on this board by
 * itself. So the districts here are **conurbations** — the Bay Area, the LA
 * basin and its valleys, the Central Valley towns — which is also the honest
 * unit at 600 km. City detail still lives one board in.
 */

import CALIFORNIA_TRANSPORT from "../transport/california.ts";
import type { City, District, Hill, LatLng } from "../engine/types.ts";

function routePath(routeId: string): LatLng[] {
  const route = CALIFORNIA_TRANSPORT.routes.find((candidate) => candidate.id === routeId);
  if (!route) throw new Error(`california: missing transport route "${routeId}"`);
  const segments = new Map(CALIFORNIA_TRANSPORT.segments.map((segment) => [segment.id, segment]));
  const nodes = new Map(CALIFORNIA_TRANSPORT.nodes.map((node) => [node.id, node]));
  const points: LatLng[] = [];
  for (const id of route.segmentIds) {
    const segment = segments.get(id);
    if (!segment) continue;
    const from = nodes.get(segment.fromNodeId)?.position;
    const to = nodes.get(segment.toNodeId)?.position;
    if (!from || !to) continue;
    if (points.length === 0) points.push([from.lat, from.lng]);
    points.push([to.lat, to.lng]);
  }
  return points;
}

export const CALIFORNIA_US_101 = routePath("la-sf-us-101");
export const CALIFORNIA_I_5 = routePath("la-sf-i-5");

/**
 * Longitude's foreshortening at this board's centre latitude.
 *
 * `World` computes exactly this from `city.center.lat` — 37.3 now that the
 * board is the whole state — and uses it inside
 * `elevationAt`, so any spacing measured here has to be measured the same way
 * or a chain running east-west comes out with its peaks 22% further apart than
 * one running north-south. Repeated rather than imported because `cities` must
 * not import `engine` — see ARCHITECTURE.md §2 — and kept next to the one
 * function that needs it.
 */
const LNG_SQUASH = Math.cos((37.3 * Math.PI) / 180);

/**
 * A range as a chain of peaks along a line, at the spacing that makes a chain
 * into a ridge rather than into a row of domes.
 *
 * The arithmetic is in the note on `HILLS` below and this is where it is
 * applied: two equal peaks a fraction `s` of a radius apart meet at
 * `1.35 × (1 − s²/4)²` of their own height, so `0.9` puts the saddle at 85% of
 * the summit — a continuous crest with notches in it. Writing that spacing out
 * by hand is what produced the board's worst-looking mistake twice: the Coast
 * Ranges shipped once at 1.5 radii and came out as separate domes, and the
 * desert shipped once with one bell per range and came out as bubble wrap.
 *
 * Three things beyond the spacing, all of them about not looking generated:
 *
 *   - **The ends fall away.** A range front is highest somewhere in the middle
 *     and dies out at both ends; a chain of identical peaks is a wall with
 *     square ends, and at 1,919 m to the scene unit a square end is very
 *     obviously a square end. `1 − 0.42 × (2t − 1)²` is the taper.
 *   - **The line is not a line.** Each peak is nudged perpendicular to the
 *     chain by up to a fifth of a radius, so the crest wanders the way a real
 *     range front does instead of being drawn with a ruler.
 *   - **The nudge is deterministic.** It comes off a hash of the range's own
 *     name and the peak's index, so a board looks the same on every reload and
 *     two people looking at it see the same mountains. `Math.random` here would
 *     be a different state on every page load.
 */
function ridge(
  name: string,
  from: LatLng,
  to: LatLng,
  elevation: number,
  radius: number,
): Hill[] {
  const [lat0, lng0] = from;
  const [lat1, lng1] = to;
  const dLat = lat1 - lat0;
  const dLng = lng1 - lng0;
  const length = Math.hypot(dLat, dLng * LNG_SQUASH);
  const steps = Math.max(1, Math.round(length / (radius * 0.9)));

  // Unit normal to the chain, in the same squashed metric, then unsquashed on
  // the way back into longitude so the nudge is the distance it claims to be.
  const nLat = length === 0 ? 0 : (-dLng * LNG_SQUASH) / length;
  const nLng = length === 0 ? 0 : dLat / length / LNG_SQUASH;

  const hills: Hill[] = [];
  for (let i = 0; i <= steps; i += 1) {
    const t = steps === 0 ? 0.5 : i / steps;
    // A 32-bit integer hash of the name and the index. Any cheap avalanche
    // would do; this one is fnv-1a's constants because they are memorable.
    let h = 2_166_136_261 ^ i;
    for (let k = 0; k < name.length; k += 1) {
      h = Math.imul(h ^ name.charCodeAt(k), 16_777_619);
    }
    const wander = (((h >>> 8) & 0xffff) / 0xffff - 0.5) * 0.4 * radius;
    hills.push({
      name: steps === 1 ? name : `${name} ${i + 1}`,
      lat: lat0 + dLat * t + nLat * wander,
      lng: lng0 + dLng * t + nLng * wander,
      elevation: Math.round(elevation * (1 - 0.42 * (2 * t - 1) ** 2)),
      radius,
    });
  }
  return hills;
}

/**
 * Original, hand-traced coast silhouette for this board. It is a drawing, not
 * survey data — see ARCHITECTURE.md §3.2 for why every coastline in this repo
 * has to be.
 *
 * Two things about the shape are deliberate.
 *
 * **The polygon goes in through the Golden Gate.** San Francisco Bay used to be
 * absent altogether and the peninsula was a straight line, which cost the board
 * the one piece of California anybody can identify from orbit. Modelling the
 * bay as `inlandWater` would have been cheaper by one draw call and wrong: the
 * bay is tidal salt water joined to the Pacific, and a lake sitting next to a
 * sea it does not touch reads as exactly that. So the trace runs south down the
 * ocean, turns east through the Gate along the Marin shore, up into San Pablo
 * Bay, back down the East Bay, around the south bay at Fremont, north again up
 * the peninsula and out through the Gate on San Francisco's own waterfront.
 * Winding stays consistent — land is always on the left — which is what
 * `ShapeGeometry` needs to triangulate the shore plate.
 *
 * **All four sides are now the state's own edges, and none of them is a crop.**
 * The Pacific is a coast, the south is the Mexican border, the east is the
 * Colorado River and the Nevada line, and the north is the 42nd parallel. That
 * last one is what this trace was extended for and it is the whole of the
 * owner's first complaint: the board used to close along 38.13 N with a ruled
 * segment, so it drew the southern two thirds of California while the minimap
 * beside it drew the whole state, and the two disagreed about the shape of the
 * place in a single frame. A ruled line across the top of a silhouette is not a
 * subtle defect — it is the one edge of the state everybody can name after the
 * coast.
 *
 * The three artificial closures follow one rule, which is that they sit just
 * *outside* `bounds` so that the land covers the outermost row or column of the
 * lattice and no strip of sea is left along the edge of the frame. The Mexican
 * border is two hundredths below `bounds.minLat`; the Oregon line is two
 * hundredths above `bounds.maxLat`. Neither is a crop and neither leaves a
 * moat. (`coastalFalloff` ramps relief to zero within `coastFalloff` of any
 * polygon edge, so the bottom and top rows of ground are flattened — which is
 * what a state edge should look like, and is what the Nevada line has always
 * looked like.)
 */
export const CORRIDOR_LAND: LatLng[] = [
  // ---- The Oregon line, where it meets the sea ---------------------------
  //
  // 42.07 N and not 42.05, and the two hundredths are the same trick the
  // Mexican border plays at the other end of the state: the closure sits just
  // *outside* `bounds.maxLat`, so the land covers the top row of the lattice
  // and no strip of sea is left along the top of the frame pretending to be
  // Oregon. The real parallel is 42.00, which is 7.8 km south of this and 4
  // units on a 554-unit board — a rounding error at 1,919 m to the unit, and
  // the honest direction to round in, because the alternative is a visible
  // moat between California and a state that is not on this board.
  [42.07, -124.23],

  // ---- The North Coast, Oregon to Point Reyes ----------------------------
  //
  // Two hundred and fifty kilometres of coast that used to be open ocean, and
  // the reason the board disagreed with its own minimap about the shape of
  // California. The three things worth getting right are all in the first
  // eighty kilometres of it.
  //
  // **Cape Mendocino is the westernmost ground in the state**, at -124.41, and
  // it is the corner that makes the northern silhouette read as California
  // rather than as a coastline in general — the coast runs almost due south
  // from the Oregon line, turns hard west at Trinidad, and then bends back
  // south-east for four hundred kilometres to the Golden Gate. Miss the cape
  // and the whole North Coast is a straight line.
  //
  // **Humboldt Bay is not traced**, for the reason San Diego Bay is not: it is
  // thirty-five kilometres long and two wide, which is a scratch a pixel across
  // here, and every extra inlet is a self-intersection waiting to happen. The
  // spit stands in for both shores.
  //
  // **The Lost Coast is drawn as a coast and not as a bay.** Between Punta
  // Gorda and Shelter Cove the King Range rises 1,246 m out of the surf in five
  // kilometres; there is no road along it in life and there is no indentation
  // in it here.
  [41.99, -124.21], // Smith River
  [41.87, -124.2],
  [41.76, -124.21], // Point St George and Crescent City
  [41.55, -124.08], // the mouth of the Klamath
  [41.3, -124.1],
  [41.05, -124.15], // Trinidad Head
  [40.87, -124.18],
  [40.77, -124.24], // the Humboldt spit, off Eureka
  [40.62, -124.35], // False Cape
  [40.44, -124.41], // Cape Mendocino — the westernmost ground in California
  [40.28, -124.36], // Punta Gorda
  [40.1, -124.13], // Shelter Cove, the foot of the King Range
  [39.9, -123.95],
  [39.72, -123.83], // Cape Vizcaino
  [39.5, -123.79], // Fort Bragg
  [39.3, -123.8], // Mendocino
  [39.1, -123.72],
  [38.95, -123.73], // Point Arena
  [38.75, -123.53],
  [38.55, -123.32], // Fort Ross
  [38.35, -123.07], // Bodega Head
  [38.2, -122.99],

  // ---- Pacific coast, north to south -------------------------------------
  [38.05, -122.98],
  [38.0, -123.02], // Point Reyes
  [37.93, -122.79],
  [37.84, -122.55], // Marin headland, the north side of the Gate

  // ---- In through the Golden Gate: Marin shore, then San Pablo Bay -------
  //
  // San Pablo Bay stops at 38.04, one hundredth of a degree below the top of
  // the board, and that number is load-bearing. The first trace ran it to 38.14
  // — off-board, which seemed harmless — and the closure edge along 38.13 cut
  // straight across it. A self-intersecting contour is not a rendering error
  // anyone sees as an error: `isLand` still answered correctly, the terrain
  // grid still left a hole, and `ShapeGeometry` quietly triangulated the slit
  // shut, so the whole bay came out paved in the shore-plate colour with the
  // Bay Bridge approach running over dry land. `src/test/packs/` now asserts
  // the contour has no self-intersections, because this is exactly the class of
  // defect that passes every other check.
  [37.87, -122.48],
  [37.93, -122.45],
  [38.0, -122.47],
  [38.04, -122.48], // head of San Pablo Bay
  [38.04, -122.2],
  //
  // The bay is drawn about forty per cent wider than it is. The central bay is
  // eleven kilometres across, which at 1,919 m to the unit is under six units
  // and about twenty pixels from the state camera — narrow enough that the one
  // shape in California everybody can name from orbit arrives as a scratch. The
  // extra width is taken entirely off the East Bay flats, so San Francisco and
  // the peninsula keep every lot they had. It is the same kind of emphasis as a
  // vertical exaggeration of 13 and a two-kilometre-wide freeway: this is a
  // board, not a survey.

  // ---- Down the East Bay -------------------------------------------------
  [37.98, -122.22],
  [37.94, -122.29],
  [37.86, -122.26], // Berkeley
  [37.79, -122.22], // Oakland
  [37.7, -122.14],
  [37.6, -122.06],
  [37.51, -121.98], // Fremont
  [37.45, -121.92], // the south bay tip

  // ---- North again up the peninsula, and out through the Gate ------------
  [37.47, -122.09],
  [37.56, -122.18],
  [37.66, -122.26],
  [37.75, -122.34],
  [37.8, -122.38], // the San Francisco waterfront
  [37.81, -122.47], // the south side of the Gate

  // ---- Ocean coast again, San Francisco south ----------------------------
  [37.77, -122.51], // Ocean Beach
  [37.66, -122.5],
  [37.5, -122.5],
  [37.18, -122.4], // Año Nuevo

  // ---- Monterey Bay ------------------------------------------------------
  [37.02, -122.22],
  [36.96, -122.03], // Santa Cruz
  [36.88, -121.85],
  [36.8, -121.79], // Moss Landing, the head of the bay
  [36.7, -121.8],
  [36.62, -121.89], // Monterey
  [36.53, -121.95], // Point Lobos

  // ---- Big Sur and the Santa Lucia coast ---------------------------------
  [36.3, -121.9],
  [36.1, -121.63],
  [35.9, -121.5],
  [35.67, -121.3],
  [35.55, -121.1], // San Simeon
  [35.4, -120.9],
  [35.28, -120.87], // Morro Bay
  [35.15, -120.68], // Pismo
  [34.95, -120.65], // Point Sal
  [34.75, -120.63],
  [34.57, -120.65], // Point Arguello

  // ---- Point Conception: the corner, and the only east-west coast in the
  // state. Getting this turn right is most of what makes the silhouette south
  // of Big Sur recognisable.
  [34.45, -120.47],
  [34.42, -120.1],
  [34.4, -119.72], // Santa Barbara
  [34.32, -119.42],
  [34.25, -119.27], // Ventura
  [34.16, -119.23],
  [34.08, -119.06], // Point Mugu
  [34.04, -118.81], // Point Dume
  [34.02, -118.6],
  [34.01, -118.49], // Santa Monica
  [33.92, -118.44],
  [33.8, -118.42],
  [33.74, -118.41], // Palos Verdes, west
  [33.71, -118.32],
  [33.74, -118.25],
  [33.76, -118.19], // San Pedro and the harbour
  [33.72, -118.1], // Long Beach
  [33.66, -118.0],
  [33.6, -117.9], // Newport
  [33.46, -117.71], // Dana Point
  [33.32, -117.55],
  [33.19, -117.39], // Oceanside
  [33.07, -117.28],

  // ---- North San Diego County, and the city --------------------------------
  //
  // Everything from here down is the fix for the shape the board used to have.
  // The old trace stopped at Del Mar and closed with three ruled segments — one
  // running back north-west, one due north along -117.45 for five degrees of
  // latitude — which is the outline of a paper dart and not of California. It
  // cut San Diego off the board, put the Peninsular Ranges, the Colorado
  // Desert, the Salton basin and the eastern half of the Mojave in the sea, and
  // left the state sitting on the water as a cut-out. The silhouette is the
  // single most recognisable thing about this place and the board did not have
  // it.
  [33.0, -117.28], // Del Mar
  [32.9, -117.26],
  [32.85, -117.29], // Point La Jolla
  [32.78, -117.26],
  [32.71, -117.26],
  [32.66, -117.25], // Point Loma
  // San Diego Bay is not traced. The Golden Gate earns its excursion because it
  // is the one shape in the state anybody can name from orbit; San Diego Bay is
  // twenty kilometres long and three wide, which at 1,919 m to the unit is a
  // scratch a pixel and a half across, and the winding cost of a second inlet
  // is a self-intersection waiting to happen. The Silver Strand's outer shore
  // stands in for both sides of it.
  [32.63, -117.19],
  [32.57, -117.13], // Imperial Beach

  // ---- The Mexican border --------------------------------------------------
  //
  // One straight segment, and straight in life too — the 1848 treaty drew it as
  // a single line from a marine league south of San Diego Bay to the junction
  // of the Gila and the Colorado and it has not bent since.
  //
  // It sits two hundredths of a degree *below* `bounds.minLat`, which is closer
  // in than any other closure and deliberate: the board's own crop and the
  // state's own edge then fall on the same line, so the land covers the bottom
  // row of the lattice and no strip of sea is left along the bottom of the
  // frame pretending to be Baja. `coastFalloff` is 0.025°, so the only ground
  // this flattens is the bottom row itself.
  [32.53, -117.12],
  [32.72, -114.72], // the Colorado at Yuma

  // ---- Up the Colorado -----------------------------------------------------
  //
  // The one edge of the state that is a river rather than a ruled line, and the
  // reason the south-east corner now has something to look at. North from Yuma,
  // out east to Parker — -114.13 is the easternmost ground in California — and
  // back north-west to Needles and the tri-point.
  [32.85, -114.7],
  [33.03, -114.62],
  [33.25, -114.55],
  [33.45, -114.53],
  [33.68, -114.52],
  [33.9, -114.5],
  [34.05, -114.44],
  [34.18, -114.33],
  [34.28, -114.15], // Parker Dam
  [34.4, -114.28],
  [34.52, -114.38],
  [34.65, -114.5],
  [34.76, -114.62], // Needles
  [34.88, -114.63],
  [35.0, -114.63], // the Arizona / Nevada / California tri-point

  // ---- The Nevada line, both halves of it ---------------------------------
  //
  // The oblique first: one ruled segment from the tri-point to the corner at
  // Lake Tahoe — 39.0 N, -120.0 — at a gradient of -1.342° of longitude per
  // degree of latitude. That number is worth writing down because it is what
  // sites the two peaks in the White Mountains: the line is at -118.17 where
  // White Mountain Peak stands and the peak is nine hundredths of a degree
  // inside it, so both are placed against the line rather than against a round
  // number.
  //
  // It used to stop at 38.2, a sixth of a degree past the old crop. It now runs
  // to the corner and then turns, because the corner is the point: above 39.0
  // the boundary is the **120th meridian**, dead straight for three degrees of
  // latitude, and the right angle where the oblique meets it is the second most
  // recognisable thing about this state's outline after Point Conception. A
  // board that stopped before the corner had the diagonal and not the notch.
  [35.5, -115.3],
  [36.0, -115.97],
  [36.5, -116.64],
  [37.0, -117.31],
  [37.5, -117.98],
  [38.0, -118.65],
  [38.5, -119.32],
  [39.0, -120.0], // the corner, in Lake Tahoe

  // ---- Up the 120th meridian ----------------------------------------------
  [39.5, -120.0],
  [40.0, -120.0],
  [40.5, -120.0],
  [41.0, -120.0],
  [41.5, -120.0],
  [42.07, -120.0], // the north-east corner

  // ---- West along the Oregon line ------------------------------------------
  //
  // The 42nd parallel, ruled in life as well as here — it was drawn by treaty in
  // 1819 and has not moved since. Carried as six vertices rather than one
  // segment so that `coastalFalloff`'s edge search has something to find at a
  // sensible spacing along four hundred kilometres of straight boundary.
  [42.07, -120.8],
  [42.07, -121.6],
  [42.07, -122.4],
  [42.07, -123.2],
  [42.07, -123.8],
];

/**
 * The ranges, as chains of radial peaks.
 *
 * `World.elevationAt` sums overlapping hills as `tallest + 35% of the rest`, so
 * a chain becomes a ridge and the gap between two chains becomes a valley for
 * free. The whole of California's structure is three north-south chains — the
 * outer Coast Range, the inner Diablo Range, and the Sierra — with the Salinas
 * Valley and the Central Valley falling out as the flats between them, closed
 * at the south end by the one east-west chain, the Transverse Ranges.
 *
 * **Spacing is the number that matters, and it is about 0.9 × radius.** Work it
 * out from the falloff: two equal peaks a fraction `s` of a radius apart meet at
 * `1.35 × (1 − s²/4)²` of their own height, so `s = 0.9` puts the saddle at 85%
 * — a continuous crest with notches in it. The first version of this list was
 * spaced 1.5 to 1.8 radii and the state came out as a row of separate domes,
 * which is what a chain of `(1 − d²)²` bells looks like when they do not touch.
 * Going much below 0.9 is the opposite failure: the 35% blend from four
 * neighbours lifts the saddle *above* the summits and the range turns into a
 * plateau.
 *
 * Every radius was then checked against the two corridor routes, because a
 * freeway drapes onto whatever the heightfield says and a peak centred on the
 * road turns US-101 into a rollercoaster. The Salinas Valley, the Santa Clara
 * Valley and the whole of I-5's Central Valley run sit outside every radius.
 * The four places the routes *do* climb are the four places a driver climbs in
 * life: the Cuesta Grade above San Luis Obispo, Newhall and Tejon passes on
 * I-5's way out of Los Angeles, and Altamont on the Bay approach.
 */
const HILLS: Hill[] = [
  // ---- Outer Coast Range: Purisima to Bolinas Ridge, west of the Salinas
  // and Santa Clara valleys.
  { name: "Purisima Hills", lat: 34.75, lng: -120.3, elevation: 900, radius: 0.18 },
  { name: "Casmalia Hills", lat: 34.95, lng: -120.2, elevation: 950, radius: 0.18 },
  { name: "Irish Hills", lat: 35.15, lng: -120.35, elevation: 900, radius: 0.18 },
  { name: "Cuesta Ridge", lat: 35.35, lng: -120.65, elevation: 800, radius: 0.16 },
  { name: "Santa Lucia Range", lat: 35.55, lng: -120.95, elevation: 950, radius: 0.18 },
  { name: "Rocky Butte", lat: 35.75, lng: -121.15, elevation: 1_200, radius: 0.2 },
  { name: "Cone Peak", lat: 35.95, lng: -121.3, elevation: 1_500, radius: 0.2 },
  { name: "Junipero Serra Peak", lat: 36.15, lng: -121.42, elevation: 1_700, radius: 0.2 },
  { name: "Ventana Wilderness", lat: 36.35, lng: -121.55, elevation: 1_500, radius: 0.2 },
  { name: "Sierra de Salinas", lat: 36.55, lng: -121.72, elevation: 1_150, radius: 0.18 },
  { name: "Santa Cruz Mountains", lat: 37.05, lng: -122.03, elevation: 700, radius: 0.15 },
  { name: "Loma Prieta", lat: 37.2, lng: -122.1, elevation: 1_000, radius: 0.16 },
  { name: "Skyline Ridge", lat: 37.35, lng: -122.22, elevation: 900, radius: 0.15 },
  { name: "Montara Ridge", lat: 37.5, lng: -122.38, elevation: 700, radius: 0.13 },
  { name: "San Bruno Mountain", lat: 37.65, lng: -122.47, elevation: 400, radius: 0.1 },
  { name: "San Francisco Hills", lat: 37.755, lng: -122.45, elevation: 260, radius: 0.06 },
  { name: "Marin Headlands", lat: 37.9, lng: -122.6, elevation: 500, radius: 0.11 },
  { name: "Bolinas Ridge", lat: 38.02, lng: -122.72, elevation: 600, radius: 0.12 },

  // ---- Inner Coast Range: the Temblor and the Diablo, the wall along the
  // Central Valley's west side. It is what makes the valley a valley rather
  // than a plain that runs into the sea.
  { name: "Temblor Range", lat: 35.1, lng: -119.95, elevation: 900, radius: 0.2 },
  { name: "Carrizo Ridge", lat: 35.3, lng: -120.05, elevation: 1_000, radius: 0.2 },
  { name: "La Panza Range", lat: 35.5, lng: -120.25, elevation: 950, radius: 0.2 },
  { name: "Cholame Hills", lat: 35.7, lng: -120.45, elevation: 900, radius: 0.2 },
  { name: "Diablo Range", lat: 35.9, lng: -120.6, elevation: 1_000, radius: 0.2 },
  { name: "Priest Valley", lat: 36.1, lng: -120.7, elevation: 1_100, radius: 0.2 },
  { name: "San Benito Mountain", lat: 36.3, lng: -120.62, elevation: 1_250, radius: 0.22 },
  { name: "Panoche Hills", lat: 36.5, lng: -120.8, elevation: 1_150, radius: 0.2 },
  { name: "Pacheco Ridge", lat: 36.7, lng: -121.0, elevation: 1_100, radius: 0.2 },
  { name: "Pacheco Pass", lat: 36.9, lng: -121.15, elevation: 1_050, radius: 0.2 },
  { name: "Henry Coe", lat: 37.1, lng: -121.28, elevation: 1_150, radius: 0.2 },
  { name: "Mount Hamilton", lat: 37.34, lng: -121.62, elevation: 1_250, radius: 0.14 },
  { name: "Mount Isabel", lat: 37.32, lng: -121.4, elevation: 1_100, radius: 0.18 },
  { name: "Altamont", lat: 37.62, lng: -121.62, elevation: 600, radius: 0.14 },
  { name: "Mount Diablo", lat: 37.88, lng: -121.91, elevation: 1_150, radius: 0.13 },
  { name: "Vaca Mountains", lat: 38.04, lng: -122.06, elevation: 700, radius: 0.14 },
  { name: "Berkeley Hills", lat: 37.87, lng: -122.19, elevation: 450, radius: 0.09 },

  /**
   * ---- The northern Coast Ranges ----
   *
   * Bolinas Ridge to the Oregon line: the Mayacamas behind the Napa Valley, the
   * Mendocino Range behind Fort Bragg, the Yolla Bolly at the Klamath's shoulder
   * and — the one that matters — the King Range.
   *
   * The King Range is 1,246 m and it stands **five kilometres from the surf**,
   * which is why eighty kilometres of California shoreline has no road along it
   * and is called the Lost Coast. A 0.1 radius is what keeps it that steep here:
   * anything wider puts a shelf between the summit and the water and the whole
   * point of the landform is that there is not one. `coastFalloff` still flattens
   * the last 0.025° of it, which is about two units, and that is a beach at this
   * scale rather than a plain.
   */
  ...ridge("Sonoma Mountains", [38.25, -122.55], [38.55, -122.85], 800, 0.12),
  ...ridge("Mayacamas Mountains", [38.5, -122.6], [39.0, -122.95], 1_300, 0.14),
  { name: "Mount St Helena", lat: 38.67, lng: -122.63, elevation: 1_320, radius: 0.1 },
  ...ridge("Mendocino Range", [39.05, -123.3], [39.95, -123.55], 1_200, 0.16),
  ...ridge("Snow Mountain", [39.1, -122.75], [39.7, -122.9], 1_800, 0.15),
  ...ridge("Yolla Bolly Mountains", [39.85, -122.85], [40.45, -123.15], 2_300, 0.18),
  ...ridge("King Range", [39.98, -124.02], [40.32, -124.18], 1_250, 0.1),
  ...ridge("North Coast Front", [40.55, -123.85], [41.55, -123.85], 1_200, 0.16),
  { name: "Round Valley Rim", lat: 39.78, lng: -123.32, elevation: 900, radius: 0.12 },

  /**
   * ---- The Klamath Mountains ----
   *
   * The most confusing terrain in the state and the reason the north-west corner
   * cannot be drawn as a chain: the Klamaths do not run north-south the way
   * everything else in California does. They are a knot — the Trinity Alps, the
   * Salmons, the Marbles and the Siskiyous crossing each other at every angle —
   * and four chains laid at four different bearings is the cheapest honest way
   * to say so with the tools this pack has. A single north-south ridge here
   * would make the corner read as more Coast Range, which is exactly what it is
   * not.
   *
   * The Trinity Alps at 2,700 m are the high ground; the Siskiyous carry the
   * Oregon line itself, which is why that chain runs east-west along 41.8.
   */
  ...ridge("Trinity Alps", [40.72, -123.15], [41.15, -122.7], 2_700, 0.16),
  ...ridge("Salmon Mountains", [40.95, -123.45], [41.4, -123.05], 2_200, 0.15),
  ...ridge("Marble Mountains", [41.35, -123.4], [41.72, -123.05], 2_300, 0.14),
  ...ridge("Siskiyou Mountains", [41.8, -123.75], [41.95, -122.65], 2_000, 0.14),
  ...ridge("Scott Bar Mountains", [41.55, -122.95], [41.85, -122.65], 1_700, 0.13),
  ...ridge("South Fork Mountain", [40.2, -123.45], [40.75, -123.5], 1_700, 0.14),
  { name: "Mount Eddy", lat: 41.32, lng: -122.48, elevation: 2_750, radius: 0.12 },

  /**
   * ---- The southern Cascades ----
   *
   * **Shasta and Lassen are the two objects that make the north read as the
   * north**, and they are the only free-standing stratovolcanoes on this board.
   * Everything else in California is a range; these are cones, and a cone
   * standing alone on a plateau is a silhouette nothing else here produces.
   *
   * Shasta is 4,322 m and rises about 3,000 m from the ground around it in
   * seventeen kilometres, so the radius is 0.24 — deliberately tighter than the
   * Sierra crest's 0.30 on a peak a fifth taller again, because the whole
   * character of the mountain is that it is steep and by itself. Shastina is its
   * satellite cone on the west shoulder and costs one record; without it the
   * summit is a perfect circle, which no volcano is.
   *
   * Lassen is 3,187 m, the southern end of the Cascade arc, and the last
   * mountain in the contiguous United States to erupt before St Helens. It sits
   * a hundred kilometres south of Shasta with the Hat Creek country between
   * them, and the gap is as much the picture as the peaks are.
   */
  { name: "Mount Shasta", lat: 41.409, lng: -122.194, elevation: 4_320, radius: 0.24 },
  { name: "Shastina", lat: 41.409, lng: -122.27, elevation: 3_700, radius: 0.09 },
  { name: "Lassen Peak", lat: 40.488, lng: -121.505, elevation: 3_190, radius: 0.17 },
  { name: "Brokeoff Mountain", lat: 40.43, lng: -121.58, elevation: 2_800, radius: 0.1 },
  ...ridge("Cascade Front", [40.25, -121.62], [41.05, -121.95], 2_000, 0.18),
  ...ridge("Trinity Divide", [40.9, -122.42], [41.25, -122.4], 2_100, 0.14),
  { name: "Medicine Lake Highland", lat: 41.58, lng: -121.55, elevation: 2_350, radius: 0.24 },

  /**
   * ---- The northern Sierra, and the Warners ----
   *
   * The crest above carries the range from Piute Peak to Sonora Pass. North of
   * that it keeps going for another three degrees of latitude and it does one
   * thing the southern half never does: it **dies out**. Sonora is 3,150 m,
   * Donner is 2,600, Grizzly Ridge is 2,100, and by Lassen there is no Sierra
   * left at all — the arc hands over to the Cascades. That taper is drawn here
   * rather than stopped abruptly, because a 3,000 m wall ending in mid-air at
   * 39 N was what the old crop actually looked like.
   *
   * The Warner Mountains are the odd one out and are worth their eight records:
   * they are a Basin-and-Range block stranded in the far north-east corner, a
   * hundred kilometres east of the Cascades with nothing but plateau between,
   * and they are the only relief in the top right of the frame.
   */
  //
  // Written as chains and not as a row of peaks, and that is not a style
  // choice — it is the mistake this board has now made twice. The crest above
  // is thirteen hand-placed bells at 0.25° on a 0.28-0.30 radius, which is 0.89
  // radii apart and is a ridge. The first draft of the northern half was six
  // bells at 0.35° on a 0.24-0.26 radius: 1.4 radii apart, which is a row of
  // separate domes, and a photograph of it looked exactly like the bubble wrap
  // the desert shipped as once before. `ridge` computes the 0.9 spacing rather
  // than trusting anybody to type it.
  ...ridge("Ebbetts Crest", [38.2, -119.7], [38.72, -120.05], 3_000, 0.26),
  ...ridge("Carson Range", [38.72, -119.98], [39.15, -120.05], 3_000, 0.24),
  ...ridge("Donner Crest", [39.15, -120.2], [39.55, -120.45], 2_600, 0.22),
  ...ridge("Sierra Buttes", [39.5, -120.55], [39.95, -120.8], 2_500, 0.2),
  ...ridge("Grizzly Ridge", [39.9, -120.85], [40.35, -121.0], 2_100, 0.2),
  ...ridge("Diamond Mountains", [40.1, -120.5], [40.5, -120.35], 1_900, 0.16),
  ...ridge("Warner Mountains", [41.0, -120.2], [41.9, -120.3], 2_600, 0.13),

  // ---- Sierra Nevada: the crest ------------------------------------------
  // Thirteen peaks at ~0.25° spacing on a ~0.29° radius. This is the board's
  // one genuinely big landform and the reason the exaggeration is 13.
  { name: "Piute Peak", lat: 35.45, lng: -118.42, elevation: 2_300, radius: 0.28 },
  { name: "Greenhorn Mountains", lat: 35.7, lng: -118.35, elevation: 2_800, radius: 0.28 },
  { name: "Kern Plateau", lat: 35.95, lng: -118.3, elevation: 3_200, radius: 0.3 },
  { name: "Olancha Peak", lat: 36.2, lng: -118.28, elevation: 3_600, radius: 0.3 },
  { name: "Great Western Divide", lat: 36.45, lng: -118.28, elevation: 4_000, radius: 0.3 },
  { name: "Mount Whitney", lat: 36.62, lng: -118.29, elevation: 4_300, radius: 0.28 },
  { name: "Mount Williamson", lat: 36.85, lng: -118.38, elevation: 3_900, radius: 0.28 },
  { name: "Palisade Crest", lat: 37.05, lng: -118.52, elevation: 3_800, radius: 0.28 },
  { name: "Mount Humphreys", lat: 37.25, lng: -118.72, elevation: 3_700, radius: 0.28 },
  { name: "Mount Ritter", lat: 37.45, lng: -118.92, elevation: 3_550, radius: 0.3 },
  { name: "Mount Lyell", lat: 37.65, lng: -119.12, elevation: 3_450, radius: 0.3 },
  { name: "Yosemite High Country", lat: 37.85, lng: -119.35, elevation: 3_350, radius: 0.3 },
  { name: "Sonora Crest", lat: 38.05, lng: -119.6, elevation: 3_150, radius: 0.3 },

  // ---- Sierra Nevada: the western foothills ------------------------------
  // The long ramp out of the valley. Without it the range front rises out of
  // flat farmland inside one cell and reads as a wall dropped on a table.
  { name: "Kern Foothills", lat: 35.55, lng: -118.95, elevation: 800, radius: 0.3 },
  { name: "Tule Foothills", lat: 35.85, lng: -118.95, elevation: 900, radius: 0.3 },
  { name: "Kaweah Foothills", lat: 36.15, lng: -119.02, elevation: 1_000, radius: 0.3 },
  { name: "Sequoia Foothills", lat: 36.45, lng: -119.1, elevation: 1_100, radius: 0.3 },
  { name: "Kings Foothills", lat: 36.75, lng: -119.25, elevation: 1_050, radius: 0.3 },
  { name: "San Joaquin Foothills", lat: 37.05, lng: -119.45, elevation: 1_000, radius: 0.3 },
  { name: "Mother Lode", lat: 37.35, lng: -119.65, elevation: 1_000, radius: 0.3 },
  { name: "Tuolumne Foothills", lat: 37.65, lng: -119.9, elevation: 950, radius: 0.32 },
  { name: "Stanislaus Foothills", lat: 37.95, lng: -120.2, elevation: 900, radius: 0.32 },
  // The northern half of the ramp, as one chain rather than six bells, for the
  // spacing reason the crest above gives.
  ...ridge("Mother Lode North", [38.2, -120.35], [40.3, -121.85], 850, 0.3),

  // ---- White and Inyo Mountains, the far wall of the Owens Valley ---------
  { name: "Inyo Mountains", lat: 36.45, lng: -117.85, elevation: 2_500, radius: 0.2 },
  { name: "New York Butte", lat: 36.65, lng: -117.88, elevation: 2_700, radius: 0.2 },
  { name: "Waucoba Mountain", lat: 36.85, lng: -117.92, elevation: 2_900, radius: 0.2 },
  { name: "Westgard Pass", lat: 37.05, lng: -117.95, elevation: 3_100, radius: 0.2 },
  { name: "Piute Mountain", lat: 37.25, lng: -117.95, elevation: 3_300, radius: 0.22 },
  { name: "Cottonwood Basin", lat: 37.45, lng: -118.0, elevation: 3_600, radius: 0.22 },
  // These two are sited against the Nevada line rather than against the crest.
  // The line is at -118.17 at White Mountain Peak's latitude and at -118.43 at
  // Montgomery's, and a peak placed east of it is a peak in Nevada — outside
  // `landmasses`, so `isLand` is false under it and the summit renders as open
  // water with a mountain's skirt on the California side of it.
  { name: "White Mountain Peak", lat: 37.63, lng: -118.28, elevation: 4_000, radius: 0.22 },
  { name: "Montgomery Peak", lat: 37.84, lng: -118.5, elevation: 3_700, radius: 0.22 },

  // ---- Transverse Ranges: the east-west wall that closes the valley's south
  // end and stands behind Los Angeles.
  // The Santa Ynez sit a little north of true, and the low front behind Santa
  // Barbara is broken out separately. Both are set by the road: US-101's
  // authored path runs straight from Santa Barbara to Santa Maria, where the
  // real freeway goes round the outside at Gaviota, so a range centred on the
  // true crest put a kilometre of climb on a leg that tops out near 300 m.
  { name: "Santa Barbara Front", lat: 34.48, lng: -119.72, elevation: 700, radius: 0.1 },
  { name: "Santa Ynez Mountains", lat: 34.6, lng: -120.12, elevation: 1_000, radius: 0.16 },
  { name: "Santa Ynez Crest", lat: 34.66, lng: -119.86, elevation: 950, radius: 0.15 },
  { name: "San Rafael Mountains", lat: 34.6, lng: -119.6, elevation: 1_700, radius: 0.2 },
  { name: "Sierra Madre Ridge", lat: 34.7, lng: -119.35, elevation: 2_100, radius: 0.2 },
  { name: "Mount Pinos", lat: 34.8, lng: -119.1, elevation: 2_300, radius: 0.2 },
  // Sited west of where I-5 crosses, not on it. Mount Pinos and the Tehachapis
  // carry the high ground either side; the gap they leave between them is Tejon
  // Pass, and the blend puts the road over it at about 1,300 m against 1,258 m
  // in life. A 2,000 m peak centred on the crossing made the Grapevine a wall.
  { name: "San Emigdio Mountains", lat: 34.88, lng: -119.02, elevation: 1_900, radius: 0.2 },
  { name: "Tehachapi Mountains", lat: 35.0, lng: -118.6, elevation: 1_900, radius: 0.2 },
  { name: "Tehachapi Pass", lat: 35.08, lng: -118.35, elevation: 1_800, radius: 0.2 },
  { name: "Liebre Mountain", lat: 34.62, lng: -118.55, elevation: 1_500, radius: 0.18 },
  { name: "Sierra Pelona", lat: 34.55, lng: -118.3, elevation: 1_600, radius: 0.18 },
  { name: "Mount Gleason", lat: 34.45, lng: -118.05, elevation: 2_000, radius: 0.18 },
  { name: "Mount Wilson", lat: 34.32, lng: -117.85, elevation: 2_500, radius: 0.18 },
  { name: "Mount San Antonio", lat: 34.24, lng: -117.65, elevation: 2_900, radius: 0.18 },
  { name: "Santa Susana Mountains", lat: 34.35, lng: -118.42, elevation: 1_200, radius: 0.15 },
  // 720 m on a 0.12° radius, and both numbers are set by the road rather than by
  // the range. US-101's authored path runs straight from downtown Los Angeles
  // to Ventura, so it cuts the Santa Monicas where the real freeway goes round
  // through the Conejo Valley; at 800 m on 0.15° the heightfield put 760 m of
  // climb into a leg that tops out near 350 m in life. See the corridor test in
  // `src/test/packs/`.
  { name: "Santa Monica Mountains", lat: 34.1, lng: -118.7, elevation: 720, radius: 0.12 },
  { name: "Hollywood Hills", lat: 34.13, lng: -118.4, elevation: 500, radius: 0.12 },

  // ---- The western Mojave, and the ranges behind the LA basin -------------
  //
  // The first of the chains that use `ridge`. Everything from here to the spurs
  // is desert, and the desert was the last part of the board to be wrong: it
  // shipped once as a field of two dozen lone domes, evenly sized, each one a
  // separate `(1 - d²)²` bell standing by itself on a flat, and from the state
  // camera it read as bubble wrap. Basin and Range is not a field of hills. It
  // is a field of *ridges* — long, narrow, parallel, all leaning the same way —
  // with dry troughs between them, and a ridge is what a chain at 0.9 radii
  // gives you.
  ...ridge("Coso Range", [35.9, -117.82], [36.22, -117.7], 2_200, 0.15),
  ...ridge("Argus Range", [35.68, -117.46], [36.08, -117.38], 1_900, 0.13),
  ...ridge("Slate Range", [35.72, -117.26], [35.94, -117.2], 1_500, 0.11),
  ...ridge("El Paso Mountains", [35.3, -117.78], [35.46, -117.52], 1_400, 0.12),
  ...ridge("Rand Mountains", [35.18, -117.98], [35.4, -117.72], 1_300, 0.13),
  ...ridge("Fremont Peak", [34.84, -117.96], [35.12, -117.74], 1_200, 0.13),
  ...ridge("Shadow Mountains", [34.48, -117.64], [34.72, -117.42], 1_300, 0.13),
  ...ridge("Ord Mountains", [34.58, -116.98], [34.86, -116.76], 1_300, 0.13),
  ...ridge("Rodman Mountains", [34.62, -116.62], [34.88, -116.46], 1_400, 0.12),
  { name: "Chino Front", lat: 33.95, lng: -117.35, elevation: 1_400, radius: 0.2 },
  ...ridge("Santa Ana Mountains", [33.58, -117.34], [33.86, -117.6], 1_500, 0.14),
  ...ridge("Elsinore Ridge", [33.38, -117.08], [33.62, -117.34], 1_300, 0.14),
  ...ridge("Palomar Mountain", [33.18, -116.9], [33.42, -117.12], 1_600, 0.15),

  /**
   * ---- The Peninsular Ranges ----
   *
   * The wall behind San Diego and Palm Springs, and the reason the bottom
   * corner of the frame is a landscape rather than a beach.
   *
   * These are not low desert hills. San Gorgonio is 3,506 m and San Jacinto
   * 3,302, which makes them the second and third highest things on this board
   * after the Sierra, and San Jacinto's east face drops 3,000 m onto a valley
   * floor that is *below sea level* in under ten kilometres. That step is the
   * single most dramatic piece of ground in the state and the board had none of
   * it: the old bounds stopped at -117.55, half a degree west of the summit.
   */
  ...ridge("San Bernardino Mountains", [34.06, -116.68], [34.26, -117.08], 3_400, 0.16),
  ...ridge("San Jacinto", [33.72, -116.58], [33.9, -116.76], 3_100, 0.13),
  ...ridge("Santa Rosa Mountains", [33.4, -116.32], [33.68, -116.56], 2_300, 0.14),
  ...ridge("Anza Highlands", [33.18, -116.38], [33.44, -116.62], 1_500, 0.15),
  ...ridge("Volcan and Cuyamaca", [32.86, -116.52], [33.16, -116.62], 1_800, 0.14),
  ...ridge("Laguna Mountains", [32.66, -116.24], [32.9, -116.46], 1_700, 0.13),
  ...ridge("In-Ko-Pah Gorge", [32.6, -116.0], [32.78, -116.18], 1_200, 0.13),
  { name: "San Diego Backcountry", lat: 32.9, lng: -116.86, elevation: 800, radius: 0.2 },

  /**
   * ---- The eastern Mojave and the Colorado Desert ----
   *
   * Twenty ranges between the Sierra's rain shadow and the river, and the whole
   * of the board's south-east corner is these plus the two floors under them.
   *
   * They lean north-north-west because that is the way the Eastern California
   * Shear Zone leans, and keeping every one of them within about twenty degrees
   * of the same bearing is most of what makes the corner read as a *region*
   * rather than as scattered lumps. It is the same argument the Coast Ranges
   * make one chain at a time, applied to an area four times the size.
   *
   * None of this is wildland and none of it is farmed, so `parks` cannot touch
   * it and `flats` never gets near it: every one of these is drawn in the two
   * stops above `upland`, which is why the pack declares `alpine` at all. What
   * carries them is the second thing — the terrain now casts its own shadow, so
   * a ridge in an unpainted desert throws a shadow east in the morning and west
   * in the evening, and the corner of the board that used to be blank is the
   * part of the frame that changes most across a day.
   */
  ...ridge("Providence Mountains", [34.72, -115.78], [35.08, -115.46], 2_000, 0.14),
  ...ridge("New York Mountains", [35.08, -115.44], [35.38, -115.2], 2_100, 0.13),
  ...ridge("Clark Mountain", [35.38, -115.72], [35.62, -115.5], 2_300, 0.13),
  ...ridge("Kingston Range", [35.58, -116.02], [35.86, -115.8], 2_100, 0.14),
  ...ridge("Avawatz Mountains", [35.46, -116.52], [35.72, -116.34], 1_800, 0.13),
  ...ridge("Soda Mountains", [35.04, -116.36], [35.3, -116.18], 1_000, 0.12),
  ...ridge("Cady Mountains", [34.68, -116.44], [34.98, -116.16], 1_300, 0.13),
  ...ridge("Piute Range", [34.86, -115.08], [35.2, -114.92], 1_300, 0.12),
  ...ridge("Sacramento Mountains", [34.56, -114.98], [34.9, -114.84], 1_100, 0.11),
  ...ridge("Old Woman Mountains", [34.3, -115.38], [34.68, -115.12], 1_700, 0.13),
  ...ridge("Turtle Mountains", [34.12, -115.06], [34.42, -114.86], 1_300, 0.12),
  ...ridge("Whipple Mountains", [34.18, -114.68], [34.42, -114.5], 1_200, 0.11),
  ...ridge("Big Maria Mountains", [33.76, -114.66], [34.02, -114.5], 900, 0.11),
  ...ridge("Bullion Mountains", [34.26, -116.34], [34.66, -116.08], 1_200, 0.13),
  ...ridge("Sheep Hole Mountains", [33.98, -115.8], [34.32, -115.64], 1_100, 0.12),
  ...ridge("Little San Bernardino", [33.82, -116.38], [34.16, -115.92], 1_600, 0.14),
  ...ridge("Coxcomb Mountains", [33.82, -115.48], [34.14, -115.32], 1_200, 0.12),
  ...ridge("Eagle Mountains", [33.66, -115.7], [33.94, -115.46], 1_600, 0.13),
  ...ridge("Palen Mountains", [33.68, -115.2], [34.0, -115.04], 1_100, 0.12),
  ...ridge("Mule Mountains", [33.44, -114.9], [33.7, -114.72], 700, 0.11),
  ...ridge("Orocopia Mountains", [33.42, -115.94], [33.66, -115.72], 900, 0.12),
  ...ridge("Chuckwalla Mountains", [33.38, -115.58], [33.68, -115.14], 900, 0.13),
  ...ridge("Chocolate Mountains", [32.94, -114.92], [33.4, -115.44], 800, 0.15),
  ...ridge("Cargo Muchacho", [32.76, -114.96], [32.94, -114.8], 600, 0.11),

  /**
   * ---- Death Valley ----
   *
   * Five ranges and, deliberately, no floor between them.
   *
   * `elevationAt` returns exactly 0 where no hill reaches and `groundColor`
   * paints anything under 3 m with `palette.sand`. Everywhere else on the board
   * that is a defect — the note on "the floors" below is about four hundred
   * kilometres of farmland that was being painted as beach — and here it is the
   * right answer twice over: the floor really is below sea level, and it really
   * is a white salt pan. So Badwater gets the beach colour on purpose, with the
   * highest ground for a hundred kilometres on both sides of it and `alpine`
   * grey on top of that, which is the widest range of value the board reaches
   * anywhere outside the Sierra.
   *
   * The Black Mountains are the constraint. They run down the *east* side of the
   * valley and their radius is the only thing keeping the pan at zero: at 0.18
   * the chain reached across the floor and lifted Badwater to 52 m, which is
   * `flats` gold and turns the most recognisable salt flat in North America into
   * a wheat field.
   */
  ...ridge("Panamint Range", [35.92, -117.22], [36.56, -117.24], 3_000, 0.15),
  ...ridge("Cottonwood Mountains", [36.58, -117.3], [37.04, -117.5], 2_200, 0.14),
  ...ridge("Last Chance Range", [36.94, -117.62], [37.26, -117.78], 2_300, 0.13),
  ...ridge("Grapevine Mountains", [36.66, -117.16], [37.0, -117.32], 2_300, 0.12),
  ...ridge("Funeral Mountains", [36.34, -116.98], [36.6, -116.88], 1_700, 0.12),
  ...ridge("Black Mountains", [35.92, -116.78], [36.32, -116.62], 1_600, 0.11),
  ...ridge("Owlshead Mountains", [35.62, -117.06], [35.9, -116.88], 1_200, 0.13),

  /**
   * ---- Spurs ----
   *
   * Short, low, irregularly placed peaks hanging off the main chains.
   *
   * A chain on its own gives a ridge with an even scallop along it, because the
   * chain is evenly spaced and every bell is the same width — from the state
   * camera the Coast Ranges came out looking like a caterpillar. Real range
   * fronts are ridges *and* the spurs and side canyons running down off them,
   * and it is the spurs that break the period. They are placed off-rhythm on
   * purpose: no two are the same distance apart, and none of them lines up with
   * a peak on the chain it hangs off.
   */
  { name: "Cuyama Spur", lat: 34.88, lng: -119.98, elevation: 640, radius: 0.11 },
  { name: "Huasna Spur", lat: 35.07, lng: -120.44, elevation: 520, radius: 0.09 },
  { name: "Santa Margarita Spur", lat: 35.44, lng: -120.5, elevation: 600, radius: 0.1 },
  { name: "Adelaida Spur", lat: 35.69, lng: -120.86, elevation: 680, radius: 0.1 },
  { name: "Nacimiento Spur", lat: 35.88, lng: -121.06, elevation: 820, radius: 0.11 },
  { name: "Arroyo Seco Spur", lat: 36.24, lng: -121.28, elevation: 940, radius: 0.1 },
  { name: "Carmel Spur", lat: 36.44, lng: -121.72, elevation: 780, radius: 0.09 },
  { name: "Corralitos Spur", lat: 37.08, lng: -121.88, elevation: 520, radius: 0.09 },
  { name: "Woodside Spur", lat: 37.42, lng: -122.24, elevation: 560, radius: 0.08 },
  { name: "Panoche Spur", lat: 36.41, lng: -120.98, elevation: 780, radius: 0.11 },
  { name: "Los Banos Spur", lat: 36.98, lng: -120.9, elevation: 640, radius: 0.1 },
  { name: "Orestimba Spur", lat: 37.28, lng: -121.18, elevation: 700, radius: 0.1 },
  { name: "Del Puerto Spur", lat: 37.52, lng: -121.42, elevation: 620, radius: 0.09 },
  { name: "Kaweah Spur", lat: 36.28, lng: -118.72, elevation: 1_900, radius: 0.14 },
  { name: "Kings Canyon Spur", lat: 36.88, lng: -118.9, elevation: 2_200, radius: 0.15 },
  { name: "Mariposa Spur", lat: 37.52, lng: -119.5, elevation: 1_800, radius: 0.14 },
  { name: "Merced Spur", lat: 37.72, lng: -119.72, elevation: 1_500, radius: 0.13 },
  { name: "Isabella Spur", lat: 35.66, lng: -118.62, elevation: 1_500, radius: 0.13 },
  { name: "Frazier Spur", lat: 34.72, lng: -118.92, elevation: 1_600, radius: 0.11 },
  { name: "Castaic Spur", lat: 34.5, lng: -118.68, elevation: 1_100, radius: 0.1 },
  { name: "Cajon Spur", lat: 34.22, lng: -117.5, elevation: 2_000, radius: 0.12 },
  { name: "Trabuco Spur", lat: 33.62, lng: -117.62, elevation: 1_000, radius: 0.1 },

  /**
   * ---- The floors ----
   *
   * Broad, almost flat rises with no summit worth the name, and they fix the
   * single most damaging thing about the old board.
   *
   * `terrain.ts` paints anything under 3 m with `palette.sand` — the beach
   * colour — and `elevationAt` returns exactly 0 everywhere no hill reaches.
   * So the Central Valley, the Mojave, the LA basin and the Salinas Valley,
   * which between them are most of the land in frame, were all being painted as
   * beach. That is where "a pale sand lozenge" came from: it was not a palette
   * that needed darkening, it was four hundred kilometres of farmland sitting
   * at sea level.
   *
   * These lift each floor onto `palette.flats` and give it a barely-perceptible
   * grade. The summits are deliberately *low* — 28 m for the Central Valley,
   * not the 90 m it was first given — because `groundColor` starts blending
   * `flats` toward `upland` immediately above 3 m and reaches it at 150. At 90
   * the valley came out 58% of the way to bare stone and the board was still
   * pale; at 28 it is farmland with a hint of dust on it, which is the whole
   * job. The two deserts are the exception and are meant to be up there: the
   * Mojave really does sit at 600 m and really is the colour of `upland`.
   */
  { name: "Central Valley floor", lat: 36.6, lng: -120.0, elevation: 28, radius: 1.7 },
  { name: "Mojave floor", lat: 34.9, lng: -117.8, elevation: 620, radius: 1.1 },
  { name: "Owens Valley floor", lat: 36.9, lng: -118.1, elevation: 380, radius: 0.8 },
  { name: "Salinas Valley floor", lat: 36.3, lng: -121.2, elevation: 26, radius: 0.5 },
  { name: "Santa Clara Valley floor", lat: 37.3, lng: -121.85, elevation: 22, radius: 0.24 },
  { name: "Los Angeles basin floor", lat: 34.0, lng: -118.15, elevation: 26, radius: 0.42 },
  { name: "Oxnard Plain", lat: 34.22, lng: -119.12, elevation: 18, radius: 0.22 },
  { name: "Antelope Valley floor", lat: 34.75, lng: -118.2, elevation: 700, radius: 0.42 },

  /*
   * The northern floors, and the one that carries a third of the new board.
   *
   * **The Sacramento Valley is the same object as the San Joaquin and has to
   * overlap it**, for the reason the dry floors below give at length: a radial
   * bell falls to zero with zero gradient at its own edge, two floors that
   * merely touch leave a seam at exactly 0 m between them, and 0 m is the beach
   * colour. A pale sand stripe drawn across the middle of the Central Valley at
   * the latitude of Stockton is the exact failure this avoids. The San Joaquin
   * floor is centred at 36.6 on a radius of 1.7, so it reaches 38.3; this one
   * is centred at 39.4 on 1.3 and reaches 38.1, which puts two tenths of a
   * degree of overlap under the join.
   *
   * The plateau floors are the opposite case and are meant to be high. The
   * Modoc Plateau really does sit at 1,400 m, the Klamath Basin at 1,260 and
   * Surprise Valley at 1,500, so they come out as `upland` rock rather than as
   * `flats` gold — which is right: the top right of this board is high desert,
   * not farmland, and it is the same country as the Great Basin over the line.
   */
  // A chain along the valley's own axis rather than one bell, because the
  // Sacramento Valley is 250 km long and 80 km wide and a single radial bell
  // that covers its length is a 290 km circle — which is what the first draft
  // drew, and it came out as a smooth gold bowl swallowing the Coast Ranges on
  // one side and the Sierra foothills on the other. The San Joaquin gets away
  // with one bell because it really is nearly as wide as it is long.
  ...ridge("Sacramento Valley floor", [38.5, -121.6], [40.35, -122.2], 34, 0.62),
  // 631 m of andesite standing alone in the middle of a dead-flat valley — the
  // smallest mountain range in the world by the sign at the county line, and
  // one of the very few things on this board that is legible *because* nothing
  // else is near it. A 0.08 radius is nine kilometres, which is what it is.
  { name: "Sutter Buttes", lat: 39.21, lng: -121.82, elevation: 631, radius: 0.08 },
  // One wide bell and not a chain, which is the opposite call from the
  // Sacramento Valley two lines up and is the same reasoning applied to a
  // different shape. The Modoc is a *plateau*: 20,000 km² of basalt at a fairly
  // even 1,400 m, as round as it is long. Drawn as a chain of 0.42 bells it came
  // out as three separate domes in a photograph — the bubble-wrap failure again,
  // and this time in a place that has no ranges in it at all. The Mojave floor
  // takes the same treatment at 1.1 for the same reason.
  { name: "Modoc Plateau floor", lat: 41.32, lng: -120.95, elevation: 1_400, radius: 0.78 },
  { name: "Surprise Valley floor", lat: 41.4, lng: -120.06, elevation: 1_500, radius: 0.16 },
  { name: "Honey Lake floor", lat: 40.3, lng: -120.4, elevation: 1_220, radius: 0.42 },
  { name: "Shasta Valley floor", lat: 41.65, lng: -122.5, elevation: 800, radius: 0.24 },
  { name: "Scott Valley floor", lat: 41.5, lng: -122.9, elevation: 850, radius: 0.14 },

  /*
   * The dry floors, east of the Transverse Ranges.
   *
   * Same job as the four above and one extra constraint: they have to *overlap*.
   * A radial bell falls to zero with zero gradient at its own edge, so two
   * floors that merely touch leave a seam at exactly 0 m between them — and 0 m
   * is the beach colour, so the seam arrives as a pale sand stripe drawn across
   * the middle of a desert. The Mojave floor reaches -116.7 and the eastern one
   * starts from -115.9 on a radius of 1.0, which puts two tenths of a degree of
   * overlap under the join and about 200 m of ground in it.
   *
   * The two irrigated valleys are the exception and are meant to be low: the
   * Imperial and the Coachella are farmed, they are `flats` gold rather than
   * `upland` rock, and that is the honest reason the bottom corner of the board
   * has a colour in it that the desert around it does not.
   */
  { name: "Eastern Mojave floor", lat: 35.0, lng: -115.9, elevation: 780, radius: 1.0 },
  { name: "Ward Valley floor", lat: 34.4, lng: -115.0, elevation: 450, radius: 0.55 },
  { name: "Chuckwalla Valley floor", lat: 33.6, lng: -115.2, elevation: 250, radius: 0.4 },
  { name: "Lower Colorado floor", lat: 33.4, lng: -114.7, elevation: 120, radius: 0.5 },
  // Sited on Palm Springs and pulled back off the lake, which is a rendering
  // constraint and not a geographic one. `isLand` is false inside
  // `inlandWater`, so the terrain grid has a hole there — quantised to the
  // lattice, and therefore stair-stepped — while the lake plate is a smooth
  // polygon at y=0.05. Any ground the floor lifts along the shore stands *over*
  // the water as a blocky rim, which arrives as a row of pale steps across the
  // north end of the sea. The real Coachella Valley runs below sea level as it
  // approaches the shore anyway, so a floor that dies out before it gets there
  // is the honest shape as well as the one that renders.
  { name: "Coachella Valley floor", lat: 33.82, lng: -116.32, elevation: 60, radius: 0.28 },
  { name: "Imperial Valley floor", lat: 32.8, lng: -115.5, elevation: 14, radius: 0.38 },
  { name: "Anza-Borrego floor", lat: 33.1, lng: -116.15, elevation: 220, radius: 0.28 },
  { name: "Amargosa Desert floor", lat: 36.3, lng: -116.35, elevation: 700, radius: 0.3 },
  { name: "Panamint Valley floor", lat: 36.0, lng: -117.35, elevation: 400, radius: 0.22 },
  { name: "San Diego mesa", lat: 32.88, lng: -117.13, elevation: 110, radius: 0.2 },
];

/**
 * Wildland, which on this board is what draws the mountains.
 *
 * See the header: ground colour saturates at 150 m, so `parks` is the only
 * channel left that can distinguish a range from a farm. Each polygon is a
 * range *envelope* traced to sit over the hill chain it belongs to — the first
 * version was drawn independently of the hills and produced green stripes lying
 * across gold domes, which looks exactly as wrong as it sounds.
 *
 * Two envelopes stop deliberately short.
 *
 * The Sierra one has its eastern edge about half a degree west of the crest, so
 * the granite above the tree line is left painted as rock. Its western edge sits
 * a little *up* the range front rather than at the base, because the Sierra
 * foothills really are gold grassland and the conifers really do start around
 * 600 m. Those two edges are the closest this two-colour ramp can get to a snow
 * line and a tree line.
 *
 * The Coast Range one stops at 37.6 N. North of that the peninsula is
 * continuously built and `createBlocks` skips every lot inside a park — an
 * envelope drawn to the Golden Gate deletes San Francisco.
 */
const RANGES: LatLng[][] = [
  // Outer Coast Range: Point Conception to the Santa Cruz Mountains.
  [
    [34.6, -120.315],
    [34.85, -120.115],
    [35.15, -120.165],
    [35.4, -120.445],
    [35.65, -120.745],
    [35.9, -120.945],
    [36.15, -121.115],
    [36.4, -121.265],
    [36.6, -121.465],
    [36.78, -121.645],
    [36.98, -121.815],
    [37.15, -121.885],
    [37.32, -122.045],
    [37.45, -122.185],
    [37.55, -122.38],
    [37.6, -122.55],
    [37.45, -122.48],
    [37.25, -122.38],
    [37.02, -122.23],
    [36.85, -122.03],
    [36.55, -121.98],
    [36.3, -121.88],
    [36.05, -121.63],
    [35.8, -121.38],
    [35.55, -121.13],
    [35.3, -120.91],
    [35.05, -120.71],
    [34.8, -120.65],
  ],
  // Marin: the Headlands and Bolinas Ridge, north of the Gate.
  [
    [38.05, -122.53],
    [37.95, -122.4],
    [37.86, -122.46],
    [37.85, -122.66],
    [37.95, -122.82],
    [38.05, -122.9],
  ],
  /*
   * The North Coast forest, Sonoma to the Oregon line.
   *
   * The largest single wildland envelope on the board and the one that changes
   * the frame most, because the ground it covers used to be ocean. North of the
   * Bay this coast is continuous forest for four hundred kilometres — redwood on
   * the seaward slope, Douglas fir behind it — and it is genuinely darker and
   * greener than anything else in California. Get it wrong and the top left of
   * the board is gold grassland running to the Oregon line, which is a picture
   * of a state four hundred kilometres inland from this one.
   *
   * Its western edge follows the coast at about a tenth of a degree inland
   * rather than sitting on it, so `coastFalloff`'s flattened rim stays outside
   * the park and the shore reads as a shore. Its eastern edge is the inner Coast
   * Range crest, which is where the fog stops reaching and the country turns to
   * oak and grass — a real line, and the one the eye reads as the edge of the
   * north coast.
   */
  [
    [38.3, -122.95],
    [38.7, -123.15],
    [39.1, -123.35],
    [39.5, -123.4],
    [39.9, -123.5],
    [40.3, -123.6],
    [40.7, -123.7],
    [41.1, -123.75],
    [41.5, -123.85],
    [41.9, -123.9],
    [41.95, -124.15],
    [41.5, -124.1],
    [41.0, -124.05],
    [40.6, -124.2],
    [40.3, -124.3],
    [40.0, -124.05],
    [39.6, -123.72],
    [39.2, -123.66],
    [38.8, -123.42],
    [38.4, -123.1],
  ],
  /*
   * The Klamath and the Trinity Alps: the interior knot.
   *
   * Drawn separately from the coast belt above rather than merged with it,
   * because the ground between them is the Trinity River country and is not the
   * same landscape — and because one envelope covering both would swallow the
   * Shasta and Scott valleys, which are farmed, pale and the only two flat
   * things in the north-west corner. Two greens with a gold gap in them is the
   * shape of that corner.
   */
  [
    [40.2, -123.4],
    [40.6, -123.3],
    [41.0, -123.1],
    [41.4, -123.0],
    [41.8, -122.9],
    [41.95, -123.2],
    [41.6, -123.5],
    [41.2, -123.6],
    [40.8, -123.5],
    [40.4, -123.55],
  ],
  /*
   * The Cascade belt: Shasta, Lassen, and the conifer between them.
   *
   * The envelope stops short of Shasta's summit cone on purpose, the same way
   * the Sierra one stops half a degree west of the crest. Above about 2,700 m
   * the mountain is scree, glacier and old snow, and leaving it out of the park
   * is the only way this two-colour ramp can draw a tree line — the cone comes
   * out `alpine` grey standing on a green skirt, which is what it looks like
   * from a hundred kilometres away on any clear day in the valley.
   */
  [
    [40.2, -121.9],
    [40.6, -121.75],
    [41.0, -121.85],
    [41.18, -121.95],
    [41.2, -122.3],
    [41.05, -122.45],
    [40.6, -122.25],
    [40.25, -122.2],
  ],
  /*
   * The Shasta-Trinity forest north and west of the mountain — and the gap
   * between this polygon and the one above it is the point of both.
   *
   * `groundColor` answers `inPark` **first**, so a park polygon paints its
   * ground green at any altitude and the `alpine` stop is unreachable inside
   * one. That is correct almost everywhere and catastrophic on a stratovolcano:
   * the first draft ran one envelope over the whole Cascade belt and Mount
   * Shasta rendered as a 4,320 m cone of pine, which is the single most
   * recognisable landform in northern California drawn wrong.
   *
   * So the two belts stop either side of 41.2–41.55 and the mountain sits in the
   * gap, painted by the height ramp as the rock and old snow it is. The gap is
   * also honest on its own terms: the Shasta Valley immediately west of the cone
   * is open grassland at 800 m with no trees on it at all, which is why the
   * mountain reads as free-standing from the interstate.
   */
  [
    [41.55, -122.05],
    [41.9, -122.15],
    [41.95, -122.55],
    [41.6, -122.7],
    [41.35, -122.6],
    [41.4, -122.25],
  ],
  /*
   * The northern Sierra forest belt, carrying the range on from Sonora Pass.
   *
   * Same two edges as its southern half and for the same two reasons: the
   * western one sits a little up the range front because the foothills really
   * are gold grassland and the conifers really do start around 600 m, and the
   * eastern one stops short of the crest so the granite above the tree line is
   * left as rock. It narrows as it goes north because the range does.
   */
  [
    [38.05, -119.84],
    [38.35, -120.0],
    [38.7, -120.25],
    [39.05, -120.5],
    [39.4, -120.75],
    [39.75, -121.0],
    [40.05, -121.25],
    [40.2, -121.5],
    [39.9, -121.4],
    [39.55, -121.25],
    [39.2, -121.05],
    [38.85, -120.8],
    [38.5, -120.55],
    [38.15, -120.35],
  ],
  // Inner Coast Range: the Temblor and the Diablo.
  [
    [35.05, -119.715],
    [35.35, -119.815],
    [35.65, -120.165],
    [35.95, -120.365],
    [36.25, -120.385],
    [36.55, -120.565],
    [36.85, -120.765],
    [37.15, -121.015],
    [37.45, -121.315],
    [37.7, -121.465],
    [37.95, -121.715],
    [38.05, -121.865],
    [38.05, -122.165],
    [37.9, -122.21],
    [37.75, -122.05],
    [37.55, -121.88],
    [37.35, -121.83],
    [37.15, -121.58],
    [36.9, -121.38],
    [36.65, -121.18],
    [36.4, -120.93],
    [36.15, -120.88],
    [35.85, -120.75],
    [35.55, -120.48],
    [35.25, -120.18],
    [35.05, -119.98],
  ],
  // Sierra Nevada forest belt: between the gold foothills and the bare crest.
  [
    [35.45, -118.6],
    [35.75, -118.55],
    [36.05, -118.52],
    [36.35, -118.52],
    [36.6, -118.54],
    [36.85, -118.64],
    [37.1, -118.8],
    [37.35, -119.0],
    [37.6, -119.25],
    [37.85, -119.5],
    [38.05, -119.84],
    [38.05, -120.44],
    [37.8, -120.24],
    [37.5, -119.96],
    [37.2, -119.74],
    [36.9, -119.54],
    [36.6, -119.36],
    [36.3, -119.29],
    [36.0, -119.24],
    [35.7, -119.19],
    [35.45, -119.09],
  ],
  // Transverse Ranges: Santa Ynez through the San Gabriels.
  [
    [34.72, -120.25],
    [34.85, -119.75],
    [35.02, -119.25],
    [35.18, -118.75],
    [35.22, -118.3],
    [35.0, -118.18],
    [34.75, -118.02],
    [34.5, -117.82],
    [34.35, -117.55],
    [34.22, -117.65],
    [34.25, -118.02],
    [34.35, -118.3],
    [34.44, -118.75],
    [34.48, -119.2],
    [34.48, -119.75],
    [34.5, -120.2],
  ],
  // The Santa Monica Mountains, which separate the Westside from the Valley.
  [
    [34.18, -118.765],
    [34.16, -118.405],
    [34.09, -118.455],
    [34.09, -118.815],
  ],
  // Santa Ana Mountains and the Palomar front, closing the south-east.
  [
    [34.05, -117.525],
    [33.85, -117.175],
    [33.45, -116.825],
    [33.15, -116.875],
    [33.2, -117.225],
    [33.55, -117.475],
    [33.85, -117.725],
  ],
  /*
   * San Bernardino and San Jacinto: the conifer belt on the two 3,000 m peaks
   * that stand over Palm Springs.
   *
   * Its eastern edge is the pass and it stops there, hard. That edge is the
   * point of the polygon: on one side of it is 3,400 m of pine and on the other
   * is the Coachella Valley at 30 m, and the board has exactly one channel that
   * can show the difference — `groundColor` saturates at 150 m, so without this
   * envelope the two would be painted the same value and the biggest step of
   * relief in the state would read as a smudge.
   */
  [
    [34.32, -117.15],
    [34.32, -116.72],
    [34.0, -116.62],
    [33.72, -116.58],
    [33.62, -116.78],
    [33.9, -116.92],
    [34.05, -117.08],
  ],
  /*
   * The Lagunas and the Cuyamacas, behind San Diego. Chaparral and pine on the
   * Pacific side of the divide; the eastern edge is where the ground falls into
   * Anza-Borrego and stops being wildland of any kind.
   */
  [
    [33.25, -116.78],
    [33.2, -116.38],
    [32.85, -116.25],
    [32.62, -116.28],
    [32.62, -116.62],
    [32.9, -116.78],
  ],
];

/**
 * The Salton Sea, and it is the only inland water this board draws.
 *
 * A hundred kilometres of open water in the middle of a desert, and by some
 * distance the most legible single object in the south-east of the frame: the
 * two dry valleys either side of it are `flats` gold and `upland` rock, both
 * warm, and the lake is the one cool value for two hundred kilometres in any
 * direction. It is also the reason the basin around it reads as a basin.
 *
 * Drawn as `inlandWater` rather than as a concavity in the landmass, which is
 * the opposite of the call made for San Francisco Bay twelve hundred lines up
 * and for the opposite reason: the bay is tidal salt water joined to the
 * Pacific through the Gate, and this is a closed sump with no outlet at all.
 * It costs one draw call and it cannot self-intersect the coastline.
 */
const SALTON_SEA: LatLng[][] = [
  [
    [33.545, -116.09], // the north-west shore, below Mecca
    [33.436, -116.096],
    [33.361, -116.054],
    [33.295, -116.001],
    [33.234, -115.94],
    [33.177, -115.873],
    [33.126, -115.799],
    [33.083, -115.714],
    [33.075, -115.58], // the south-east shore, above Calipatria
    [33.184, -115.574],
    [33.259, -115.616],
    [33.325, -115.669],
    [33.386, -115.73],
    [33.443, -115.797],
    [33.494, -115.871],
    [33.537, -115.956],
  ],
];

/**
 * The built state, as conurbations.
 *
 * Every polygon here is an urban *footprint* — the extent of continuous
 * settlement — because at 806 m to the lot that is the smallest thing this
 * board can draw with more than a handful of instances in it. Two exceptions
 * carry a `downtown` palette and a real tower chance: the San Francisco
 * peninsula tip and the LA basin core. They are only about 140 and 900 lots,
 * but they are the two the eye is sent to by the chapter list, and a pale
 * cluster with a few dark towers in it is what makes a patch of speckle read as
 * a city centre rather than as a gravel bar.
 *
 * The count is the constraint. Every lot is ten triangles in the one instanced
 * `blocks` mesh — ten rather than twelve because at this scale `blocks.ts` drops
 * the face nobody can get under — and the California board is the tight one:
 * 650 draw calls and 750k triangles, shared with the aircraft layer. About
 * eight and a half thousand lots is what the corridor's reclaimed headroom
 * pays for, which is why the Inland Empire, Sacramento and San Diego are absent
 * rather than thin. They are all mostly outside `bounds` anyway, and a
 * half-drawn city is worse than an honest edge.
 */
const DISTRICTS: District[] = [
  // ---- The Los Angeles basin ---------------------------------------------
  {
    id: "la-core",
    name: "Los Angeles",
    polygon: [
      [34.12, -118.52],
      [34.12, -118.15],
      [33.98, -118.05],
      [33.86, -118.14],
      [33.78, -118.3],
      [33.86, -118.45],
      [34.02, -118.55],
    ],
    gridAngle: 0.63,
    minHeight: 30,
    maxHeight: 260,
    towerChance: 0.035,
    palette: "downtown",
    coverage: 0.82,
  },
  {
    id: "san-fernando-valley",
    name: "San Fernando Valley",
    polygon: [
      [34.32, -118.62],
      [34.32, -118.28],
      [34.15, -118.28],
      [34.15, -118.62],
    ],
    gridAngle: 0.0,
    minHeight: 16,
    maxHeight: 52,
    towerChance: 0.004,
    palette: "residential",
    coverage: 0.7,
  },
  {
    id: "san-gabriel-valley",
    name: "San Gabriel Valley",
    polygon: [
      [34.16, -118.2],
      [34.16, -117.72],
      [33.98, -117.68],
      [33.96, -118.08],
    ],
    gridAngle: 0.06,
    minHeight: 16,
    maxHeight: 60,
    towerChance: 0.005,
    palette: "residential",
    coverage: 0.68,
  },
  {
    id: "la-harbour",
    name: "San Pedro & Long Beach",
    polygon: [
      [33.86, -118.28],
      [33.86, -118.09],
      [33.73, -118.09],
      [33.73, -118.28],
    ],
    gridAngle: 0.1,
    minHeight: 12,
    maxHeight: 46,
    towerChance: 0.006,
    palette: "industrial",
    coverage: 0.66,
  },
  {
    id: "orange-county",
    name: "Orange County",
    polygon: [
      [33.9, -118.1],
      [33.9, -117.72],
      [33.62, -117.62],
      [33.5, -117.78],
      [33.66, -118.05],
    ],
    gridAngle: 0.55,
    minHeight: 14,
    maxHeight: 54,
    towerChance: 0.005,
    palette: "residential",
    coverage: 0.68,
  },

  // ---- The Bay Area -------------------------------------------------------
  {
    id: "san-francisco",
    name: "San Francisco",
    polygon: [
      [37.81, -122.51],
      [37.81, -122.37],
      [37.7, -122.37],
      [37.7, -122.51],
    ],
    gridAngle: 0.46,
    minHeight: 34,
    maxHeight: 250,
    towerChance: 0.06,
    palette: "downtown",
    coverage: 0.9,
  },
  {
    id: "peninsula",
    name: "The Peninsula",
    polygon: [
      [37.7, -122.5],
      [37.7, -122.34],
      [37.45, -122.1],
      [37.36, -122.1],
      [37.4, -122.32],
      [37.55, -122.45],
    ],
    gridAngle: 0.55,
    minHeight: 14,
    maxHeight: 60,
    towerChance: 0.005,
    palette: "residential",
    coverage: 0.66,
  },
  {
    id: "santa-clara-valley",
    name: "San Jose & Santa Clara",
    polygon: [
      [37.47, -122.03],
      [37.44, -121.86],
      [37.24, -121.72],
      [37.18, -121.88],
      [37.32, -122.05],
    ],
    gridAngle: 0.62,
    minHeight: 15,
    maxHeight: 90,
    towerChance: 0.008,
    palette: "residential",
    coverage: 0.7,
  },
  {
    id: "east-bay",
    name: "Oakland & the East Bay",
    polygon: [
      [38.0, -122.21],
      [37.98, -122.02],
      [37.72, -121.86],
      [37.5, -121.88],
      [37.55, -122.0],
      [37.78, -122.22],
    ],
    gridAngle: 0.42,
    minHeight: 15,
    maxHeight: 90,
    towerChance: 0.007,
    palette: "residential",
    coverage: 0.6,
  },

  // ---- The Central Valley -------------------------------------------------
  {
    id: "stockton",
    name: "Stockton",
    polygon: [
      [38.03, -121.38],
      [38.03, -121.2],
      [37.9, -121.18],
      [37.9, -121.38],
    ],
    gridAngle: 0.35,
    minHeight: 12,
    maxHeight: 48,
    towerChance: 0.004,
    palette: "residential",
    coverage: 0.66,
  },
  {
    id: "modesto",
    name: "Modesto & Turlock",
    polygon: [
      [37.72, -121.08],
      [37.72, -120.88],
      [37.45, -120.82],
      [37.45, -121.0],
    ],
    gridAngle: 0.3,
    minHeight: 11,
    maxHeight: 40,
    towerChance: 0.003,
    palette: "residential",
    coverage: 0.46,
  },
  {
    id: "fresno",
    name: "Fresno",
    polygon: [
      [36.88, -119.92],
      [36.88, -119.66],
      [36.66, -119.62],
      [36.66, -119.88],
    ],
    gridAngle: 0.28,
    minHeight: 12,
    maxHeight: 60,
    towerChance: 0.005,
    palette: "residential",
    coverage: 0.64,
  },
  {
    id: "bakersfield",
    name: "Bakersfield",
    polygon: [
      [35.46, -119.14],
      [35.46, -118.88],
      [35.26, -118.86],
      [35.26, -119.12],
    ],
    gridAngle: 0.0,
    minHeight: 11,
    maxHeight: 46,
    towerChance: 0.004,
    palette: "residential",
    coverage: 0.62,
  },
  {
    id: "salinas",
    name: "Salinas",
    polygon: [
      [36.86, -121.6],
      [36.86, -121.44],
      [36.6, -121.4],
      [36.6, -121.56],
    ],
    gridAngle: 0.72,
    minHeight: 10,
    maxHeight: 34,
    towerChance: 0.002,
    palette: "residential",
    coverage: 0.56,
  },

  // ---- The south coast ----------------------------------------------------
  {
    id: "santa-barbara",
    name: "Santa Barbara",
    polygon: [
      [34.46, -119.78],
      [34.46, -119.6],
      [34.38, -119.58],
      [34.38, -119.78],
    ],
    gridAngle: 1.05,
    minHeight: 10,
    maxHeight: 32,
    towerChance: 0.002,
    palette: "residential",
    coverage: 0.56,
  },
  /**
   * The one district south of the old bounds, and the reason the new coast is
   * not two hundred kilometres of empty sand.
   *
   * Held to a compact core rather than to the real urban extent, which runs
   * from the border to Oceanside and would be about twelve hundred lots. The
   * board's triangle budget is spoken for — see the note on `DISTRICTS` — and a
   * dense small city and a thin large one cost the same to look at, so this is
   * the downtown, Coronado, the bay shore and the mesas immediately behind
   * them. `downtown` rather than `residential` for the same reason San
   * Francisco is: a handful of towers is what makes a patch of speckle read as
   * a city centre instead of as a gravel bar, and at 806 m to the lot there is
   * no other channel for it.
   */
  {
    id: "san-diego",
    name: "San Diego",
    polygon: [
      [32.9, -117.24],
      [32.9, -117.06],
      [32.7, -116.98],
      [32.6, -117.06],
      [32.62, -117.22],
      [32.78, -117.26],
    ],
    gridAngle: 0.18,
    minHeight: 16,
    maxHeight: 140,
    towerChance: 0.02,
    palette: "downtown",
    coverage: 0.5,
  },
  {
    id: "ventura-oxnard",
    name: "Ventura & Oxnard",
    polygon: [
      [34.32, -119.32],
      [34.32, -119.06],
      [34.15, -119.06],
      [34.15, -119.28],
    ],
    gridAngle: 0.2,
    minHeight: 11,
    maxHeight: 40,
    towerChance: 0.003,
    palette: "residential",
    coverage: 0.56,
  },
];

export const CALIFORNIA_CITY: City = {
  id: "california",
  name: "California",
  /**
   * The middle of the board, not the middle of the corridor and not the middle
   * of the state's population.
   *
   * Scene space is centred here, and everything sized off the origin — the
   * satellite dome, the shadow box, the star field — is centred with it, so a
   * centre off to one side makes those covers too small on the far side by
   * exactly the offset. The board now runs 32.50 to 42.05 and -124.50 to
   * -114.0, whose midpoint is 37.275, -119.25. Rounded to 37.3, which is also
   * the latitude `LNG_SQUASH` above is taken at; the two have to agree or a
   * chain running east-west comes out with its peaks in the wrong places.
   *
   * It moved two degrees north with the bounds and that is the whole reason it
   * is written down: 35.3 was the middle of a board that stopped at 38.05, and
   * left where it was it would now sit ninety scene units south of the middle
   * of the frame.
   */
  center: { lat: 37.3, lng: -119.25 },

  /**
   * The board is California. All of it, and it stops where the state stops on
   * every side.
   *
   * The last version of this comment argued that `maxLat` could stay a crop —
   * "a crop along the top of the frame, far from the camera and half in the
   * fog, is the cheap direction to be wrong in". That was wrong for a reason
   * the argument could not see from inside itself: the minimap draws the whole
   * state from the same pack and the board drew two thirds of it, so the frame
   * contained a picture of California and a picture of a piece of California at
   * the same time, and the eye goes straight to the disagreement. There is no
   * cheap direction to be wrong about a silhouette this well known.
   *
   * 32.50 to 42.05 N and -124.50 to -114.0 W: the Mexican border, the Oregon
   * line, Cape Mendocino with eight kilometres of ocean west of it, and the
   * Colorado past Parker. Nothing here is chosen for the corridor's
   * convenience.
   *
   * **The price was paid in the cell, not in the bounds, and that is the whole
   * arithmetic of this change.** Extending north and west at the old 0.022 by
   * 0.027 spacing takes the lattice from 84,924 points to 168,813 — 2.02x — and
   * the terrain with it, against a mobile budget with 70,000 triangles spare.
   * Coarsening the cell by 1.42x in each axis puts it back. What matters on
   * screen is not the cell in metres but the cell as a *fraction of the board*,
   * because the camera retreats to frame whatever it is given; see `cellLat`.
   */
  bounds: { minLat: 32.5, maxLat: 42.05, minLng: -124.5, maxLng: -114.0 },
  latScale: 58,

  /**
   * 15, against 13, against the 2.25 this board shipped with. See the header
   * table: this is the number that decides whether the state has mountains on
   * it, and 2.25 put the Sierra 1.6 units off a board 284 units tall.
   *
   * The two points went on when the board became the whole state, and they are
   * not a taste change — they are what keeps the relief where it already was
   * once the camera stood further back. Relief in the frame is `peak units over
   * board span`, because `scene.ts` retreats the camera to frame the span:
   *
   * | board | exaggeration | peak | span | relief |
   * | --- | --- | --- | --- | --- |
   * | the southern two thirds | 13 | 35.7 u | 428 u | 8.3% |
   * | the whole state, at 13 | 13 | 35.7 u | 554 u | 6.4% |
   * | the whole state, at 15 | 15 | 41.2 u | 554 u | 7.4% |
   * | Southern California | 3.4 | 29.4 u | 393 u | 7.5% |
   * | the Bay Area | 3.6 | 48.7 u | 1,003 u | 4.9% |
   *
   * So 15 puts this board on Southern California's number exactly, which is the
   * calibration that matters — the two are meant to read as the same landscape
   * at two zooms.
   *
   * **The bed-of-nails objection does not survive the arithmetic here**, and the
   * old comment's warning about pushing to 20 is still correct for the board it
   * was written about. A 250 m downtown tower goes from 1.69 units to 1.95, on a
   * board whose span went from 428 to 554 — so as a fraction of the frame it is
   * 0.0035 where it was 0.0040. The towers are *smaller* in this frame than they
   * were in the last one, not larger, and the mountains merely caught up.
   */
  verticalExaggeration: 15,

  /**
   * About 3.5 km, coarsened by 1.42x when the board became the whole state.
   *
   * This is the same trade the board made once before when it grew east, made
   * again and larger, and it is worth restating rather than referring to,
   * because it is the only reason the extension fits.
   *
   * The instinct when a board looks flat is that the lattice is too fine. It is
   * not: the Sierra is 80 km wide, which is 23 cells even at this spacing, and
   * Southern California renders the San Gabriels — the range that board is
   * famous for — across 37 coarse cells. The structure a state board is missing
   * is vertical, never horizontal.
   *
   * **The cell as a fraction of the board is what the eye sees, and it did not
   * move.** The camera retreats to frame whatever it is given, so the number
   * that matters is cell over span, not cell in metres:
   *
   * | board | cell | span | fraction |
   * | --- | --- | --- | --- |
   * | corridor, before the east | 0.020° | 284 u | 0.0041 |
   * | southern two thirds | 0.022° | 428 u | 0.0030 |
   * | the whole state | 0.0312° | 554 u | 0.0033 |
   *
   * So the ground cell went from 2,449 m to 3,473 m — 42% coarser on the earth
   * — and *finer* in the frame than the board two revisions ago. The lattice
   * holds at 85,008 points against 84,924, and the terrain triangle count with
   * it.
   *
   * `cellLng` is 0.0383 rather than 0.0312 for the same reason it was 0.027
   * rather than 0.022: a degree of longitude at this latitude is `cos(37.3)` of
   * a degree of latitude, so an equal-area cell has to be 1/0.795 as wide as it
   * is tall. Both were multiplied by the same 1.42.
   */
  cellLat: 0.0312,
  cellLng: 0.0383,

  /**
   * ~2.8 km, or a little over one cell.
   *
   * The falloff exists to ramp the terrain grid's stair-stepped rim down onto
   * the smooth shore plate, so it has to be at least a cell wide. The price is
   * that Big Sur — where the Santa Lucias stand 1,500 m up within eight
   * kilometres of the surf — gets a narrow shelf before it climbs. At 1,919 m
   * to the unit that shelf is under two units wide and the range still reads as
   * falling into the sea.
   */
  coastFalloff: 0.025,

  landmasses: [CORRIDOR_LAND],
  parks: RANGES,
  inlandWater: SALTON_SEA,
  hills: HILLS,
  districts: DISTRICTS,
  landmarks: [
    /**
     * Two markers, not two buildings.
     *
     * Nothing in Los Angeles is 700 m tall. These are the board's pins — the
     * chapter list sends you to them and `label: true` prints their names — and
     * at 1,919 m to the unit an honest 310 m US Bank Tower would be 2.1 units
     * on a board 284 units across, which is not a destination, it is a speck.
     * They are deliberately narrow so they read as a spire over the city
     * speckle rather than as a building sitting on top of it.
     */
    { name: "Los Angeles", lat: 34.0522, lng: -118.2437, height: 760, footprint: 0.028, shape: "tower", color: 0xb9a288, label: true },
    { name: "San Francisco", lat: 37.7749, lng: -122.4194, height: 720, footprint: 0.026, shape: "tower", color: 0x9fb2c2, label: true },
  ],
  bridges: [],
  /**
   * The two corridors, authored twice: once as the symbol this board draws and
   * once as the road it actually is.
   *
   * `width` is 1 and 1.06 scene units, which at 1,919 m to the unit is 1,919 m
   * and 2,034 m of asphalt — wider, by a factor of two, than the widest thing in
   * downtown Los Angeles, and the most prominent marks on the state board. That
   * was a deliberate choice and it is defensible on its own terms: a 47 m
   * freeway on a board 554 units across is a fortieth of a unit and would not
   * exist at all. It is not defensible at the seam, where the same road is
   * 43–55 m on Southern California and 23–30 m on the Bay Area, because a 2 km
   * ribbon becoming a 30 m line is a change of drawing convention rather than an
   * LOD transition.
   *
   * `widthM` is US-101 and I-5 as they are on the ground — six lanes plus
   * shoulders through the Salinas Valley, eight through the San Joaquin — and it
   * is read by `cities/reconcile.ts` and by nothing else. The engine draws
   * `width`, always.
   */
  roads: [
    { path: CALIFORNIA_US_101, width: 1, widthM: 44, kind: "freeway" },
    { path: CALIFORNIA_I_5, width: 1.06, widthM: 47, kind: "freeway" },
  ],
  chapters: [
    {
      id: "california-overview",
      label: "California",
      shortLabel: "State",
      number: "01",
      description: "Los Angeles and San Francisco joined as one living route board.",
      /*
       * Framed on the middle of the bounds, and pulled back with the board:
       * `scene.ts` sizes the fog, the far plane and the orbit limits from
       * `boardSpan`, but the opening pose is authored here and does not scale
       * itself. This is the third time it has had to move — 284 units across,
       * then 428 when the state's own eastern edge arrived, now 554 with the
       * north on — and each time the failure of not moving it was the same one:
       * a shot that framed the Central Valley with a third of the state off the
       * side of the screen.
       *
       * 612/528 holds the *angle* the board is seen from — 40.8° above the
       * horizontal, the same as every version of this pose — and changes only
       * the stand-off, which is 1.39 board spans against the old 1.26. The
       * extra tenth is the board's aspect and not its size: at 428 x 319 it was
       * a landscape rectangle that filled a 16:10 frame, and at 554 x 484 it is
       * nearly square and arrives as a diamond, which needs more room in the
       * axis it is turned into. Shot at 580 the Mexican border sat seventy
       * pixels off the bottom edge.
       *
       * `chapterFraming` then widens it further on a narrow window, which is a
       * different correction for a different reason and composes with this one.
       */
      focus: { lat: 37.15, lng: -119.35, distance: 612, height: 528, rotation: 0.42 },
    },
    {
      id: "la-sf-us-101",
      label: "US-101",
      shortLabel: "101",
      number: "02",
      description: "Follow the unbadged Lumbridge EV up US-101 through coastal oak country and the Salinas Valley.",
      focus: { lat: 35.8, lng: -121.04, distance: 112, height: 72, rotation: 0.8 },
    },
    {
      id: "la-sf-i-5",
      label: "I-5 · I-580 · I-80",
      shortLabel: "I-5",
      number: "03",
      description: "Follow the Lumbridge EV on I-5 through the Central Valley, then the Bay approach over I-580 and I-80.",
      focus: { lat: 36.15, lng: -120.15, distance: 105, height: 70, rotation: 0.78 },
    },
    {
      id: "los-angeles",
      label: "Los Angeles",
      shortLabel: "LA",
      number: "04",
      description: "The southern door into Tera's detailed Southern California board.",
      focus: { lat: 34.0522, lng: -118.2437, distance: 38, height: 26, rotation: 0.8 },
    },
    {
      id: "san-francisco",
      label: "San Francisco",
      shortLabel: "SF",
      number: "05",
      description: "The northern door into the detailed Bay Area board and Lumbridge HQ.",
      focus: { lat: 37.7749, lng: -122.4194, distance: 38, height: 26, rotation: 0.8 },
    },
    /**
     * The sixth chapter, and the reason it exists is that the tour used to end
     * where the board used to end.
     *
     * Two hundred kilometres of state came onto this board and the chapter list
     * had no way to look at any of it: every authored pose sat below 38 N, so a
     * visitor who never dragged the camera would never see the Klamaths, the
     * Cascades or four hundred kilometres of North Coast. A board with land on
     * it that the tour cannot reach is a board that is half decoration.
     *
     * Sited between Shasta and Lassen rather than on either, because the gap is
     * as much of the picture as the peaks are — a hundred kilometres of Hat
     * Creek country with a 4,320 m cone at one end and a 3,190 m one at the
     * other, and nothing else in California looks like that.
     */
    {
      id: "shasta-cascades",
      label: "Shasta & the north",
      shortLabel: "North",
      number: "06",
      description:
        "Two volcanoes, the Klamath knot and four hundred kilometres of coast that used to be ocean.",
      focus: { lat: 40.6, lng: -122.4, distance: 212, height: 152, rotation: 0.5 },
    },
  ],

  /**
   * California in late summer, which is when the state looks most like itself:
   * gold grass, dark chaparral, bare granite above the tree line.
   *
   * The two changes that matter are `flats` and `upland`. They used to be
   * 0xb7a16c and 0x9a8155 — two browns half a step apart — so the entire board
   * was one value and the ranges could not separate from the farmland at any
   * hour. `flats` is now the Central Valley's harvested gold and `upland` is a
   * pale granite grey, which is a real difference in *hue* as well as value and
   * survives both the ACES shoulder at noon and the warm sun at dusk. Green
   * comes from `parks`; see the header.
   */
  palette: {
    skyTop: 0x7da6c9,
    skyHorizon: 0xe9d8bb,
    sea: 0x3c6d8b,
    lake: 0x4a7d93,
    shore: 0xc4b184,
    sand: 0xceba8c,
    flats: 0xb49b57,
    /**
     * Warmer and a shade darker than the grey it used to be, because it is no
     * longer being asked to be two things at once.
     *
     * `upland` was 0xa89d84 — a pale granite — and it had to serve both the
     * Sierra crest and the Mojave, which are not the same colour in any light.
     * With `alpine` carrying the rock above 900 m, this is free to be what
     * covers most of the ground it is actually painted on: creosote and desert
     * varnish on an alluvial fan, which is a warm mid brown.
     */
    upland: 0x9d8a63,
    /**
     * Bare granite above the tree line, and the reason the ranges in the
     * south-east corner are visible at all.
     *
     * See `ScenePalette.alpine` and `ALPINE_FROM` in `terrain.ts`. Deliberately
     * *lighter* than everything under it, which is the way round a photograph
     * has it: exposed rock and old snow are the brightest ground in the state,
     * and a board that darkens with altitude reads as a bruise.
     */
    alpine: 0xb9b3a4,
    park: 0x76854e,
    parkHigh: 0x3d5739,
  },
};

export default CALIFORNIA_CITY;
