Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(pdf): draw the cover route of a long road trip without spreading every point into one call

Maurice8f5324c90166
diff --git a/client/src/components/PDF/tripPdfOverview.test.ts b/client/src/components/PDF/tripPdfOverview.test.ts
index ba2c84df9..b5fb082b3 100644
--- a/client/src/components/PDF/tripPdfOverview.test.ts
+++ b/client/src/components/PDF/tripPdfOverview.test.ts
@@ -129,6 +129,17 @@ describe('the cover route and day band', () => {
const d = /<path d="([^"]+)" stroke=/.exec(svg)?.[1] ?? '';
expect(d.split('L').length).toBeLessThanOrEqual(1700);
});
+
+ it('FE-PDFOVERVIEW-009: a trip of more points than a call takes arguments still draws its card', () => {
+ const days = Array.from({ length: 8 }, (_, day) => ({
+ colour: '#ff0000',
+ lines: [Array.from({ length: 100000 }, (_, i) => [45 + day + i / 100000, 7 + i / 50000] as [number, number])],
+ }));
+ const svg = coverRouteSvg(days);
+ expect(svg).toContain('<svg class="cover-route-svg"');
+ const numbers = (svg.match(/-?\d+\.\d/g) ?? []).map(Number);
+ for (const n of numbers) expect(n).toBeGreaterThanOrEqual(0);
+ });
});
describe('glanceHtml', () => {
diff --git a/client/src/components/PDF/tripPdfOverview.ts b/client/src/components/PDF/tripPdfOverview.ts
index 57ed8a29f..9af68a14f 100644
--- a/client/src/components/PDF/tripPdfOverview.ts
+++ b/client/src/components/PDF/tripPdfOverview.ts
@@ -75,15 +75,22 @@ export function coverRouteSvg(days: readonly CoverRouteDay[]): string {
const lines = days.flatMap((d) => d.lines.filter((l) => l.length > 1).map((l) => ({ colour: d.colour, points: l })));
const points = lines.flatMap((l) => l.points);
if (!lines.length) return '';
- const lats = points.map((p) => p[0]);
- const midLat = (Math.min(...lats) + Math.max(...lats)) / 2;
- const k = Math.cos((midLat * Math.PI) / 180);
- const xs = points.map((p) => p[1] * k);
- const ys = points.map((p) => -p[0]);
- const minX = Math.min(...xs);
- const minY = Math.min(...ys);
- const w = Math.max(...xs) - minX;
- const h = Math.max(...ys) - minY;
+ // A loop, not Math.min(...points): a long road trip passes the argument limit of a call.
+ let minLat = Infinity;
+ let maxLat = -Infinity;
+ let minLng = Infinity;
+ let maxLng = -Infinity;
+ for (const [lat, lng] of points) {
+ minLat = Math.min(minLat, lat);
+ maxLat = Math.max(maxLat, lat);
+ minLng = Math.min(minLng, lng);
+ maxLng = Math.max(maxLng, lng);
+ }
+ const k = Math.cos((((minLat + maxLat) / 2) * Math.PI) / 180);
+ const minX = minLng * k;
+ const minY = -maxLat;
+ const w = (maxLng - minLng) * k;
+ const h = maxLat - minLat;
const scale = Math.min(
w > 0 ? (ROUTE_W - 2 * ROUTE_PAD) / w : Infinity,
h > 0 ? (ROUTE_H - 2 * ROUTE_PAD) / h : Infinity