(hfovDeg: number, lut: FovPoint[])
| 552 | } |
| 553 | |
| 554 | export function zoomUnitsFromHfov(hfovDeg: number, lut: FovPoint[]): number { |
| 555 | const pts = [...lut].sort((a, b) => b.hfovDeg - a.hfovDeg); // wide -> tele |
| 556 | if (pts.length === 0) return 0; |
| 557 | if (hfovDeg >= pts[0].hfovDeg) return pts[0].units; |
| 558 | const last = pts[pts.length - 1]; |
| 559 | if (hfovDeg <= last.hfovDeg) return last.units; |
| 560 | for (let i = 1; i < pts.length; i++) { |
| 561 | if (hfovDeg >= pts[i].hfovDeg) { |
| 562 | const a = toLogTan(pts[i - 1].hfovDeg); |
| 563 | const b = toLogTan(pts[i].hfovDeg); |
| 564 | const f = (toLogTan(hfovDeg) - a) / (b - a); |
| 565 | return Math.round(pts[i - 1].units * (1 - f) + pts[i].units * f); |
| 566 | } |
| 567 | } |
| 568 | return last.units; |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * The HFOV to command: frame the plane at ~1/4–1/3 of frame height, but never |
no test coverage detected