{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "geo",
  "title": "Geo",
  "description": "Places on a flat map of the world by latitude and longitude, and the land as a fixed grid of dots, a point every 2.5 degrees, with no map package.",
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/lib/geo.ts",
      "content": "/*\n * Places on a flat map of the world, by latitude and longitude, and the land\n * as a grid of dots. The map is equirectangular: a degree is one unit across\n * and one down, so a place's point is its longitude east of the map's west\n * edge and its latitude south of its north edge. The land is fixed data, a\n * point every 2.5 degrees with every other row set half a step east, made\n * once by `scripts/make-geo-land.ts` from Natural Earth: no map package, and\n * nothing worked out from shapes at runtime.\n *\n *   const bounds = WORLD\n *   projectPoint({ lat: 51.5, lng: -0.13 }, bounds) // { x: 179.87, y: 32.5 }\n *   dotsPath(landDots(bounds))                     // one path, a dot a point\n */\n\n/** A place on the earth, in degrees: `lat` north of the equator, `lng` east of Greenwich. */\ninterface LatLng {\n  lat: number\n  lng: number\n}\n\n/** The part of the earth a map shows, in degrees. `west` is less than `east`: a map doesn't cross the date line. */\ninterface MapBounds {\n  north: number\n  south: number\n  west: number\n  east: number\n}\n\n/** A point on the map, in its own units: a degree each, from its west edge and its north edge. */\ninterface MapPoint {\n  x: number\n  y: number\n}\n\n/** The world, from 84°N, above Greenland, to 58°S, under Cape Horn: Antarctica is left out. */\nconst WORLD: MapBounds = { north: 84, south: -58, west: -180, east: 180 }\n\n/** The land's grid: a point every `step` degrees, `rows` rows from `north` down, `columns` around the world. */\nconst LAND_GRID = { step: 2.5, north: 84, rows: 57, columns: 144 } as const\n\n/**\n * Each row of the grid as runs of sea and land, sea first, in base 36, rows\n * joined by `|`: `3.a.2` is 3 points of sea, 10 of land, 2 of sea. Made by\n * `scripts/make-geo-land.ts`, from Natural Earth's land at 1:110m.\n */\nconst LAND =\n  '13.8.7.a.28|x.3.2.5.1.k.f.3.8.1.h.3.x|r.1.5.1.4.3.2.l.e.1.1.2.1q|o.5.2.1.1.6.9.g.u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6.y.f.b|17.8.s.5.y.4.3.8.b|17.5.1.1.t.1.12.1.7.6.c|17.6.27.4.c|16.5.2m.1.2|16.5.2b.1.a.1.2|16.3.2m.1.4|16.4.2q|15.3.2s|16.3.2r|17.2.2r|40'\n\n/** The grid's point at `row` and `column`: every other row is set half a step east, so the dots pack as a weave. */\nfunction landGridPoint(row: number, column: number): LatLng {\n  const { step, north } = LAND_GRID\n  return {\n    lat: north - (row + 0.5) * step,\n    lng: -180 + (column + 0.5 + (row % 2 === 1 ? 0.5 : 0)) * step,\n  }\n}\n\nlet landPoints: LatLng[] | undefined\n\n/** Every point of the grid that is on land, read once from `LAND`. */\nfunction allLand(): LatLng[] {\n  if (landPoints) return landPoints\n  const points: LatLng[] = []\n  LAND.split('|').forEach((runs, row) => {\n    let column = 0\n    runs.split('.').forEach((run, index) => {\n      const count = Number.parseInt(run, 36)\n      // Runs go sea, land, sea, land: the odd ones are land.\n      if (index % 2 === 1) {\n        for (let at = column; at < column + count; at++)\n          points.push(landGridPoint(row, at))\n      }\n      column += count\n    })\n  })\n  landPoints = points\n  return points\n}\n\n/** The map's size in its own units: a degree each way. */\nfunction mapSize(bounds: MapBounds): { width: number; height: number } {\n  return {\n    width: bounds.east - bounds.west,\n    height: bounds.north - bounds.south,\n  }\n}\n\n/** Where `point` sits on the map of `bounds`, in the map's units. */\nfunction projectPoint(point: LatLng, bounds: MapBounds): MapPoint {\n  return {\n    x: round(point.lng - bounds.west),\n    y: round(bounds.north - point.lat),\n  }\n}\n\n/** The land's dots inside `bounds`, as points on its map, row by row from the north and west to east. */\nfunction landDots(bounds: MapBounds): MapPoint[] {\n  return allLand()\n    .filter(\n      (point) =>\n        point.lat <= bounds.north &&\n        point.lat >= bounds.south &&\n        point.lng >= bounds.west &&\n        point.lng <= bounds.east,\n    )\n    .map((point) => projectPoint(point, bounds))\n}\n\n/**\n * Dots as one path of round-capped strokes that go nowhere, so thousands of\n * them are one element. Each dot along a row is a move from the one before\n * it, which keeps the path short; a new row starts from its own point.\n */\nfunction dotsPath(dots: readonly MapPoint[]): string {\n  let path = ''\n  let last: MapPoint | undefined\n  for (const dot of dots) {\n    path +=\n      last && last.y === dot.y ? `m${round(dot.x - last.x)} 0h0` : `M${dot.x} ${dot.y}h0`\n    last = dot\n  }\n  return path\n}\n\n/** To three places, so the server's markup and the browser's agree. */\nfunction round(value: number): number {\n  return Math.round(value * 1000) / 1000\n}\n\nexport type { LatLng, MapBounds, MapPoint }\nexport { dotsPath, LAND_GRID, landDots, landGridPoint, mapSize, projectPoint, WORLD }\n",
      "type": "registry:lib",
      "target": "@lib/geo.ts"
    }
  ],
  "type": "registry:lib"
}