/// Explicit inputs for the opt-in full-editor benchmark. class ViewportBenchConfig { ViewportBenchConfig.fromEnvironment(Map environment) : outputPath = environment['CUTDEX_FULL_APP_VIEWPORT_BENCH']!, startGate = environment['CUTDEX_FULL_APP_VIEWPORT_START_GATE'], expectedFrames = _number(environment, 'EXPECTED_FRAMES'), rounds = _integer(environment, 'ROUNDS', 5), paired = _flag(environment, 'PAIRED', false), silent = _flag(environment, 'SILENT', false), nativeOnly = _flag(environment, 'NATIVE_ONLY', true), captureHelper = environment['CUTDEX_FULL_APP_VIEWPORT_CAPTURE_HELPER'], timelineFps = _integer(environment, 'TIMELINE_FPS', 30), inputHz = _integer(environment, 'INPUT_HZ', 60), inputCount = _integer(environment, 'INPUT_COUNT', 360), localStartFrame = _optionalInteger(environment, 'LOCAL_START_FRAME'), localSpanFrames = _integer(environment, 'LOCAL_SPAN_FRAMES', 20), localPixelsPerFrame = _number(environment, 'LOCAL_PIXELS_PER_FRAME') ?? 4, edgeMarginFrames = _integer(environment, 'EDGE_MARGIN_FRAMES', 900), sampleIntervalMs = _integer(environment, 'SAMPLE_INTERVAL_MS', 16) { if (outputPath.isEmpty || rounds < 1 || timelineFps < 1 || inputHz < 1 || inputCount < 6 || inputCount.isOdd || localSpanFrames < 1 || localPixelsPerFrame <= 0 || edgeMarginFrames < 1 || sampleIntervalMs < 1 || (expectedFrames != null && expectedFrames! <= 0)) { throw ArgumentError('Invalid viewport benchmark configuration'); } if (!nativeOnly && (captureHelper == null || captureHelper!.isEmpty)) { throw ArgumentError('CAPTURE_HELPER is required when NATIVE_ONLY=0'); } } final String outputPath; final String? startGate; final double? expectedFrames; final int rounds, timelineFps, inputHz, inputCount, localSpanFrames; final int edgeMarginFrames, sampleIntervalMs; final int? localStartFrame; final double localPixelsPerFrame; final bool paired, silent, nativeOnly; final String? captureHelper; Map toJson() => { 'expectedFrames': expectedFrames, 'rounds': rounds, 'paired': paired, 'timelineFps': timelineFps, 'inputHz': inputHz, 'inputCount': inputCount, 'localStartFrame': localStartFrame, 'localSpanFrames': localSpanFrames, 'localPixelsPerFrame': localPixelsPerFrame, 'edgeMarginFrames': edgeMarginFrames, 'sampleIntervalMs': sampleIntervalMs, 'nativeOnly': nativeOnly, 'captureHelper': captureHelper, 'silent': silent, }; static int _integer(Map env, String key, int fallback) => _optionalInteger(env, key) ?? fallback; static int? _optionalInteger(Map env, String key) { final value = env['CUTDEX_FULL_APP_VIEWPORT_$key']; return value == null ? null : int.parse(value); } static double? _number(Map env, String key) { final value = env['CUTDEX_FULL_APP_VIEWPORT_$key']; if (value == null) return null; final number = double.parse(value); if (!number.isFinite) throw ArgumentError('Non-finite $key'); return number; } static bool _flag(Map env, String key, bool fallback) { final value = env['CUTDEX_FULL_APP_VIEWPORT_$key']; return switch (value) { null => fallback, '1' => true, '0' => false, _ => throw ArgumentError('$key must be 0 or 1'), }; } }