fix(live): globe sea and land colors, world map antimeridian rings
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 22s
CI / Tests (Linux, race detector) (push) Successful in 33s
CI / Dependency audit (push) Successful in 13s
Release / Plan (reuse the published image?) (push) Successful in 3s
Release / ci (push) Skipped
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Successful in 14s
Release / Gitea release (push) Successful in 3s

The globe clipped country rings by pushing hidden vertices to the limb
and closing them with chords, so the fill flipped between sea and land
as it turned. Rings are now clipped at the horizon and closed along the
limb in their own orientation; the path parser returns to the subpath
start after z; long edges follow the map projection.

gen-world.mjs unwraps longitudes and clips rings that cross the 180th
meridian (Russia, Fiji) at the map edge instead of leaving them open,
which filled the Sea of Okhotsk as land.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-14 19:27:57 -03:00
1 parent 783b0cba3e
commit 8f1ac462d1
6 files changed
+157 -33

No files matched your search

+51 -10
View File
@@ -29,6 +29,45 @@ const ring = (idx) => {
return pts;
};
// Rings that cross the antimeridian carry a +-360 degree longitude jump (the source is cut there).
// Unwrap them into one continuous ring, then clip against the map band [-180,180] on
// copies shifted by -360/0/+360, so each piece is closed along the map border instead of
// by a chord across the map.
const unwrap = (pts) => {
const out = [[pts[0][0], pts[0][1]]];
let off = 0;
for (let i = 1; i < pts.length; i++) {
const d = pts[i][0] + off - out[i - 1][0];
if (d > 180) off -= 360; else if (d < -180) off += 360;
out.push([pts[i][0] + off, pts[i][1]]);
}
return out;
};
// Sutherland-Hodgman against one vertical line
const clipX = (pts, edge, keepLeft) => {
const inside = (p) => (keepLeft ? p[0] <= edge : p[0] >= edge);
const out = [];
for (let i = 0; i < pts.length; i++) {
const a = pts[i], b = pts[(i + 1) % pts.length];
const ia = inside(a), ib = inside(b);
if (ia) out.push(a);
if (ia !== ib) out.push([edge, a[1] + ((b[1] - a[1]) * (edge - a[0])) / (b[0] - a[0])]);
}
return out;
};
const pieces = (pts) => {
if (pts.length > 1 && pts[0][0] === pts[pts.length - 1][0] && pts[0][1] === pts[pts.length - 1][1]) pts = pts.slice(0, -1);
pts = unwrap(pts);
const res = [];
for (const k of [-360, 0, 360]) {
const shifted = pts.map(([x, y]) => [x + k, y]);
if (!shifted.some(([x]) => x > -180 && x < 180)) continue;
const c = clipX(clipX(shifted, 180, true), -180, false);
if (c.length >= 3) res.push(c);
}
return res;
};
const paths = {}, cent = {};
for (const g of topo.objects.countries.geometries) {
const c = byNum.get(String(g.id).padStart(3, '0'));
@@ -37,17 +76,19 @@ for (const g of topo.objects.countries.geometries) {
let d = '';
for (const poly of polys) {
for (const r of poly) {
const pts = ring(r).map(([lo, la]) => [Math.round(px(lo)), Math.round(py(la))]);
const out = [];
for (const p of pts) { const l = out[out.length - 1]; if (!l || l[0] !== p[0] || l[1] !== p[1]) out.push(p); }
if (out.length < 4) continue;
let s = `M${out[0][0]} ${out[0][1]}`, px0 = out[0][0], py0 = out[0][1];
for (const [x, y] of out.slice(1)) {
// a ring crossing the antimeridian jumps across the map: start a new subpath instead of drawing a line over it
s += Math.abs(x - px0) > W / 2 ? `M${x} ${y}` : `l${x - px0} ${y - py0}`;
px0 = x; py0 = y;
for (const piece of pieces(ring(r))) {
const out = [];
for (const [lo, la] of piece) {
const p = [Math.round(px(lo)), Math.round(py(la))];
const l = out[out.length - 1];
if (!l || l[0] !== p[0] || l[1] !== p[1]) out.push(p);
}
if (out.length > 1 && out[0][0] === out[out.length - 1][0] && out[0][1] === out[out.length - 1][1]) out.pop();
if (out.length < 3) continue;
let s = `M${out[0][0]} ${out[0][1]}`, px0 = out[0][0], py0 = out[0][1];
for (const [x, y] of out.slice(1)) { s += `l${x - px0} ${y - py0}`; px0 = x; py0 = y; }
d += s + 'z';
}
d += s + 'z';
}
}
if (d) paths[c.cca2] = d;