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

+90 -21
View File
@@ -98,14 +98,14 @@
var rings = [], total = 0;
var re = /([MmLlHhVvZz])|(-?\d*\.?\d+)/g;
Object.keys(world.paths).forEach(function (cc) {
var d = world.paths[cc], m, cmd = '', nums = [], cur = null, x = 0, y = 0;
var d = world.paths[cc], m, cmd = '', nums = [], cur = null, x = 0, y = 0, sx = 0, sy = 0;
function flush() {
if (!cmd) return;
var up = cmd.toUpperCase(), rel = cmd !== up, i;
if (up === 'M' || up === 'L') {
for (i = 0; i + 1 < nums.length; i += 2) {
x = rel ? x + nums[i] : nums[i]; y = rel ? y + nums[i + 1] : nums[i + 1];
if (up === 'M' && i === 0) { cur = [[x, y]]; rings.push(cur); } else if (cur) cur.push([x, y]);
if (up === 'M' && i === 0) { cur = [[x, y]]; rings.push(cur); sx = x; sy = y; } else if (cur) cur.push([x, y]);
}
} else if (up === 'H') { nums.forEach(function (n) { x = rel ? x + n : n; if (cur) cur.push([x, y]); }); }
else if (up === 'V') { nums.forEach(function (n) { y = rel ? y + n : n; if (cur) cur.push([x, y]); }); }
@@ -113,7 +113,7 @@
}
re.lastIndex = 0;
while ((m = re.exec(d))) {
if (m[1]) { flush(); cmd = m[1]; if (cmd === 'z' || cmd === 'Z') cmd = ''; }
if (m[1]) { flush(); cmd = m[1]; if (cmd === 'z' || cmd === 'Z') { cmd = ''; x = sx; y = sy; } } // after z the pen returns to the subpath start
else nums.push(parseFloat(m[2]));
}
flush();
@@ -126,21 +126,37 @@
pts.push(p); last = p;
});
if (pts.length < 3) return;
var n = pts.length, v = new Float32Array(n * 3), edge = new Uint8Array(n);
for (var i = 0; i < n; i++) {
var lon = pts[i][0] / WORLD_W * 360 - 180, lat = LAT_TOP - pts[i][1] / WORLD_H * (LAT_TOP - LAT_BOT);
var cl = Math.cos(lat * RAD);
v[i * 3] = cl * Math.sin(lon * RAD); v[i * 3 + 1] = Math.sin(lat * RAD); v[i * 3 + 2] = cl * Math.cos(lon * RAD);
var q = pts[(i + n - 1) % n];
// orientation in lon/lat space (y up): ccw when the shoelace sum of the map (y down) is negative
var area = 0, k0;
for (k0 = 0; k0 < pts.length; k0++) { var pa = pts[k0], pb = pts[(k0 + 1) % pts.length]; area += pa[0] * pb[1] - pb[0] * pa[1]; }
var items = []; // [x, y, z, edge]
for (var i = 0; i < pts.length; i++) {
var q = pts[(i + pts.length - 1) % pts.length];
// segments lying on the map border (antimeridian cut) or on the clipped
// southern edge are not borders: they are not stroked on the globe
if ((pts[i][0] < 1.5 && q[0] < 1.5) || (pts[i][0] > WORLD_W - 1.5 && q[0] > WORLD_W - 1.5) ||
(pts[i][1] > WORLD_H - 1.5 && q[1] > WORLD_H - 1.5)) edge[i] = 1;
var onEdge = ((pts[i][0] < 1.5 && q[0] < 1.5) || (pts[i][0] > WORLD_W - 1.5 && q[0] > WORLD_W - 1.5) ||
(pts[i][1] > WORLD_H - 1.5 && q[1] > WORLD_H - 1.5)) ? 1 : 0;
// a ring that runs along the clipped southern edge across the whole map
// (Antarctica) really wraps around the pole: go through it
if (pts[i][1] > WORLD_H - 1.5 && q[1] > WORLD_H - 1.5 && Math.abs(pts[i][0] - q[0]) > WORLD_W * 0.5) items.push([0, -1, 0, 1]);
// long edges follow the straight line of the flat map (which is how the data
// is drawn there), so they are cut into short pieces rather than one 3D chord
var dd = Math.sqrt((pts[i][0] - q[0]) * (pts[i][0] - q[0]) + (pts[i][1] - q[1]) * (pts[i][1] - q[1])), steps = Math.min(200, Math.ceil(dd / 10));
if (dd > 60) onEdge = 1; // a closing chord of the data, not a coastline: no outline
if (Math.abs(pts[i][0] - q[0]) > WORLD_W * 0.5) steps = 1; // wraps the antimeridian: keep it a single edge
for (var sIdx = 1; sIdx <= steps; sIdx++) {
var f = sIdx / steps, mx = q[0] + (pts[i][0] - q[0]) * f, my = q[1] + (pts[i][1] - q[1]) * f;
var lon = mx / WORLD_W * 360 - 180, lat = LAT_TOP - my / WORLD_H * (LAT_TOP - LAT_BOT);
var cl = Math.cos(lat * RAD);
items.push([cl * Math.sin(lon * RAD), Math.sin(lat * RAD), cl * Math.cos(lon * RAD), onEdge]);
}
}
out.push({ v: v, edge: edge, n: n });
var n = items.length, v = new Float32Array(n * 3), edge = new Uint8Array(n);
for (var j = 0; j < n; j++) { v[j * 3] = items[j][0]; v[j * 3 + 1] = items[j][1]; v[j * 3 + 2] = items[j][2]; edge[j] = items[j][3]; }
out.push({ v: v, edge: edge, n: n, ccw: area < 0 });
total += n;
});
geo = { rings: out, total: total, scratch: new Float32Array(total * 3) };
geo = { rings: out, total: total, scratch: new Float32Array(total * 3), maxN: out.reduce(function (m, r) { return Math.max(m, r.n); }, 0) };
return geo;
}
@@ -210,6 +226,7 @@
this.build();
this.readTheme();
this.resize();
if (window.__URUTAU_LIVE_TEST) window.__URUTAU_LIVE_TEST.inst = this; // test hook, unset in production
this.unsub = U.onEvent ? U.onEvent(function (e) { self.ingest(e); }) : null;
this.listen(document, 'visibilitychange', function () { self.onVisibility(); });
@@ -956,6 +973,61 @@
this.rx = x1; this.ry = y * this.cp - z1 * this.sp; this.rz = y * this.sp + z1 * this.cp;
};
// Adds one ring (unit-sphere view coordinates x, y, z at sc[base..]) to the current
// path, clipped to the visible hemisphere: edges that cross the horizon are cut
// where they meet it and the gap is closed by an arc along the limb, walked in the
// ring's own direction, so the fill never covers the wrong side.
P.clipRing = function (g, sc, base, n, ccw, cx, cy, R) {
var j, p, q, runs = [], TWO = Math.PI * 2, EPS = 0.015; // a hair above the horizon: grazing vertices would give unstable cut points
function limb(a, b) { // where edge a->b meets z = 0, on the unit circle
var t = (sc[a + 2] - EPS) / (sc[a + 2] - sc[b + 2]);
var x = sc[a] + (sc[b] - sc[a]) * t, y = sc[a + 1] + (sc[b + 1] - sc[a + 1]) * t, h = Math.sqrt(x * x + y * y) || 1;
return [x / h, y / h];
}
for (j = 0; j < n; j++) {
p = base + ((j + n - 1) % n) * 3; q = base + j * 3;
if (sc[q + 2] > EPS && sc[p + 2] <= EPS) {
var len = 1;
while (len < n && sc[base + ((j + len) % n) * 3 + 2] > EPS) len++;
var last = base + ((j + len - 1) % n) * 3, nxt = base + ((j + len) % n) * 3;
var en = limb(p, q), ex = limb(last, nxt);
runs.push({ s: j, len: len, en: en, ex: ex, ae: Math.atan2(-en[1], en[0]), ax: Math.atan2(-ex[1], ex[0]), done: false });
}
}
if (!runs.length) {
if (sc[base + 2] <= EPS) return; // wholly hidden
for (j = 0; j < n; j++) { q = base + j * 3; if (j) g.lineTo(cx + sc[q] * R, cy - sc[q + 1] * R); else g.moveTo(cx + sc[q] * R, cy - sc[q + 1] * R); }
g.closePath();
return;
}
// Stitch the visible runs into closed contours the way a polygon clipper does:
// from where a run leaves the disc, follow the limb in the ring's own direction
// to the nearest point where some run comes back in.
for (var r0 = 0; r0 < runs.length; r0++) {
if (runs[r0].done) continue;
var run = runs[r0];
g.moveTo(cx + run.en[0] * R, cy - run.en[1] * R);
for (;;) {
run.done = true;
for (var k = 0; k < run.len; k++) { q = base + ((run.s + k) % n) * 3; g.lineTo(cx + sc[q] * R, cy - sc[q + 1] * R); }
g.lineTo(cx + run.ex[0] * R, cy - run.ex[1] * R);
var best = null, bd = 1e9;
for (var m = 0; m < runs.length; m++) {
var d = ccw ? run.ax - runs[m].ae : runs[m].ae - run.ax;
d = ((d % TWO) + TWO) % TWO;
// an arc of almost a full turn is a rounding artefact (the cut points of a sliver
// came out in the wrong order): walk the short way back instead
if (d > TWO * 0.95) d -= TWO;
if (d < bd) { bd = d; best = runs[m]; }
}
g.arc(cx, cy, R, run.ax, best.ae, bd < 0 ? !ccw : !!ccw);
if (best === runs[r0] || best.done) break;
run = best;
}
g.closePath();
}
};
P.drawGlobeBase = function (g, m) {
var cx = this.cx, cy = this.cy, R = this.gR, acc = this.pal.accent, tx = this.pal.text, dark = this.dark;
var lat, lon, k, up, cl;
@@ -992,16 +1064,13 @@
var rings = this.geo.rings, sc = this.geo.scratch, o = 0, i, j;
g.beginPath();
for (i = 0; i < rings.length; i++) {
var r = rings[i], v = r.v, n = r.n;
var r = rings[i], v = r.v, n = r.n, base = o;
// rotate every vertex (true screen position and depth, nothing pinned)
for (j = 0; j < n; j++) {
this.rot(v[j * 3], v[j * 3 + 1], v[j * 3 + 2]);
var sx = this.rx, sy = this.ry, z = this.rz;
if (z < 0) { var hl = Math.sqrt(sx * sx + sy * sy) || 1; sx /= hl; sy /= hl; } // hidden side: pinned to the limb
sc[o] = cx + sx * R; sc[o + 1] = cy - sy * R; sc[o + 2] = z;
if (j === 0) g.moveTo(sc[o], sc[o + 1]); else g.lineTo(sc[o], sc[o + 1]);
o += 3;
sc[o] = this.rx; sc[o + 1] = this.ry; sc[o + 2] = this.rz; o += 3;
}
g.closePath();
this.clipRing(g, sc, base, n, r.ccw, cx, cy, R);
}
g.fillStyle = rgba(tx, 0.2); g.fill();
g.strokeStyle = rgba(tx, dark ? 0.38 : 0.45); g.lineWidth = 0.8; g.beginPath();
@@ -1010,7 +1079,7 @@
var e = rings[i].edge, n2 = rings[i].n;
for (j = 1; j <= n2; j++) {
var p = (j - 1) * 3 + o, q = (j % n2) * 3 + o;
if (sc[p + 2] > 0 && sc[q + 2] > 0 && !e[j % n2]) { g.moveTo(sc[p], sc[p + 1]); g.lineTo(sc[q], sc[q + 1]); }
if (sc[p + 2] > 0 && sc[q + 2] > 0 && !e[j % n2]) { g.moveTo(cx + sc[p] * R, cy - sc[p + 1] * R); g.lineTo(cx + sc[q] * R, cy - sc[q + 1] * R); }
}
o += n2 * 3;
}