feat(stammbaum): round pan/zoom URL params for readable shared links (#692)
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 2m36s
CI / OCR Service Tests (pull_request) Successful in 22s
CI / Backend Unit Tests (pull_request) Successful in 3m30s
CI / fail2ban Regex (pull_request) Successful in 45s
CI / Semgrep Security Scan (pull_request) Successful in 22s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m6s
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 2m36s
CI / OCR Service Tests (pull_request) Successful in 22s
CI / Backend Unit Tests (pull_request) Successful in 3m30s
CI / fail2ban Regex (pull_request) Successful in 45s
CI / Semgrep Security Scan (pull_request) Successful in 22s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m6s
Pan rounded to 2 decimals, zoom to 3, so ?cx/?cy/?z no longer carry float noise like cx=457.8300882631206. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -80,6 +80,14 @@ describe('serializePanZoomParams', () => {
|
|||||||
const state = { x: 87.5, y: -12.25, z: 2.4 };
|
const state = { x: 87.5, y: -12.25, z: 2.4 };
|
||||||
expect(parsePanZoomParams(serializePanZoomParams(state))).toEqual(state);
|
expect(parsePanZoomParams(serializePanZoomParams(state))).toEqual(state);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('rounds noisy floats so shared URLs stay readable', () => {
|
||||||
|
expect(serializePanZoomParams({ x: 457.8300882631206, y: 0, z: 1.2000000000000002 })).toEqual({
|
||||||
|
cx: '457.83',
|
||||||
|
cy: '0',
|
||||||
|
z: '1.2'
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('screenDeltaToSvg', () => {
|
describe('screenDeltaToSvg', () => {
|
||||||
|
|||||||
@@ -71,9 +71,18 @@ export function parsePanZoomParams(raw: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Serialise a view state into URL query params (the inverse of {@link parsePanZoomParams}). */
|
/** Format a number with at most `dp` decimals, dropping trailing zeros. */
|
||||||
|
function round(n: number, dp: number): string {
|
||||||
|
return String(Number(n.toFixed(dp)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialise a view state into URL query params (the inverse of
|
||||||
|
* {@link parsePanZoomParams}). Pan is rounded to 2 decimals and zoom to 3 so
|
||||||
|
* shared links stay readable (no `cx=457.8300882631206` float noise).
|
||||||
|
*/
|
||||||
export function serializePanZoomParams(state: PanZoomState): { cx: string; cy: string; z: string } {
|
export function serializePanZoomParams(state: PanZoomState): { cx: string; cy: string; z: string } {
|
||||||
return { cx: String(state.x), cy: String(state.y), z: String(state.z) };
|
return { cx: round(state.x, 2), cy: round(state.y, 2), z: round(state.z, 3) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user