1
0
mirror of git://f0xx.org/ac/ac-be-hub synced 2026-08-09 20:59:23 +03:00

feat(globe3d=11): latf/lngf/zy/zx land plate zoom URL params

Default latf=1.25; linear multiply on lon/lat plus optional non-linear
bias via zy/zx toward equator and prime meridian.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Anton Afanasyeu
2026-08-05 19:34:26 +02:00
parent ae83a64042
commit a4e582d212
2 changed files with 62 additions and 24 deletions

View File

@@ -12,7 +12,7 @@
* globe3d=9: v4 sphere grid only (thin EW + NS) — proper rotation baseline.
* globe3d=10: v4 visible-arc → screen ellipse (hub ry), disk-clipped.
* globe3d=11: v10 grid + geographic mercator-flat land (360° U-wrap).
* ?f=0.66 — NS latitude factor (default 0.66; lower = more squeeze).
* ?latf=1.25&lngf=1&zy=0&zx=0 — land plate zoom (linear + non-linear).
*/
export const GLOBE_VIEW = { imgW: 1920, imgH: 1080, cx: 720, cy: 560, r: 322, rim: 330 };
@@ -30,14 +30,39 @@ const CONTINENT_INNER_SX = 1.2408477842003853;
const CONTINENT_INNER_SY = 1.2408477842003853;
/** Map plate center longitude (extract_red_polygons.py CENTER_LON). */
const MERCATOR_LON_CENTER = (12 * Math.PI) / 180;
/** Default NS latitude factor (override with ?f= on globe3d=11). */
const CONTINENT_LAT_FACTOR_DEFAULT = 0.66;
/** Default land-plate zoom (?latf / ?lngf / ?zy / ?zx on globe3d=11). */
const LAND_ZOOM_DEFAULT = { latf: 1.25, lngf: 1, zy: 0, zx: 0 };
function resolveContinentLatFactor(raw) {
if (typeof raw !== 'number' || !isFinite(raw)) {
return CONTINENT_LAT_FACTOR_DEFAULT;
function clampZoomNum(v, min, max, fallback) {
if (typeof v !== 'number' || !isFinite(v)) {
return fallback;
}
return Math.max(0.05, Math.min(2, raw));
return Math.max(min, Math.min(max, v));
}
function resolveLandZoom(raw) {
const r = raw && typeof raw === 'object' ? raw : {};
return {
latf: clampZoomNum(r.latf, 0.05, 4, LAND_ZOOM_DEFAULT.latf),
lngf: clampZoomNum(r.lngf, 0.05, 4, LAND_ZOOM_DEFAULT.lngf),
zy: clampZoomNum(r.zy, -4, 4, LAND_ZOOM_DEFAULT.zy),
zx: clampZoomNum(r.zx, -4, 4, LAND_ZOOM_DEFAULT.zx),
};
}
/**
* Linear latf/lngf on sphere lon/lat; zy/zx bias zoom toward equator/ prime meridian:
* mul = factor × (1 + z×(1t²)), t = |coord|/pole (1 at pole, 0 at center line).
*/
function landZoomLonLat(lon, lat, zoom) {
const latT = Math.min(1, Math.abs(lat) / (Math.PI / 2));
const lonT = Math.min(1, Math.abs(lon) / Math.PI);
const latMul = zoom.latf * (1 + zoom.zy * (1 - latT * latT));
const lonMul = zoom.lngf * (1 + zoom.zx * (1 - lonT * lonT));
return {
lon: wrapLon(lon * lonMul + MERCATOR_LON_CENTER),
lat: Math.max(-1.52, Math.min(1.52, lat * latMul)),
};
}
const RASTER_SCALE = 2;
const AXIS_STEPS = 160;
@@ -961,11 +986,10 @@ function sampleFlatPlateFromHub(mercFlat, hpX, hpY) {
}
/** Sphere tex → mercator-flat plate (lon center + inverse Mercator Y). */
function sampleMercFlatFromTex(mercFlat, tex, latFactor) {
function sampleMercFlatFromTex(mercFlat, tex, landZoom) {
const ll = texLonLat(tex);
const lon = wrapLon(ll.lon + MERCATOR_LON_CENTER);
const lat = Math.max(-1.52, Math.min(1.52, ll.lat * latFactor));
return sampleMercFlat(mercFlat, lon, lat);
const mapped = landZoomLonLat(ll.lon, ll.lat, landZoom);
return sampleMercFlat(mercFlat, mapped.lon, mapped.lat);
}
function isLandPixel(r, g, b, a) {
@@ -1077,11 +1101,11 @@ function sampleLandRgbaMercator(mercFlat, tex) {
}
/** globe3d=11 — geographic mercator wrap (360°); z > LIMB_Z only. */
function sampleLandVisibleHemisphere(mercFlat, tex, latFactor) {
function sampleLandVisibleHemisphere(mercFlat, tex, landZoom) {
if (tex.z <= LIMB_Z) {
return null;
}
const flat = sampleMercFlatFromTex(mercFlat, tex, latFactor);
const flat = sampleMercFlatFromTex(mercFlat, tex, landZoom);
if (isHubContinentPixel(flat[0], flat[1], flat[2], flat[3])) {
return hubContinentRgba(flat);
}
@@ -1187,7 +1211,7 @@ export async function mountHubGlobe(stage, opts) {
const build = opts.build || 'earth3d';
const reducedMotion = !!opts.reducedMotion;
const renderVersion = Math.max(1, parseInt(opts.renderVersion, 10) || 1);
const continentLatFactor = resolveContinentLatFactor(opts.continentLatFactor);
const landZoom = resolveLandZoom(opts.landZoom);
const canvas = document.createElement('canvas');
canvas.className = 'hub-globe-canvas';
@@ -1299,7 +1323,7 @@ export async function mountHubGlobe(stage, opts) {
cy,
r,
fillDiskRegion(ctx, cx, cy, r, rotation, function (tex) {
const l = sampleLandVisibleHemisphere(mercFlat, tex, continentLatFactor);
const l = sampleLandVisibleHemisphere(mercFlat, tex, landZoom);
return l || [0, 0, 0, 0];
})
);
@@ -1375,7 +1399,10 @@ export async function mountHubGlobe(stage, opts) {
raf = requestAnimationFrame(tick);
stage.dataset.globe3d = String(renderVersion);
if (renderVersion >= 11) {
stage.dataset.globeLatFactor = String(continentLatFactor);
stage.dataset.globeLatf = String(landZoom.latf);
stage.dataset.globeLngf = String(landZoom.lngf);
stage.dataset.globeZy = String(landZoom.zy);
stage.dataset.globeZx = String(landZoom.zx);
}
stage.dataset.globeAxis =
renderVersion === 11
@@ -1405,7 +1432,10 @@ export async function mountHubGlobe(stage, opts) {
canvas.remove();
delete stage.dataset.globe3d;
delete stage.dataset.globeAxis;
delete stage.dataset.globeLatFactor;
delete stage.dataset.globeLatf;
delete stage.dataset.globeLngf;
delete stage.dataset.globeZy;
delete stage.dataset.globeZx;
},
};
}