cursedbelt 5.92.3 โ 5.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react/components/ComboboxField.d.ts +10 -0
- package/dist/react/components/ComboboxField.d.ts.map +1 -1
- package/dist/react/components/ComboboxField.js +4 -4
- package/dist/react/components/ComboboxField.js.map +1 -1
- package/dist/react/components/CommentThread.d.ts +9 -3
- package/dist/react/components/CommentThread.d.ts.map +1 -1
- package/dist/react/components/CommentThread.js +25 -11
- package/dist/react/components/CommentThread.js.map +1 -1
- package/dist/react/components/VoiceNote.d.ts +20 -0
- package/dist/react/components/VoiceNote.d.ts.map +1 -0
- package/dist/react/components/VoiceNote.js +54 -0
- package/dist/react/components/VoiceNote.js.map +1 -0
- package/dist/react/components/VoiceRecorder.d.ts +35 -0
- package/dist/react/components/VoiceRecorder.d.ts.map +1 -0
- package/dist/react/components/VoiceRecorder.js +155 -0
- package/dist/react/components/VoiceRecorder.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/map-frame/MapFrame.d.ts +219 -0
- package/dist/react/map-frame/MapFrame.d.ts.map +1 -0
- package/dist/react/map-frame/MapFrame.js +726 -0
- package/dist/react/map-frame/MapFrame.js.map +1 -0
- package/dist/react/map-frame/geo.d.ts +210 -0
- package/dist/react/map-frame/geo.d.ts.map +1 -0
- package/dist/react/map-frame/geo.js +345 -0
- package/dist/react/map-frame/geo.js.map +1 -0
- package/dist/react/map-frame/index.d.ts +5 -0
- package/dist/react/map-frame/index.d.ts.map +1 -0
- package/dist/react/map-frame/index.js +3 -0
- package/dist/react/map-frame/index.js.map +1 -0
- package/dist/styles-areas/canvas-hud.css +5 -5
- package/dist/styles-areas/workbench.css +17 -17
- package/package.json +13 -1
- package/scripts/guardrails-baseline.json +1 -1
- package/scripts/styleAreas.ts +1 -1
- package/src/react/components/ComboboxField.spec.tsx +39 -0
- package/src/react/components/ComboboxField.tsx +20 -4
- package/src/react/components/CommentThread.spec.tsx +25 -0
- package/src/react/components/CommentThread.tsx +60 -10
- package/src/react/components/VoiceNote.tsx +92 -0
- package/src/react/components/VoiceRecorder.spec.tsx +116 -0
- package/src/react/components/VoiceRecorder.tsx +224 -0
- package/src/react/index.ts +9 -0
- package/src/react/map-frame/MapFrame.spec.ts +168 -0
- package/src/react/map-frame/MapFrame.tsx +954 -0
- package/src/react/map-frame/geo.spec.ts +393 -0
- package/src/react/map-frame/geo.ts +421 -0
- package/src/react/map-frame/index.ts +34 -0
- package/src/react/media/HoverScrubVideoThumb.spec.tsx +4 -0
- package/src/styles-areas/canvas-hud.css +5 -5
- package/src/styles-areas/workbench.css +17 -17
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The map's arithmetic (moved with the code from `FORGE/apps/family/src/shared/geo.test.ts`, forge task 3700).
|
|
3
|
+
*
|
|
4
|
+
* ๐ด This file exists because **a pin in the wrong place still looks like a
|
|
5
|
+
* pin.** A projection that is subtly wrong produces a beautiful, confident,
|
|
6
|
+
* incorrect map, and the error grows with latitude. So the geometry is pinned
|
|
7
|
+
* against values that can be checked by hand rather than against whatever the
|
|
8
|
+
* implementation currently returns.
|
|
9
|
+
*/
|
|
10
|
+
import { describe, expect, test } from "bun:test";
|
|
11
|
+
import {
|
|
12
|
+
boundsOf,
|
|
13
|
+
centerOf,
|
|
14
|
+
type Clusterable,
|
|
15
|
+
clusterByScreen,
|
|
16
|
+
formatDistance,
|
|
17
|
+
type LatLng,
|
|
18
|
+
fromWorldFraction,
|
|
19
|
+
haversineKm,
|
|
20
|
+
MERCATOR_MAX_LAT,
|
|
21
|
+
project,
|
|
22
|
+
scaleBar,
|
|
23
|
+
snapZoom,
|
|
24
|
+
unproject,
|
|
25
|
+
type Viewport,
|
|
26
|
+
worldFraction,
|
|
27
|
+
zoomAnchoredAt,
|
|
28
|
+
zoomToFit,
|
|
29
|
+
} from "./geo.js";
|
|
30
|
+
|
|
31
|
+
const VIEW: Viewport = { center: { lat: 0, lng: 0 }, zoom: 2, width: 640, height: 400 };
|
|
32
|
+
|
|
33
|
+
describe("the projection โ Google's own Web Mercator", () => {
|
|
34
|
+
test("the origin is the center of the world square", () => {
|
|
35
|
+
const at = worldFraction({ lat: 0, lng: 0 });
|
|
36
|
+
expect(at.x).toBeCloseTo(0.5, 10);
|
|
37
|
+
expect(at.y).toBeCloseTo(0.5, 10);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("the antimeridian and the poles land on the edges", () => {
|
|
41
|
+
expect(worldFraction({ lat: 0, lng: -180 }).x).toBeCloseTo(0, 10);
|
|
42
|
+
expect(worldFraction({ lat: 0, lng: 180 }).x).toBeCloseTo(1, 10);
|
|
43
|
+
// Clamped at Mercator's limit rather than running to infinity.
|
|
44
|
+
expect(worldFraction({ lat: 89.9, lng: 0 }).y).toBeCloseTo(
|
|
45
|
+
worldFraction({ lat: MERCATOR_MAX_LAT, lng: 0 }).y,
|
|
46
|
+
10,
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("north is a SMALLER y โ screen coordinates grow downward", () => {
|
|
51
|
+
expect(worldFraction({ lat: 60, lng: 0 }).y).toBeLessThan(worldFraction({ lat: 10, lng: 0 }).y);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("๐ด a known point lands where Google puts it", () => {
|
|
55
|
+
/*
|
|
56
|
+
* London, 51.5072ยฐN 0.1276ยฐW. Derived by hand so this stays checkable
|
|
57
|
+
* rather than being whatever the implementation happened to return:
|
|
58
|
+
*
|
|
59
|
+
* x = (-0.1276 + 180) / 360 = 0.4996456
|
|
60
|
+
* sin(51.5072ยฐ) = 0.7827170
|
|
61
|
+
* ln((1 + sin) / (1 - sin)) = ln(8.204551) = 2.1046905
|
|
62
|
+
* y = 0.5 - 2.1046905 / (4ฯ) = 0.3325264
|
|
63
|
+
*
|
|
64
|
+
* If either drifts, every pin in the app drifts with it.
|
|
65
|
+
*/
|
|
66
|
+
const london = worldFraction({ lat: 51.5072, lng: -0.1276 });
|
|
67
|
+
expect(london.x).toBeCloseTo(0.4996456, 6);
|
|
68
|
+
expect(london.y).toBeCloseTo(0.332526, 5);
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
* And the same value from the OTHER closed form of Mercator โ
|
|
72
|
+
* y = 0.5 - ln(tan(ฯ/4 + ฯ/2)) / 2ฯ
|
|
73
|
+
* which is mathematically identical to the implementation's
|
|
74
|
+
* y = 0.5 - ln((1 + sin ฯ) / (1 - sin ฯ)) / 4ฯ
|
|
75
|
+
* but shares none of its arithmetic. A wrong implementation cannot satisfy
|
|
76
|
+
* both, which is what makes this a check rather than a copy of the output.
|
|
77
|
+
*/
|
|
78
|
+
for (const lat of [-33.9249, 0, 44.6488, 51.5072, 59.9139]) {
|
|
79
|
+
const viaTan = 0.5 - Math.log(Math.tan(Math.PI / 4 + (lat * Math.PI) / 360)) / (2 * Math.PI);
|
|
80
|
+
expect(worldFraction({ lat, lng: 0 }).y).toBeCloseTo(viaTan, 12);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("project and unproject are inverses at every zoom", () => {
|
|
85
|
+
for (const zoom of [1, 4, 9, 14]) {
|
|
86
|
+
const view: Viewport = { ...VIEW, zoom };
|
|
87
|
+
for (const point of [
|
|
88
|
+
{ lat: 51.5072, lng: -0.1276 },
|
|
89
|
+
{ lat: -33.9249, lng: 18.4241 },
|
|
90
|
+
{ lat: 56.8433, lng: 60.6454 },
|
|
91
|
+
]) {
|
|
92
|
+
const back = unproject(project(point, view), view);
|
|
93
|
+
expect(back.lat).toBeCloseTo(point.lat, 6);
|
|
94
|
+
expect(back.lng).toBeCloseTo(point.lng, 6);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("the center of the viewport projects to the center of the image", () => {
|
|
100
|
+
const view: Viewport = { center: { lat: 49.8, lng: 8.65 }, zoom: 7, width: 640, height: 400 };
|
|
101
|
+
const at = project(view.center, view);
|
|
102
|
+
expect(at.x).toBeCloseTo(320, 6);
|
|
103
|
+
expect(at.y).toBeCloseTo(200, 6);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("world fractions round-trip", () => {
|
|
107
|
+
const back = fromWorldFraction(worldFraction({ lat: 44.6488, lng: -63.5752 }));
|
|
108
|
+
expect(back.lat).toBeCloseTo(44.6488, 8);
|
|
109
|
+
expect(back.lng).toBeCloseTo(-63.5752, 8);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("zoomToFit โ everything on screen, at a zoom Google actually tiles", () => {
|
|
114
|
+
const size = { width: 640, height: 400 };
|
|
115
|
+
|
|
116
|
+
test("an integer, always โ every distinct zoom is a billable render", () => {
|
|
117
|
+
const zoom = zoomToFit({ south: 40, west: -75, north: 55, east: 10 }, size);
|
|
118
|
+
expect(Number.isInteger(zoom)).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("a tighter box gets a closer zoom", () => {
|
|
122
|
+
const wide = zoomToFit({ south: -33, west: -75, north: 60, east: 60 }, size);
|
|
123
|
+
const tight = zoomToFit({ south: 51.4, west: -0.3, north: 51.6, east: 0.1 }, size);
|
|
124
|
+
expect(tight).toBeGreaterThan(wide);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("a single point does not divide by zero", () => {
|
|
128
|
+
const zoom = zoomToFit({ south: 51.5, west: -0.1, north: 51.5, east: -0.1 }, size);
|
|
129
|
+
expect(Number.isFinite(zoom)).toBe(true);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("the result actually fits, with its padding", () => {
|
|
133
|
+
const bounds = { south: 38.1, west: -63.6, north: 60.4, east: 60.6 };
|
|
134
|
+
const zoom = zoomToFit(bounds, size, { padding: 48 });
|
|
135
|
+
const view: Viewport = { center: centerOf(bounds), zoom, ...size };
|
|
136
|
+
for (const corner of [
|
|
137
|
+
{ lat: bounds.south, lng: bounds.west },
|
|
138
|
+
{ lat: bounds.north, lng: bounds.east },
|
|
139
|
+
]) {
|
|
140
|
+
const at = project(corner, view);
|
|
141
|
+
expect(at.x).toBeGreaterThanOrEqual(0);
|
|
142
|
+
expect(at.x).toBeLessThanOrEqual(size.width);
|
|
143
|
+
expect(at.y).toBeGreaterThanOrEqual(0);
|
|
144
|
+
expect(at.y).toBeLessThanOrEqual(size.height);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("snapZoom stays inside the range the static API serves", () => {
|
|
149
|
+
expect(snapZoom(0.2)).toBe(1);
|
|
150
|
+
expect(snapZoom(99)).toBe(16);
|
|
151
|
+
expect(snapZoom(7.6)).toBe(8);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("boundsOf", () => {
|
|
156
|
+
test("no points is null, not an empty box at the origin", () => {
|
|
157
|
+
// A zero box at 0,0 is a real place in the Gulf of Guinea; orch's leave-by
|
|
158
|
+
// shipped exactly that bug once. Null forces the caller to decide.
|
|
159
|
+
expect(boundsOf([])).toBeNull();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("a box contains everything it was given", () => {
|
|
163
|
+
const bounds = boundsOf([
|
|
164
|
+
{ lat: 51.5, lng: -0.1 },
|
|
165
|
+
{ lat: -33.9, lng: 18.4 },
|
|
166
|
+
{ lat: 56.8, lng: 60.6 },
|
|
167
|
+
]);
|
|
168
|
+
expect(bounds).toEqual({ south: -33.9, west: -0.1, north: 56.8, east: 60.6 });
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe("haversine โ straight-line, never travel time", () => {
|
|
173
|
+
test("๐ด known distances, to within a kilometer", () => {
|
|
174
|
+
// London โ Paris is ~344 km; London โ New York ~5570 km. Both hand-checkable.
|
|
175
|
+
expect(haversineKm({ lat: 51.5072, lng: -0.1276 }, { lat: 48.8566, lng: 2.3522 })).toBeCloseTo(
|
|
176
|
+
343.6,
|
|
177
|
+
0,
|
|
178
|
+
);
|
|
179
|
+
expect(haversineKm({ lat: 51.5072, lng: -0.1276 }, { lat: 40.7128, lng: -74.006 })).toBeCloseTo(
|
|
180
|
+
5570.2,
|
|
181
|
+
0,
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("a point is zero from itself", () => {
|
|
186
|
+
expect(haversineKm({ lat: 30.2672, lng: -97.7431 }, { lat: 30.2672, lng: -97.7431 })).toBe(0);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("it is symmetric", () => {
|
|
190
|
+
const a = { lat: 6.5244, lng: 3.3792 };
|
|
191
|
+
const b = { lat: 55.9533, lng: -3.1883 };
|
|
192
|
+
expect(haversineKm(a, b)).toBeCloseTo(haversineKm(b, a), 9);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("formatDistance says both units, because the family spans two countries", () => {
|
|
196
|
+
expect(formatDistance(1609)).toContain("mi");
|
|
197
|
+
expect(formatDistance(1609)).toContain("km");
|
|
198
|
+
expect(formatDistance(0.4)).toBe("less than a mile apart");
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The distance key. ๐ด Checked against an INDEPENDENTLY derived ground
|
|
204
|
+
* resolution rather than against whatever the function returns โ a scale bar
|
|
205
|
+
* that is wrong looks exactly like one that is right, which is the same reason
|
|
206
|
+
* the projection above is pinned to a closed form.
|
|
207
|
+
*/
|
|
208
|
+
describe("scaleBar โ what a mile looks like", () => {
|
|
209
|
+
const frame = (lat: number, zoom: number) => ({
|
|
210
|
+
center: { lat, lng: 0 },
|
|
211
|
+
zoom,
|
|
212
|
+
width: 640,
|
|
213
|
+
height: 400,
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("the bar is exactly as long as the distance it claims", () => {
|
|
217
|
+
const view = frame(30.27, 8);
|
|
218
|
+
const bar = scaleBar(view);
|
|
219
|
+
// Ground resolution, derived here rather than imported: the equator is
|
|
220
|
+
// 40,075,016.686 m across 256 px at zoom 0, narrowed by cos(latitude).
|
|
221
|
+
const metresPerUnit = (40075016.686 * Math.cos((30.27 * Math.PI) / 180)) / (256 * 2 ** 8);
|
|
222
|
+
const claimedMiles = Number(bar.label.split(" mi")[0]);
|
|
223
|
+
expect((bar.widthUnits * metresPerUnit) / 1609.344).toBeCloseTo(claimedMiles, 6);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("it fits the space it is given, and takes as much of it as the series allows", () => {
|
|
227
|
+
const bar = scaleBar(frame(30.27, 8), 110);
|
|
228
|
+
expect(bar.widthUnits).toBeLessThanOrEqual(110);
|
|
229
|
+
// The NEXT step up of the 1/2/5 series must not have fitted, or the bar is
|
|
230
|
+
// needlessly short and reads as a smaller map than it is.
|
|
231
|
+
expect(bar.widthUnits).toBeGreaterThan(110 / 5);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test("the number is one a person would say out loud", () => {
|
|
235
|
+
for (const zoom of [1, 3, 5, 8, 11, 14, 16]) {
|
|
236
|
+
const miles = Number(scaleBar(frame(30.27, zoom)).label.split(" mi")[0].replace(/,/g, ""));
|
|
237
|
+
const magnitude = 10 ** Math.floor(Math.log10(miles));
|
|
238
|
+
expect([1, 2, 5]).toContain(Math.round(miles / magnitude));
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("both units, because the family spans two countries", () => {
|
|
243
|
+
const label = scaleBar(frame(52.58, 10)).label;
|
|
244
|
+
expect(label).toContain(" mi ยท ");
|
|
245
|
+
expect(label).toContain(" km");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("a pole cannot make the bar infinite", () => {
|
|
249
|
+
// cos(90ยฐ) is zero, so an unclamped ground resolution divides by nothing and
|
|
250
|
+
// renders a bar the width of the universe over a map of the Arctic.
|
|
251
|
+
const bar = scaleBar(frame(90, 6));
|
|
252
|
+
expect(Number.isFinite(bar.widthUnits)).toBe(true);
|
|
253
|
+
expect(bar.widthUnits).toBeGreaterThan(0);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("a frame with no room draws nothing rather than a fraction of a mile", () => {
|
|
257
|
+
expect(scaleBar(frame(30.27, 1), 0).widthUnits).toBe(0);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe("zoomAnchoredAt โ the ground under the cursor stays under the cursor", () => {
|
|
262
|
+
const frame = (center: LatLng, zoom: number): Viewport => ({
|
|
263
|
+
center,
|
|
264
|
+
zoom,
|
|
265
|
+
width: 640,
|
|
266
|
+
height: 400,
|
|
267
|
+
});
|
|
268
|
+
const LONDON: LatLng = { lat: 51.5074, lng: -0.1278 };
|
|
269
|
+
|
|
270
|
+
test("a wheel over a corner holds THAT corner still, not the middle", () => {
|
|
271
|
+
// ๐ด The claim the whole gesture rests on, and the one that is silently
|
|
272
|
+
// wrong if the math anchors on the center: the error is exactly zero in the
|
|
273
|
+
// middle of the frame, which is where a developer tests it by hand.
|
|
274
|
+
const before = frame(LONDON, 6);
|
|
275
|
+
const pixel = { x: 561, y: 78 };
|
|
276
|
+
const ground = unproject(pixel, before);
|
|
277
|
+
const after = frame(zoomAnchoredAt(before, pixel, 8), 8);
|
|
278
|
+
const landed = project(ground, after);
|
|
279
|
+
expect(landed.x).toBeCloseTo(pixel.x, 6);
|
|
280
|
+
expect(landed.y).toBeCloseTo(pixel.y, 6);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test("it works at a FRACTIONAL zoom โ a live gesture is never on a tile level", () => {
|
|
284
|
+
const before = frame(LONDON, 6);
|
|
285
|
+
const pixel = { x: 120, y: 330 };
|
|
286
|
+
const ground = unproject(pixel, before);
|
|
287
|
+
const after = frame(zoomAnchoredAt(before, pixel, 6.37), 6.37);
|
|
288
|
+
const landed = project(ground, after);
|
|
289
|
+
expect(landed.x).toBeCloseTo(pixel.x, 6);
|
|
290
|
+
expect(landed.y).toBeCloseTo(pixel.y, 6);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test("anchoring on the exact center leaves the center alone", () => {
|
|
294
|
+
const before = frame(LONDON, 6);
|
|
295
|
+
const next = zoomAnchoredAt(before, { x: 320, y: 200 }, 9);
|
|
296
|
+
expect(next.lat).toBeCloseTo(LONDON.lat, 9);
|
|
297
|
+
expect(next.lng).toBeCloseTo(LONDON.lng, 9);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test("`landsAt` carries the ground to a NEW pixel โ a pinch that also slides", () => {
|
|
301
|
+
// Two fingers spreading while the hand drifts is one gesture, not two. The
|
|
302
|
+
// ground under where the pinch started has to end up under where the fingers
|
|
303
|
+
// are NOW, or the map lurches away as it zooms.
|
|
304
|
+
const before = frame(LONDON, 6);
|
|
305
|
+
const grabbed = { x: 200, y: 150 };
|
|
306
|
+
const nowAt = { x: 430, y: 260 };
|
|
307
|
+
const ground = unproject(grabbed, before);
|
|
308
|
+
const after = frame(zoomAnchoredAt(before, grabbed, 7.5, nowAt), 7.5);
|
|
309
|
+
const landed = project(ground, after);
|
|
310
|
+
expect(landed.x).toBeCloseTo(nowAt.x, 6);
|
|
311
|
+
expect(landed.y).toBeCloseTo(nowAt.y, 6);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
describe("clusterByScreen โ the answer to forty pins on one degree", () => {
|
|
316
|
+
const frame = (zoom: number): Viewport => ({
|
|
317
|
+
center: { lat: 51, lng: 0 },
|
|
318
|
+
zoom,
|
|
319
|
+
width: 640,
|
|
320
|
+
height: 400,
|
|
321
|
+
});
|
|
322
|
+
const place = (id: string, lat: number, lng: number, weight = 1): Clusterable => ({
|
|
323
|
+
id,
|
|
324
|
+
point: { lat, lng },
|
|
325
|
+
weight,
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test("nothing to cluster is an empty answer, not a throw", () => {
|
|
329
|
+
expect(clusterByScreen([], frame(6), 22)).toEqual([]);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test("places far apart on screen each keep their own token", () => {
|
|
333
|
+
const out = clusterByScreen([place("a", 51, 0), place("b", 41, 12)], frame(6), 22);
|
|
334
|
+
expect(out).toHaveLength(2);
|
|
335
|
+
expect(out.every((token) => token.members.length === 1)).toBe(true);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test("places that would overlap become ONE token carrying the sum of the people", () => {
|
|
339
|
+
// The number in the token is people, not pins โ "3" over Windsor when three
|
|
340
|
+
// PLACES are stacked there but eighteen relatives are in them would be the
|
|
341
|
+
// wrong number to show, and the wrong number to reason about.
|
|
342
|
+
const out = clusterByScreen(
|
|
343
|
+
[place("windsor", 51.48, -0.61, 18), place("eton", 51.49, -0.61, 4)],
|
|
344
|
+
frame(6),
|
|
345
|
+
22,
|
|
346
|
+
);
|
|
347
|
+
expect(out).toHaveLength(1);
|
|
348
|
+
expect(out[0]?.weight).toBe(22);
|
|
349
|
+
expect(out[0]?.members).toHaveLength(2);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test("๐ด the HEAVIEST place seeds the token, whatever order the pins arrive in", () => {
|
|
353
|
+
// Determinism is not tidiness here: the atlas refetches every 1.5 s while
|
|
354
|
+
// places resolve, and a token whose identity flipped between renders would
|
|
355
|
+
// drop the reader's hover and re-key the React tree mid-gesture.
|
|
356
|
+
const near = [place("hamlet", 51.49, -0.61, 1), place("windsor", 51.48, -0.61, 18)];
|
|
357
|
+
const forwards = clusterByScreen(near, frame(6), 22);
|
|
358
|
+
const backwards = clusterByScreen([...near].reverse(), frame(6), 22);
|
|
359
|
+
expect(forwards[0]?.id).toBe("windsor");
|
|
360
|
+
expect(backwards[0]?.id).toBe("windsor");
|
|
361
|
+
expect(forwards[0]?.point).toEqual(backwards[0]?.point as never);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
test("zooming IN breaks a token apart โ the reader's own gesture is the control", () => {
|
|
365
|
+
const near = [place("a", 51.5, -0.1), place("b", 51.56, -0.1)];
|
|
366
|
+
expect(clusterByScreen(near, frame(6), 22)).toHaveLength(1);
|
|
367
|
+
expect(clusterByScreen(near, frame(11), 22)).toHaveLength(2);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test("a zero radius clusters nothing, so the layer can be turned off by arithmetic", () => {
|
|
371
|
+
const near = [place("a", 51.5, -0.1), place("b", 51.5001, -0.1001)];
|
|
372
|
+
expect(clusterByScreen(near, frame(6), 0)).toHaveLength(2);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
test("a lone place keeps its EXACT coordinate, never a rounded centroid", () => {
|
|
376
|
+
// A single-member token is still a pin, and a pin that has drifted off its
|
|
377
|
+
// own coastline is the class of bug this whole file exists to stop.
|
|
378
|
+
const out = clusterByScreen([place("darmstadt", 49.8728, 8.6512, 11)], frame(6), 22);
|
|
379
|
+
expect(out[0]?.point).toEqual({ lat: 49.8728, lng: 8.6512 });
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
test("the token sits BETWEEN its members, pulled toward the heavy one", () => {
|
|
383
|
+
const out = clusterByScreen(
|
|
384
|
+
[place("heavy", 51.0, 0.0, 20), place("light", 51.2, 0.0, 1)],
|
|
385
|
+
frame(6),
|
|
386
|
+
40,
|
|
387
|
+
);
|
|
388
|
+
const at = out[0]?.point.lat ?? 0;
|
|
389
|
+
expect(at).toBeGreaterThan(51.0);
|
|
390
|
+
expect(at).toBeLessThan(51.05);
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
|