test: curvature continuity and dual-size arc videos (t1138)
Replace the multi-segment C¹ joint checks with a single-polynomial suite: gradual curvature, no mid-arc straight cruise, vertical ends, corridors, arc-length speed, and fallSpeed via easing. Playwright records early/mid/late shots and webms at 1920×1080 and 1024×532.
@@ -160,47 +160,109 @@ describe('Smooth C1 arcs (t1134)', () =>
160
160
return Online.cellViewport(col, y, field);
161
161
}
162
162
163
it('is a C1 curve: tangents and speeds match at joints, no corners', () =>
163
it('is one continuous polynomial: C^∞, gradual curvature, no straight stretches (t1138)', () =>
164
164
{
165
const start = { x: 250, y: 700 };
166
const end = entry(3);
167
const curve = Online.makeAroundCurve(start, end, field, { clearance: 80 });
168
assert.ok(curve.segments && curve.segments.length >= 2, 'multi-segment around-field path');
169
const n = curve.segments.length;
170
for (let i = 1; i < n; i++)
165
const cases = [
166
{ name: 'incoming left-mini → col3', start: { x: 250, y: 700 }, end: entry(3) },
167
{ name: 'incoming far-left → col9', start: { x: 200, y: 800 }, end: entry(9) },
168
{ name: 'outgoing mid → right mini', start: entry(6), end: { x: field.right + 80, y: 700 } },
169
{ name: 'outgoing col0 → left mini', start: entry(0), end: { x: 200, y: 700 } },
170
{ name: 'incoming right-mini → col1', start: { x: field.right + 90, y: 720 }, end: entry(1) },
171
{ name: 'enemy→enemy behind (no field)', start: { x: 180, y: 750 }, end: { x: field.right + 90, y: 680 }, noField: true }
172
];
173
for (const c of cases)
171
174
{
172
const u = i / n;
173
const left = Online.curveDeriv(curve, u - 1e-6);
174
const right = Online.curveDeriv(curve, u + 1e-6);
175
const aL = Math.atan2(left.y, left.x);
176
const aR = Math.atan2(right.y, right.x);
177
let da = Math.abs(aR - aL);
178
if (da > Math.PI)
179
{ da = 2 * Math.PI - da; }
180
assert.ok(da < 0.02, 'joint ' + i + ' direction jump ' + da);
181
const sL = Math.hypot(left.x, left.y);
182
const sR = Math.hypot(right.x, right.y);
183
assert.ok(Math.abs(sL - sR) / Math.max(sL, 1) < 0.05,
184
'joint ' + i + ' speed jump ' + sL + ' vs ' + sR);
185
}
186
// Densely sampled tangent never snaps by a large angle (no corner).
187
let prev = null;
188
let maxDa = 0;
189
for (let i = 0; i <= 80; i++)
190
{
191
const d = Online.curveDeriv(curve, i / 80);
192
const a = Math.atan2(d.y, d.x);
193
if (prev != null)
175
const curve = Online.makeAroundCurve(c.start, c.end, c.noField ? null : field, { clearance: 110 });
176
assert.equal(curve.degree, 7, c.name + ' is a single degree-7 Bézier');
177
assert.ok(curve.pts && curve.pts.length === 8, c.name + ' has eight control points');
178
assert.ok(!curve.segments, c.name + ' is not a chain of segments');
179
assert.ok(curve.totalLen > 50, c.name + ' has a measured arc length');
180
181
// Single polynomial ⇒ C^∞: tangent and curvature vary continuously.
182
let prevA = null;
183
let maxDa = 0;
184
const kappas = [];
185
let zeroRun = 0;
186
let maxZeroRun = 0;
187
let maxDKappa = 0;
188
let prevK = null;
189
const N = 100;
190
for (let i = 0; i <= N; i++)
191
{
192
const u = i / N;
193
const d = Online.curveDeriv(curve, u);
194
const a = Math.atan2(d.y, d.x);
195
if (prevA != null)
196
{
197
let da = Math.abs(a - prevA);
198
if (da > Math.PI)
199
{ da = 2 * Math.PI - da; }
200
if (da > maxDa)
201
{ maxDa = da; }
202
}
203
prevA = a;
204
const k = Online.curveCurvature(curve, u);
205
kappas.push(k);
206
// A nearly-straight vertical heading near the ends is
207
// expected (exit up, land down). The forbidden stretch
208
// is a mid-arc cruise like the old κ=0 apex segment.
209
if (u > 0.12 && u < 0.72 && Math.abs(k) < 1e-5)
210
{
211
zeroRun++;
212
if (zeroRun > maxZeroRun)
213
{ maxZeroRun = zeroRun; }
214
}
215
else
216
{ zeroRun = 0; }
217
if (prevK != null)
218
{
219
const dk = Math.abs(k - prevK);
220
if (dk > maxDKappa)
221
{ maxDKappa = dk; }
222
}
223
prevK = k;
224
}
225
assert.ok(maxDa < 0.28, c.name + ' max step angle ' + maxDa + ' looks like a kink');
226
// No long κ≈0 cruise (the old straight apex segment). A short
227
// almost-flat inflection (a few samples) is fine.
228
assert.ok(maxZeroRun <= 8, c.name + ' straight stretch of ' + maxZeroRun + ' samples (κ≈0)');
229
// Curvature changes gradually: no spike between neighbouring samples.
230
const maxAbsK = Math.max(...kappas.map(Math.abs), 1e-9);
231
assert.ok(maxDKappa / maxAbsK < 0.85, c.name + ' curvature jump ' + maxDKappa + ' vs max |κ| ' + maxAbsK);
232
// Ends are vertical: up at the start, down at the landing.
233
const d0 = Online.curveDeriv(curve, 0);
234
const d1 = Online.curveDeriv(curve, 1);
235
assert.ok(d0.y < 0, c.name + ' starts heading up, vy=' + d0.y);
236
assert.ok(Math.abs(d0.x) < 1e-6, c.name + ' start tangent is vertical, dx=' + d0.x);
237
assert.ok(d1.y > 0, c.name + ' ends heading down, vy=' + d1.y);
238
assert.ok(Math.abs(d1.x) < 1e-6, c.name + ' end tangent is vertical, dx=' + d1.x);
239
// Peak sits above both ends (a real arch, not a sag).
240
let minY = Infinity;
241
for (let i = 0; i <= N; i++)
242
{
243
const p = Online.curvePoint(curve, i / N);
244
if (p.y < minY)
245
{ minY = p.y; }
246
}
247
assert.ok(minY < Math.min(c.start.y, c.end.y) - 20, c.name + ' peak ' + minY + ' is not a high arch');
248
if (!c.noField)
194
249
{
195
let da = Math.abs(a - prev);
196
if (da > Math.PI)
197
{ da = 2 * Math.PI - da; }
198
if (da > maxDa)
199
{ maxDa = da; }
250
for (let i = 0; i <= 80; i++)
251
{
252
const p = Online.curvePoint(curve, i / 80);
253
assert.equal(Online.pointAllowedOnArc(p, field, c.start, c.end), true,
254
c.name + ' u=' + (i / 80) + ' at ' + p.x + ',' + p.y + ' crosses the field');
255
}
256
}
257
// Arc-length: |dP/du| is nearly constant (= totalLen).
258
for (const u of [0, 0.25, 0.5, 0.75, 1])
259
{
260
const d = Online.curveDeriv(curve, u);
261
const speed = Math.hypot(d.x, d.y);
262
assert.ok(Math.abs(speed - curve.totalLen) / curve.totalLen < 0.08,
263
c.name + ' arc-length speed at u=' + u + ' is ' + speed + ' vs L=' + curve.totalLen);
200
264
}
201
prev = a;
202
265
}
203
assert.ok(maxDa < 0.35, 'max step angle ' + maxDa + ' looks like a corner');
204
266
});
205
267
206
268
it('leaves a mid-field cell going up and stays in launch/land corridors', () =>
@@ -228,20 +290,29 @@ describe('Smooth C1 arcs (t1134)', () =>
228
290
assert.ok(Math.abs(end.x - (field.left + 3.5 / 10 * field.width)) < 0.5);
229
291
const duration = 1.2;
230
292
const fallPx = (13 / 3) * (field.height / 13);
231
const endSpeedPx = (fallPx * duration) / 3;
232
const curve = Online.makeAroundCurve(start, end, field, {
233
clearance: 80, endSpeedPx: endSpeedPx, duration: duration
234
});
293
const curve = Online.makeAroundCurve(start, end, field, { clearance: 110 });
235
294
const landed = Online.curvePoint(curve, 1);
236
295
assert.ok(Math.abs(landed.x - end.x) < 0.5);
237
296
assert.ok(Math.abs(landed.y - end.y) < 0.5);
238
297
const d1 = Online.curveDeriv(curve, 1);
239
298
assert.ok(d1.y > 0, 'end tangent points down into the column');
240
assert.ok(Math.abs(d1.x) < 20, 'end tangent is vertical, dx=' + d1.x);
241
const v1 = 0.85;
242
const pxPerSec = d1.y * v1 / duration;
243
assert.ok(Math.abs(pxPerSec - fallPx) / fallPx < 0.08,
244
'arrival ' + pxPerSec + ' px/s vs fallSpeed ' + fallPx);
299
assert.ok(Math.abs(d1.x) < 1, 'end tangent is vertical, dx=' + d1.x);
300
// Under arc-length parametrisation |dP/du| = L, so arrival
301
// speed is (L/duration)*v1. flightEaseRates picks v1 to
302
// match fallSpeed, clamped so a very long path does not rush.
303
const rates = Online.flightEaseRates(curve, duration, fallPx);
304
const pxPerSec = (curve.totalLen / duration) * rates.v1;
305
const unclamped = fallPx * duration / curve.totalLen;
306
if (unclamped >= 0.28 && unclamped <= 1.15)
307
{
308
assert.ok(Math.abs(pxPerSec - fallPx) / fallPx < 0.02,
309
'arrival ' + pxPerSec + ' px/s vs fallSpeed ' + fallPx);
310
}
311
else
312
{
313
assert.ok(pxPerSec > 0 && rates.v1 >= 0.28 && rates.v1 <= 1.15,
314
'clamped arrival ' + pxPerSec + ' with v1=' + rates.v1);
315
}
245
316
});
246
317
247
318
it('smoothParam has non-zero endpoint derivatives (no visual stop)', () =>
@@ -160,47 +160,109 @@ describe('Smooth C1 arcs (t1134)', () =>160
return Online.cellViewport(col, y, field);160
return Online.cellViewport(col, y, field);161
}161
}162
162
163
it('is a C1 curve: tangents and speeds match at joints, no corners', () =>163
it('is one continuous polynomial: C^∞, gradual curvature, no straight stretches (t1138)', () =>164
{164
{165
const start = { x: 250, y: 700 };165
const cases = [166
const end = entry(3);166
{ name: 'incoming left-mini → col3', start: { x: 250, y: 700 }, end: entry(3) },167
const curve = Online.makeAroundCurve(start, end, field, { clearance: 80 });167
{ name: 'incoming far-left → col9', start: { x: 200, y: 800 }, end: entry(9) },168
assert.ok(curve.segments && curve.segments.length >= 2, 'multi-segment around-field path');168
{ name: 'outgoing mid → right mini', start: entry(6), end: { x: field.right + 80, y: 700 } },169
const n = curve.segments.length;169
{ name: 'outgoing col0 → left mini', start: entry(0), end: { x: 200, y: 700 } },170
for (let i = 1; i < n; i++)170
{ name: 'incoming right-mini → col1', start: { x: field.right + 90, y: 720 }, end: entry(1) },171
{ name: 'enemy→enemy behind (no field)', start: { x: 180, y: 750 }, end: { x: field.right + 90, y: 680 }, noField: true }172
];173
for (const c of cases)171
{174
{172
const u = i / n;175
const curve = Online.makeAroundCurve(c.start, c.end, c.noField ? null : field, { clearance: 110 });173
const left = Online.curveDeriv(curve, u - 1e-6);176
assert.equal(curve.degree, 7, c.name + ' is a single degree-7 Bézier');174
const right = Online.curveDeriv(curve, u + 1e-6);177
assert.ok(curve.pts && curve.pts.length === 8, c.name + ' has eight control points');175
const aL = Math.atan2(left.y, left.x);178
assert.ok(!curve.segments, c.name + ' is not a chain of segments');176
const aR = Math.atan2(right.y, right.x);179
assert.ok(curve.totalLen > 50, c.name + ' has a measured arc length');177
let da = Math.abs(aR - aL);180
178
if (da > Math.PI)181
// Single polynomial ⇒ C^∞: tangent and curvature vary continuously.179
{ da = 2 * Math.PI - da; }182
let prevA = null;180
assert.ok(da < 0.02, 'joint ' + i + ' direction jump ' + da);183
let maxDa = 0;181
const sL = Math.hypot(left.x, left.y);184
const kappas = [];182
const sR = Math.hypot(right.x, right.y);185
let zeroRun = 0;183
assert.ok(Math.abs(sL - sR) / Math.max(sL, 1) < 0.05,186
let maxZeroRun = 0;184
'joint ' + i + ' speed jump ' + sL + ' vs ' + sR);187
let maxDKappa = 0;185
}188
let prevK = null;186
// Densely sampled tangent never snaps by a large angle (no corner).189
const N = 100;187
let prev = null;190
for (let i = 0; i <= N; i++)188
let maxDa = 0;191
{189
for (let i = 0; i <= 80; i++)192
const u = i / N;190
{193
const d = Online.curveDeriv(curve, u);191
const d = Online.curveDeriv(curve, i / 80);194
const a = Math.atan2(d.y, d.x);192
const a = Math.atan2(d.y, d.x);195
if (prevA != null)193
if (prev != null)196
{197
let da = Math.abs(a - prevA);198
if (da > Math.PI)199
{ da = 2 * Math.PI - da; }200
if (da > maxDa)201
{ maxDa = da; }202
}203
prevA = a;204
const k = Online.curveCurvature(curve, u);205
kappas.push(k);206
// A nearly-straight vertical heading near the ends is207
// expected (exit up, land down). The forbidden stretch208
// is a mid-arc cruise like the old κ=0 apex segment.209
if (u > 0.12 && u < 0.72 && Math.abs(k) < 1e-5)210
{211
zeroRun++;212
if (zeroRun > maxZeroRun)213
{ maxZeroRun = zeroRun; }214
}215
else216
{ zeroRun = 0; }217
if (prevK != null)218
{219
const dk = Math.abs(k - prevK);220
if (dk > maxDKappa)221
{ maxDKappa = dk; }222
}223
prevK = k;224
}225
assert.ok(maxDa < 0.28, c.name + ' max step angle ' + maxDa + ' looks like a kink');226
// No long κ≈0 cruise (the old straight apex segment). A short227
// almost-flat inflection (a few samples) is fine.228
assert.ok(maxZeroRun <= 8, c.name + ' straight stretch of ' + maxZeroRun + ' samples (κ≈0)');229
// Curvature changes gradually: no spike between neighbouring samples.230
const maxAbsK = Math.max(...kappas.map(Math.abs), 1e-9);231
assert.ok(maxDKappa / maxAbsK < 0.85, c.name + ' curvature jump ' + maxDKappa + ' vs max |κ| ' + maxAbsK);232
// Ends are vertical: up at the start, down at the landing.233
const d0 = Online.curveDeriv(curve, 0);234
const d1 = Online.curveDeriv(curve, 1);235
assert.ok(d0.y < 0, c.name + ' starts heading up, vy=' + d0.y);236
assert.ok(Math.abs(d0.x) < 1e-6, c.name + ' start tangent is vertical, dx=' + d0.x);237
assert.ok(d1.y > 0, c.name + ' ends heading down, vy=' + d1.y);238
assert.ok(Math.abs(d1.x) < 1e-6, c.name + ' end tangent is vertical, dx=' + d1.x);239
// Peak sits above both ends (a real arch, not a sag).240
let minY = Infinity;241
for (let i = 0; i <= N; i++)242
{243
const p = Online.curvePoint(curve, i / N);244
if (p.y < minY)245
{ minY = p.y; }246
}247
assert.ok(minY < Math.min(c.start.y, c.end.y) - 20, c.name + ' peak ' + minY + ' is not a high arch');248
if (!c.noField)194
{249
{195
let da = Math.abs(a - prev);250
for (let i = 0; i <= 80; i++)196
if (da > Math.PI)251
{197
{ da = 2 * Math.PI - da; }252
const p = Online.curvePoint(curve, i / 80);198
if (da > maxDa)253
assert.equal(Online.pointAllowedOnArc(p, field, c.start, c.end), true,199
{ maxDa = da; }254
c.name + ' u=' + (i / 80) + ' at ' + p.x + ',' + p.y + ' crosses the field');255
}256
}257
// Arc-length: |dP/du| is nearly constant (= totalLen).258
for (const u of [0, 0.25, 0.5, 0.75, 1])259
{260
const d = Online.curveDeriv(curve, u);261
const speed = Math.hypot(d.x, d.y);262
assert.ok(Math.abs(speed - curve.totalLen) / curve.totalLen < 0.08,263
c.name + ' arc-length speed at u=' + u + ' is ' + speed + ' vs L=' + curve.totalLen);200
}264
}201
prev = a;202
}265
}203
assert.ok(maxDa < 0.35, 'max step angle ' + maxDa + ' looks like a corner');204
});266
});205
267
206
it('leaves a mid-field cell going up and stays in launch/land corridors', () =>268
it('leaves a mid-field cell going up and stays in launch/land corridors', () =>@@ -228,20 +290,29 @@ describe('Smooth C1 arcs (t1134)', () =>228
assert.ok(Math.abs(end.x - (field.left + 3.5 / 10 * field.width)) < 0.5);290
assert.ok(Math.abs(end.x - (field.left + 3.5 / 10 * field.width)) < 0.5);229
const duration = 1.2;291
const duration = 1.2;230
const fallPx = (13 / 3) * (field.height / 13);292
const fallPx = (13 / 3) * (field.height / 13);231
const endSpeedPx = (fallPx * duration) / 3;293
const curve = Online.makeAroundCurve(start, end, field, { clearance: 110 });232
const curve = Online.makeAroundCurve(start, end, field, {233
clearance: 80, endSpeedPx: endSpeedPx, duration: duration234
});235
const landed = Online.curvePoint(curve, 1);294
const landed = Online.curvePoint(curve, 1);236
assert.ok(Math.abs(landed.x - end.x) < 0.5);295
assert.ok(Math.abs(landed.x - end.x) < 0.5);237
assert.ok(Math.abs(landed.y - end.y) < 0.5);296
assert.ok(Math.abs(landed.y - end.y) < 0.5);238
const d1 = Online.curveDeriv(curve, 1);297
const d1 = Online.curveDeriv(curve, 1);239
assert.ok(d1.y > 0, 'end tangent points down into the column');298
assert.ok(d1.y > 0, 'end tangent points down into the column');240
assert.ok(Math.abs(d1.x) < 20, 'end tangent is vertical, dx=' + d1.x);299
assert.ok(Math.abs(d1.x) < 1, 'end tangent is vertical, dx=' + d1.x);241
const v1 = 0.85;300
// Under arc-length parametrisation |dP/du| = L, so arrival242
const pxPerSec = d1.y * v1 / duration;301
// speed is (L/duration)*v1. flightEaseRates picks v1 to243
assert.ok(Math.abs(pxPerSec - fallPx) / fallPx < 0.08,302
// match fallSpeed, clamped so a very long path does not rush.244
'arrival ' + pxPerSec + ' px/s vs fallSpeed ' + fallPx);303
const rates = Online.flightEaseRates(curve, duration, fallPx);304
const pxPerSec = (curve.totalLen / duration) * rates.v1;305
const unclamped = fallPx * duration / curve.totalLen;306
if (unclamped >= 0.28 && unclamped <= 1.15)307
{308
assert.ok(Math.abs(pxPerSec - fallPx) / fallPx < 0.02,309
'arrival ' + pxPerSec + ' px/s vs fallSpeed ' + fallPx);310
}311
else312
{313
assert.ok(pxPerSec > 0 && rates.v1 >= 0.28 && rates.v1 <= 1.15,314
'clamped arrival ' + pxPerSec + ' with v1=' + rates.v1);315
}245
});316
});246
317
247
it('smoothParam has non-zero endpoint derivatives (no visual stop)', () =>318
it('smoothParam has non-zero endpoint derivatives (no visual stop)', () =>@@ -411,7 +411,7 @@ def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_m
411
411
n=n_minis)
412
412
else:
413
413
assert_top(info, name)
414
shot(page, f"t1134-{name}-layout.png")
414
shot(page, f"t1138-{name}-layout.png")
415
415
416
416
flights = page.evaluate(INJECT_FLIGHTS, 0.55)
417
417
print(f"--- {name} flights:", {k: flights[k] for k in ('front', 'back', 'expectedEndX', 'expectedEndY', 'expectedStartY', 'hudH', 'mode') if k in flights})
@@ -420,27 +420,32 @@ def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_m
420
420
f"src={knd.get('src')} curve={knd.get('hasCurve')}/{knd.get('segments')} "
421
421
f"start={knd.get('start')} end={knd.get('end')} pos={knd.get('pos')}")
422
422
assert_flights(flights, name)
423
shot(page, f"t1134-{name}-midarc.png")
423
shot(page, f"t1138-{name}-midarc.png")
424
424
425
425
if name in ("1024x532-3bots", "1920x1080-8bots", "desktop-wide"):
426
426
for age, label in ((0.18, "early"), (0.85, "late")):
427
427
page.evaluate(INJECT_FLIGHTS, age)
428
shot(page, f"t1134-{name}-midarc-{label}.png")
428
shot(page, f"t1138-{name}-midarc-{label}.png")
429
429
context.close()
430
430
431
431
432
def record_arcs_video(browser, url):
433
"""A short webm of two volleys flying out, over, and into the field (t1134/t1135)."""
432
def record_arcs_video(browser, url, width, height, round_n):
433
"""A short webm of two volleys flying out, over, and into the field (t1138)."""
434
434
VIDEO.mkdir(parents=True, exist_ok=True)
435
dest = VIDEO / "t1134-arcs-1920x1080.webm"
435
raw_dir = VIDEO / f"_raw_{width}x{height}"
436
if raw_dir.exists():
437
for old in raw_dir.glob("*"):
438
old.unlink()
439
raw_dir.mkdir(parents=True, exist_ok=True)
440
dest = VIDEO / f"t1138-arcs-{width}x{height}.webm"
436
441
context = browser.new_context(
437
viewport={"width": 1920, "height": 1080},
442
viewport={"width": width, "height": height},
438
443
device_scale_factor=1,
439
record_video_dir=str(VIDEO / "_raw"),
440
record_video_size={"width": 1920, "height": 1080},
444
record_video_dir=str(raw_dir),
445
record_video_size={"width": width, "height": height},
441
446
)
442
447
page = context.new_page()
443
open_offline(page, url, round_n=25)
448
open_offline(page, url, round_n=round_n)
444
449
page.wait_for_timeout(400)
445
450
# Live volleys at age 0 so tickFlights animates them in the game loop.
446
451
page.evaluate(INJECT_FLIGHTS, 0)
@@ -449,17 +454,16 @@ def record_arcs_video(browser, url):
449
454
page.wait_for_timeout(1400)
450
455
page.close()
451
456
context.close()
452
# Playwright writes the webm next to the context; move it into place.
453
raw = list((VIDEO / "_raw").glob("*.webm"))
457
raw = list(raw_dir.glob("*.webm"))
454
458
if raw:
455
459
raw[0].replace(dest)
456
460
print(f"wrote {dest} ({dest.stat().st_size} bytes)")
457
461
else:
458
FAILURES.append("video: no webm produced")
459
print("FAIL video: no webm produced")
462
FAILURES.append(f"video {width}x{height}: no webm produced")
463
print(f"FAIL video {width}x{height}: no webm produced")
460
464
return
461
465
if dest.stat().st_size < 10000:
462
FAILURES.append(f"video: suspiciously small ({dest.stat().st_size} bytes)")
466
FAILURES.append(f"video {width}x{height}: suspiciously small ({dest.stat().st_size} bytes)")
463
467
464
468
465
469
def main():
@@ -484,7 +488,8 @@ def main():
484
488
expect_one_row=True, n_minis=8)
485
489
run_viewport(browser, url, "1920x1080-8bots", 1920, 1080, False, 25, "sides",
486
490
expect_one_row=True, n_minis=8)
487
record_arcs_video(browser, url)
491
record_arcs_video(browser, url, 1920, 1080, 25)
492
record_arcs_video(browser, url, 1024, 532, 3)
488
493
browser.close()
489
494
finally:
490
495
http.terminate()
@@ -411,7 +411,7 @@ def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_m411
n=n_minis)411
n=n_minis)412
else:412
else:413
assert_top(info, name)413
assert_top(info, name)414
shot(page, f"t1134-{name}-layout.png")414
shot(page, f"t1138-{name}-layout.png")415
415
416
flights = page.evaluate(INJECT_FLIGHTS, 0.55)416
flights = page.evaluate(INJECT_FLIGHTS, 0.55)417
print(f"--- {name} flights:", {k: flights[k] for k in ('front', 'back', 'expectedEndX', 'expectedEndY', 'expectedStartY', 'hudH', 'mode') if k in flights})417
print(f"--- {name} flights:", {k: flights[k] for k in ('front', 'back', 'expectedEndX', 'expectedEndY', 'expectedStartY', 'hudH', 'mode') if k in flights})@@ -420,27 +420,32 @@ def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_m420
f"src={knd.get('src')} curve={knd.get('hasCurve')}/{knd.get('segments')} "420
f"src={knd.get('src')} curve={knd.get('hasCurve')}/{knd.get('segments')} "421
f"start={knd.get('start')} end={knd.get('end')} pos={knd.get('pos')}")421
f"start={knd.get('start')} end={knd.get('end')} pos={knd.get('pos')}")422
assert_flights(flights, name)422
assert_flights(flights, name)423
shot(page, f"t1134-{name}-midarc.png")423
shot(page, f"t1138-{name}-midarc.png")424
424
425
if name in ("1024x532-3bots", "1920x1080-8bots", "desktop-wide"):425
if name in ("1024x532-3bots", "1920x1080-8bots", "desktop-wide"):426
for age, label in ((0.18, "early"), (0.85, "late")):426
for age, label in ((0.18, "early"), (0.85, "late")):427
page.evaluate(INJECT_FLIGHTS, age)427
page.evaluate(INJECT_FLIGHTS, age)428
shot(page, f"t1134-{name}-midarc-{label}.png")428
shot(page, f"t1138-{name}-midarc-{label}.png")429
context.close()429
context.close()430
430
431
431
432
def record_arcs_video(browser, url):432
def record_arcs_video(browser, url, width, height, round_n):433
"""A short webm of two volleys flying out, over, and into the field (t1134/t1135)."""433
"""A short webm of two volleys flying out, over, and into the field (t1138)."""434
VIDEO.mkdir(parents=True, exist_ok=True)434
VIDEO.mkdir(parents=True, exist_ok=True)435
dest = VIDEO / "t1134-arcs-1920x1080.webm"435
raw_dir = VIDEO / f"_raw_{width}x{height}"436
if raw_dir.exists():437
for old in raw_dir.glob("*"):438
old.unlink()439
raw_dir.mkdir(parents=True, exist_ok=True)440
dest = VIDEO / f"t1138-arcs-{width}x{height}.webm"436
context = browser.new_context(441
context = browser.new_context(437
viewport={"width": 1920, "height": 1080},442
viewport={"width": width, "height": height},438
device_scale_factor=1,443
device_scale_factor=1,439
record_video_dir=str(VIDEO / "_raw"),444
record_video_dir=str(raw_dir),440
record_video_size={"width": 1920, "height": 1080},445
record_video_size={"width": width, "height": height},441
)446
)442
page = context.new_page()447
page = context.new_page()443
open_offline(page, url, round_n=25)448
open_offline(page, url, round_n=round_n)444
page.wait_for_timeout(400)449
page.wait_for_timeout(400)445
# Live volleys at age 0 so tickFlights animates them in the game loop.450
# Live volleys at age 0 so tickFlights animates them in the game loop.446
page.evaluate(INJECT_FLIGHTS, 0)451
page.evaluate(INJECT_FLIGHTS, 0)@@ -449,17 +454,16 @@ def record_arcs_video(browser, url):449
page.wait_for_timeout(1400)454
page.wait_for_timeout(1400)450
page.close()455
page.close()451
context.close()456
context.close()452
# Playwright writes the webm next to the context; move it into place.457
raw = list(raw_dir.glob("*.webm"))453
raw = list((VIDEO / "_raw").glob("*.webm"))454
if raw:458
if raw:455
raw[0].replace(dest)459
raw[0].replace(dest)456
print(f"wrote {dest} ({dest.stat().st_size} bytes)")460
print(f"wrote {dest} ({dest.stat().st_size} bytes)")457
else:461
else:458
FAILURES.append("video: no webm produced")462
FAILURES.append(f"video {width}x{height}: no webm produced")459
print("FAIL video: no webm produced")463
print(f"FAIL video {width}x{height}: no webm produced")460
return464
return461
if dest.stat().st_size < 10000:465
if dest.stat().st_size < 10000:462
FAILURES.append(f"video: suspiciously small ({dest.stat().st_size} bytes)")466
FAILURES.append(f"video {width}x{height}: suspiciously small ({dest.stat().st_size} bytes)")463
467
464
468
465
def main():469
def main():@@ -484,7 +488,8 @@ def main():484
expect_one_row=True, n_minis=8)488
expect_one_row=True, n_minis=8)485
run_viewport(browser, url, "1920x1080-8bots", 1920, 1080, False, 25, "sides",489
run_viewport(browser, url, "1920x1080-8bots", 1920, 1080, False, 25, "sides",486
expect_one_row=True, n_minis=8)490
expect_one_row=True, n_minis=8)487
record_arcs_video(browser, url)491
record_arcs_video(browser, url, 1920, 1080, 25)492
record_arcs_video(browser, url, 1024, 532, 3)488
browser.close()493
browser.close()489
finally:494
finally:490
http.terminate()495
http.terminate()