# Compare

A static, globe country comparison app. No build step, package installation,
backend, or runtime CDN requests.

## Run

From the site root, run `deno task dev` and open
`http://localhost:3456/geo/compare/`.

Choose two places, compare their sizes, and practice “bigger than” and “smaller
than” with a partner. The activity uses the site's shared styles.

## Interaction

Select two countries using the searchable selectors (arrow keys and Enter
supported). They initially appear overlaid and centered. Drag the background to
rotate the globe; drag the orange outline or its dot to move that country across
the surface. Focus the globe and use arrow keys to rotate it; focus the orange
outline to move it with arrow keys (Shift for larger steps). Directional buttons
move the country. Bring together relocates it onto the stationary country and
centers the view. Original location restores its geographic position and centers
it. Swap exchanges roles and brings the new pair together.

## Globe and movement

D3's orthographic projection renders a rotatable globe. Country movement applies
a rigid three-dimensional rotation to every vertex on the unit sphere, then
reprojects the result on every movement. This preserves spherical area, shape,
and distances, while the visible outline changes with the viewing angle. No
screen-space translation or scaling is used.

The globe's far side is clipped at the horizon. Pointer movement outside the
disk is clamped just inside the visible horizon; rotate the background to
continue moving around the world. Disconnected islands remain part of the same
rigid shape. Bring together aligns the spherical centroids of the largest
polygons. The control dot can fall outside concave land. Viewing the center
gives the clearest comparison; orthographic foreshortening compresses regions
near the horizon. This is a vector globe rather than a terrain-rendering 3D
engine. Zoom ranges from 1× to 8× using the +/− buttons, mouse wheel, or
two-finger pinch. With the globe focused, +/− also zoom and 0 restores the whole
globe. Zoom centers on the view; rotate the globe to frame another region. A
pinch suspends outline dragging until the next gesture. Both selected outlines
and the base globe always share the same scale.

## Data and area methodology

242 country/territory features from Natural Earth v5.1.2, 1:50m Admin 0
Countries. Source:
https://github.com/nvkelso/natural-earth-vector/blob/v5.1.2/geojson/ne_50m_admin_0_countries.geojson

The local GeoJSON retains source geometry and reduces properties to English
name, administrative name, long-name alias, and administrative code. Search
checks those fields. Coverage and grouping of dependencies/overseas areas follow
Natural Earth; not all territories are separate features. Boundaries are
cartographic representations, not sovereignty claims.

Areas are calculated consistently from bundled polygons using d3.geoArea
(steradians) multiplied by mean Earth radius squared (6,371.0088 km). These are
approximate spherical areas of generalized geometry, not official surveyed
statistics. Inland water is included where enclosed by source polygons, and
excluded where represented as holes. Overseas polygons are included when grouped
in that feature. Coastline simplification and feature grouping affect totals.

Natural Earth is public domain:
https://www.naturalearthdata.com/about/terms-of-use/

## Bundled code

- d3-geo 3.1.1 (ISC)
- d3-array 3.2.4 (ISC)
- internmap 2.0.3 (ISC)

ES modules downloaded from jsDelivr; dependency imports rewritten to local
relative files. License texts are in vendor/*.LICENSE. No framework or build
tools.

## Verification

Run `deno run --allow-read checks.mjs` for dataset geometry, area, projection,
antimeridian, and constant-area translation checks. Browser checks cover search,
keyboard movement, swap/reset, and responsive layout.

## Continent outlines

Seven selectable continent outlines are bundled in `data/continents.geojson`,
dissolved from the same Natural Earth country geometry using topojson-server
3.0.1 and topojson-client 3.1.0 during data preparation. There are no additional
runtime dependencies. `scripts/build-continents.mjs` records the generation
process. Continent areas use the same spherical calculation as countries.

Grouping follows Natural Earth's CONTINENT field: transcontinental countries are
assigned whole, not split along physical continental boundaries (Russia is
grouped with Europe; Turkey with Asia). Overseas pieces follow their source
feature's grouping. Oceania includes Australia, New Zealand, and Pacific island
features assigned to Oceania. Features classified as “Seven seas (open ocean)”
are excluded from the seven continent outlines but remain selectable
individually. These are convenient dataset groupings, not precise
physical-continent boundaries. Large continents naturally extend beyond the
visible hemisphere; rotate the globe to inspect their full outline.

## U.S. states

All 50 U.S. states plus the District of Columbia are selectable. Search by name
or postal abbreviation; state names are explicitly labeled to distinguish
Georgia from the country. State areas use the same approximate spherical
geometry method as countries. Alaska and Hawaii retain their actual geography
and all source polygon pieces.

Source: Natural Earth v5.1.2, 1:50m Admin 1 States/Provinces, public domain
under the Natural Earth terms linked above:
https://github.com/nvkelso/natural-earth-vector/blob/v5.1.2/geojson/ne_50m_admin_1_states_provinces.geojson

`scripts/build-us-states.py` extracts USA features and minimal search metadata
into `data/us-states.geojson`. No runtime dependencies were added. State
outlines do not add border clutter to the base globe; they appear when selected.
At world scale, small states and D.C. are best moved using the control dot or
keyboard.
