Apply the eight galaxy visual refinements from the review
This commit is contained in:
@@ -74,6 +74,61 @@ export function layoutLockLabels(
|
||||
}
|
||||
}
|
||||
|
||||
const yMin = -160;
|
||||
const yMax = 108;
|
||||
const xMin = -230;
|
||||
const xMax = 230;
|
||||
for (let i = 0; i < labels.length; i++) {
|
||||
const star = starPositions[i];
|
||||
const hitsChrome =
|
||||
labels[i].y < yMin ||
|
||||
labels[i].y > yMax ||
|
||||
labels[i].x < xMin ||
|
||||
labels[i].x > xMax;
|
||||
const hitsNeighbor = starPositions.some(
|
||||
(other, k) => k !== i && dist(labels[i], other) < starR + 20,
|
||||
);
|
||||
if (hitsChrome || hitsNeighbor) {
|
||||
const ang = Math.atan2(star.y, star.x);
|
||||
labels[i] = {
|
||||
x: star.x - Math.cos(ang) * (starR + 34),
|
||||
y: star.y - Math.sin(ang) * (starR + 34),
|
||||
};
|
||||
}
|
||||
labels[i].x = Math.max(xMin, Math.min(xMax, labels[i].x));
|
||||
labels[i].y = Math.max(yMin, Math.min(yMax, labels[i].y));
|
||||
const gap = dist(labels[i], star);
|
||||
if (gap < starR + 16) {
|
||||
const ang = Math.atan2(labels[i].y - star.y, labels[i].x - star.x) || 0;
|
||||
labels[i].x = star.x + Math.cos(ang) * (starR + 18);
|
||||
labels[i].y = Math.max(
|
||||
yMin,
|
||||
Math.min(yMax, star.y + Math.sin(ang) * (starR + 18)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (let iter = 0; iter < 24; iter++) {
|
||||
for (let i = 0; i < labels.length; i++) {
|
||||
for (let j = i + 1; j < labels.length; j++) {
|
||||
const wi = labelWidth(names[i]);
|
||||
const wj = labelWidth(names[j]);
|
||||
const dx = labels[j].x - labels[i].x;
|
||||
const dy = labels[j].y - labels[i].y;
|
||||
const needX = (wi + wj) / 2 + 8;
|
||||
const needY = LABEL_H + 6;
|
||||
if (Math.abs(dx) < needX && Math.abs(dy) < needY) {
|
||||
const push = (needX - Math.abs(dx)) * 0.55 + 1;
|
||||
const dir = dx === 0 ? (i % 2 === 0 ? -1 : 1) : Math.sign(dx);
|
||||
labels[i].x -= dir * push;
|
||||
labels[j].x += dir * push;
|
||||
}
|
||||
}
|
||||
labels[i].x = Math.max(xMin, Math.min(xMax, labels[i].x));
|
||||
labels[i].y = Math.max(yMin, Math.min(yMax, labels[i].y));
|
||||
}
|
||||
}
|
||||
|
||||
return labels;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,11 +43,12 @@ export function positionOnEllipse(angle: number, phys: OrbitPhysics): Pose3 {
|
||||
const x = lx * Math.cos(node) - yInc * Math.sin(node);
|
||||
const y = lx * Math.sin(node) + yInc * Math.cos(node);
|
||||
const depth = zRaw / Math.max(phys.rx, 1);
|
||||
const facing = (depth + 1) / 2;
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
z: depth,
|
||||
scale: 0.7 + (depth + 1) * 0.3,
|
||||
scale: 0.38 + facing * 1.05,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -160,11 +161,11 @@ export function flowMoonOffsets(
|
||||
spread = 30,
|
||||
): Pose3[] {
|
||||
const out: Pose3[] = [];
|
||||
const inc = 0.85;
|
||||
const inc = 0.55;
|
||||
for (let mi = 0; mi < count; mi++) {
|
||||
const ang =
|
||||
(mi / Math.max(count, 1)) * Math.PI * 2 + time * (1.05 + mi * 0.08);
|
||||
const rad = spread * (0.82 + (mi % 3) * 0.1);
|
||||
const rad = Math.max(spread, 44) * (1 + mi * 0.05);
|
||||
const lx = Math.cos(ang) * rad;
|
||||
const ly = Math.sin(ang) * rad;
|
||||
const y = ly * Math.cos(inc);
|
||||
@@ -191,16 +192,13 @@ export function moonPositions(
|
||||
const outward = Math.atan2(cy, cx);
|
||||
for (let mi = 0; mi < count; mi++) {
|
||||
const slice = (mi / Math.max(count, 1)) * Math.PI * 2;
|
||||
const span = Math.PI * 0.7;
|
||||
const fan =
|
||||
count <= 1
|
||||
? 0
|
||||
: (mi - (count - 1) / 2) * (flowing ? 0.55 : 0.42);
|
||||
const angle = flowing
|
||||
? slice + time * (0.85 + mi * 0.08)
|
||||
: outward + fan;
|
||||
count <= 1 ? 0 : (mi / Math.max(count - 1, 1) - 0.5) * span;
|
||||
const angle = flowing ? slice + time * (0.85 + mi * 0.08) : outward + fan;
|
||||
const dist = flowing
|
||||
? baseSpread * (0.72 + (mi % 3) * 0.08)
|
||||
: baseSpread + 8 + mi * 6;
|
||||
? Math.max(baseSpread, 44)
|
||||
: 48 + mi * 8;
|
||||
out.push({
|
||||
angle,
|
||||
x: cx + Math.cos(angle) * dist,
|
||||
@@ -210,27 +208,48 @@ export function moonPositions(
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Push overlapping moons apart in lock mode (all stars). */
|
||||
/**
|
||||
* Keep lock moons on the outward side of their star, outside the corona.
|
||||
* A moon that would cross a neighbor star is dropped (null).
|
||||
*/
|
||||
export function relaxLockedMoons(
|
||||
stars: Vec2[],
|
||||
moonsByStar: Vec2[][],
|
||||
): Vec2[][] {
|
||||
const flat: { p: Vec2; star: number; moon: number }[] = [];
|
||||
): (Vec2 | null)[][] {
|
||||
const flat: { p: Vec2; star: number; moon: number; drop: boolean }[] = [];
|
||||
for (let si = 0; si < moonsByStar.length; si++) {
|
||||
for (let mi = 0; mi < moonsByStar[si].length; mi++) {
|
||||
flat.push({ p: { ...moonsByStar[si][mi] }, star: si, moon: mi });
|
||||
flat.push({ p: { ...moonsByStar[si][mi] }, star: si, moon: mi, drop: false });
|
||||
}
|
||||
}
|
||||
|
||||
const minMoon = 22;
|
||||
const minStarMoon = 28;
|
||||
const minMoon = 20;
|
||||
const minStarMoon = 46;
|
||||
|
||||
for (let iter = 0; iter < 40; iter++) {
|
||||
for (let iter = 0; iter < 28; iter++) {
|
||||
for (let i = 0; i < flat.length; i++) {
|
||||
const s = stars[flat[i].star];
|
||||
const outward = Math.atan2(s.y, s.x);
|
||||
const ang = Math.atan2(flat[i].p.y - s.y, flat[i].p.x - s.x);
|
||||
let delta = ang - outward;
|
||||
while (delta > Math.PI) delta -= Math.PI * 2;
|
||||
while (delta < -Math.PI) delta += Math.PI * 2;
|
||||
if (Math.abs(delta) > Math.PI * 0.42) {
|
||||
const clamped = outward + Math.sign(delta || 1) * Math.PI * 0.42;
|
||||
const ds = Math.max(dist(flat[i].p, s), minStarMoon);
|
||||
flat[i].p.x = s.x + Math.cos(clamped) * ds;
|
||||
flat[i].p.y = s.y + Math.sin(clamped) * ds;
|
||||
}
|
||||
const ds = dist(flat[i].p, s);
|
||||
if (ds < minStarMoon) {
|
||||
const a = Math.atan2(flat[i].p.y - s.y, flat[i].p.x - s.x);
|
||||
flat[i].p.x = s.x + Math.cos(a) * minStarMoon;
|
||||
flat[i].p.y = s.y + Math.sin(a) * minStarMoon;
|
||||
}
|
||||
for (let j = i + 1; j < flat.length; j++) {
|
||||
const d = dist(flat[i].p, flat[j].p);
|
||||
if (d < minMoon && d > 0.001) {
|
||||
const push = (minMoon - d) * 0.55;
|
||||
const push = (minMoon - d) * 0.5;
|
||||
const ux = (flat[i].p.x - flat[j].p.x) / d;
|
||||
const uy = (flat[i].p.y - flat[j].p.y) / d;
|
||||
flat[i].p.x += ux * push;
|
||||
@@ -239,19 +258,33 @@ export function relaxLockedMoons(
|
||||
flat[j].p.y -= uy * push;
|
||||
}
|
||||
}
|
||||
const s = stars[flat[i].star];
|
||||
const ds = dist(flat[i].p, s);
|
||||
if (ds < minStarMoon && ds > 0.001) {
|
||||
const ang = Math.atan2(flat[i].p.y - s.y, flat[i].p.x - s.x);
|
||||
flat[i].p.x = s.x + Math.cos(ang) * minStarMoon;
|
||||
flat[i].p.y = s.y + Math.sin(ang) * minStarMoon;
|
||||
}
|
||||
}
|
||||
|
||||
for (const moon of flat) {
|
||||
const parent = stars[moon.star];
|
||||
for (let si = 0; si < stars.length; si++) {
|
||||
if (si === moon.star) continue;
|
||||
if (dist(moon.p, stars[si]) < 40) {
|
||||
moon.drop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dist(moon.p, parent) < 40) moon.drop = true;
|
||||
if (moon.p.y > 128 || moon.p.y < -185) {
|
||||
const side = moon.p.x >= parent.x ? 1 : -1;
|
||||
const ds = Math.max(dist(moon.p, parent), 46);
|
||||
moon.p.x = parent.x + side * ds;
|
||||
moon.p.y = Math.max(-175, Math.min(120, parent.y));
|
||||
for (let si = 0; si < stars.length; si++) {
|
||||
if (si !== moon.star && dist(moon.p, stars[si]) < 40) moon.drop = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const out = moonsByStar.map((row) => row.map(() => ({ x: 0, y: 0 })));
|
||||
const out: (Vec2 | null)[][] = moonsByStar.map((row) => row.map(() => null));
|
||||
for (const f of flat) {
|
||||
out[f.star][f.moon] = f.p;
|
||||
out[f.star][f.moon] = f.drop ? null : f.p;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user