{"version":3,"file":"estimate.cjs","names":[],"sources":["../../src/geo/estimate.ts"],"sourcesContent":["import { haversineKm } from \"./distance\";\nimport type { Coordinate, TravelEstimate, TravelMode } from \"./types\";\n\n/**\n * Multiplier applied to the great-circle distance to approximate real road\n * distance. Mirrors `DEFAULT_CIRCUITY_FACTOR` from `tempest-fastapi-sdk`.\n */\nexport const DEFAULT_CIRCUITY_FACTOR = 1.3;\n\n/**\n * Default average car speed in km/h used to derive duration from distance.\n * Mirrors `DEFAULT_CAR_SPEED_KMH` from `tempest-fastapi-sdk`.\n */\nexport const DEFAULT_CAR_SPEED_KMH = 50.0;\n\n/**\n * Per-mode multipliers applied to the car duration. Mirrors\n * `DEFAULT_MODE_DURATION_FACTORS` from `tempest-fastapi-sdk` — motorcycles are\n * a touch faster, buses considerably slower (stops + dedicated lanes).\n */\nexport const DEFAULT_MODE_DURATION_FACTORS: Record<TravelMode, number> = {\n    car: 1.0,\n    motorcycle: 0.95,\n    bus: 1.6,\n};\n\n/**\n * Look up the duration multiplier for a travel mode, falling back to `1.0`\n * for unknown modes. Mirrors `duration_factor` from `tempest-fastapi-sdk`.\n *\n * @param mode - Travel mode.\n * @param factors - Optional override map (partial merges over the defaults).\n * @returns The multiplier for `mode`.\n */\nexport function durationFactor(\n    mode: TravelMode,\n    factors?: Partial<Record<TravelMode, number>>,\n): number {\n    return factors?.[mode] ?? DEFAULT_MODE_DURATION_FACTORS[mode] ?? 1.0;\n}\n\n/** Options for {@link estimateTravel}. */\nexport interface EstimateTravelOptions {\n    /** Distance multiplier over the great-circle line. Default: `1.3`. */\n    circuityFactor?: number;\n    /** Average car speed in km/h. Default: `50`. */\n    carSpeedKmh?: number;\n    /** Per-mode duration multipliers (merged over the defaults). */\n    modeDurationFactors?: Partial<Record<TravelMode, number>>;\n}\n\n/**\n * Offline travel estimate between two coordinates. No network — distance comes\n * from {@link haversineKm} scaled by circuity, duration from a mode-adjusted\n * average speed. Mirrors `estimate_travel` from `tempest-fastapi-sdk`.\n *\n * @param origin - Start coordinate.\n * @param destination - End coordinate.\n * @param mode - Travel mode. Default: `\"car\"`.\n * @param options - Tuning knobs (circuity, speed, per-mode factors).\n * @returns A `\"heuristic\"` {@link TravelEstimate}.\n * @throws {RangeError} If `carSpeedKmh <= 0` or `circuityFactor <= 0`.\n *\n * @example\n * estimateTravel(\n *   { latitude: -23.5505, longitude: -46.6333 },\n *   { latitude: -23.5629, longitude: -46.6544 },\n *   \"car\",\n * ); // { mode: \"car\", distance_km: …, duration_minutes: …, source: \"heuristic\" }\n *\n * @tempest-limits param-count — `(origin, destination, mode)` is the shape every\n * routing API uses, and the fourth argument is already the named-options object the\n * rule asks for. Folding origin and destination into it would hide that the pair is\n * ordered, and this function is re-exported from the package root, so the change\n * would break every caller to satisfy a count.\n */\nexport function estimateTravel(\n    origin: Coordinate,\n    destination: Coordinate,\n    mode: TravelMode = \"car\",\n    options: EstimateTravelOptions = {},\n): TravelEstimate {\n    const {\n        circuityFactor = DEFAULT_CIRCUITY_FACTOR,\n        carSpeedKmh = DEFAULT_CAR_SPEED_KMH,\n        modeDurationFactors,\n    } = options;\n\n    if (carSpeedKmh <= 0) {\n        throw new RangeError(\"carSpeedKmh must be greater than 0\");\n    }\n    if (circuityFactor <= 0) {\n        throw new RangeError(\"circuityFactor must be greater than 0\");\n    }\n\n    const distanceKm = haversineKm(origin, destination) * circuityFactor;\n    const carMinutes = (distanceKm / carSpeedKmh) * 60.0;\n    const durationMinutes = carMinutes * durationFactor(mode, modeDurationFactors);\n\n    return {\n        mode,\n        distance_km: distanceKm,\n        duration_minutes: durationMinutes,\n        source: \"heuristic\",\n    };\n}\n"],"mappings":"kCAOA,IAAa,EAA0B,IAM1B,EAAwB,GAOxB,EAA4D,CACrE,IAAK,EACL,WAAY,IACZ,IAAK,GACT,EAUA,SAAgB,EACZ,EACA,EACM,CACN,OAAO,IAAU,IAAS,EAA8B,IAAS,CACrE,CAqCA,SAAgB,EACZ,EACA,EACA,EAAmB,MACnB,EAAiC,CAAC,EACpB,CACd,GAAM,CACF,iBAAiB,EACjB,cAAA,GACA,uBACA,EAEJ,GAAI,GAAe,EACf,MAAU,WAAW,oCAAoC,EAE7D,GAAI,GAAkB,EAClB,MAAU,WAAW,uCAAuC,EAGhE,IAAM,EAAa,EAAA,YAAY,EAAQ,CAAW,EAAI,EAItD,MAAO,CACH,OACA,YAAa,EACb,iBANgB,EAAa,EAAe,GACX,EAAe,EAAM,CAAmB,EAMzE,OAAQ,WACZ,CACJ"}