/* 586 TM ↔ 경위도 · 화면 TM 틀 헬퍼 — `D03_PlanAnalysis_Tm.ts` 를 stdin 점 목록으로 돌려 JSON 으로 냄. * 입력 { points: [[epsg, x, y]], lonlat: [[epsg, lon, lat]], frames: [{ epsg, box, view, probes }] } */ const path = require("path"); const { makeLoader } = require("./helper_ts_stub_loader.cjs"); const ROOT = path.join(__dirname, "..", ".."); const { load } = makeLoader({ root: ROOT }); const tm = load("D03_PlanAnalysis", "logic", "D03_PlanAnalysis_Tm.ts"); const input = JSON.parse(require("fs").readFileSync(0, "utf-8")); const out = { unknown: tm.tmParams(5174), toLonLat: input.points.map(([epsg, x, y]) => tm.tmToLonLat(tm.tmParams(epsg), x, y)), toTm: input.lonlat.map(([epsg, lon, lat]) => tm.lonLatToTm(tm.tmParams(epsg), lon, lat)), frames: input.frames.map(({ epsg, box, view, probes }) => { // 경위도 상자를 화면 직사각형에 펴는 바탕(캔버스 지금 꼴) · 가운데 = (cx, cy) const [lonMin, latMin, lonMax, latMax] = box; const [w, h, x0, y0, sx, sy] = view; const project = (lon, lat) => [ x0 + ((lon - lonMin) / (lonMax - lonMin)) * sx, y0 + ((latMax - lat) / (latMax - latMin)) * sy, ]; const unproject = (px, py) => [ lonMin + ((px - x0) / sx) * (lonMax - lonMin), latMax - ((py - y0) / sy) * (latMax - latMin), ]; const p = tm.tmParams(epsg); const frame = tm.localTmFrame(p, project, unproject, w / 2, h / 2); return { pxPerMeter: frame.pxPerMeter, probes: probes.map(([x, y]) => { const exact = project(...tm.tmToLonLat(p, x, y)); const got = frame.toScreen(x, y); const back = frame.toMetric(...got); return { exact, got, back }; }), }; }), }; process.stdout.write(JSON.stringify(out));