pickStringChar maps a local (dx, dy) direction to a line character, accounting for terminal cell aspect ratio (~2:1 tall:wide). Without this correction, near-horizontal lines would often pick diagonal chars.
(dx, dy float32)
| 227 | // accounting for terminal cell aspect ratio (~2:1 tall:wide). Without this |
| 228 | // correction, near-horizontal lines would often pick diagonal chars. |
| 229 | func pickStringChar(dx, dy float32) rune { |
| 230 | // Treat one vertical cell as if it were 2 wide for angle calc — |
| 231 | // matches the visual aspect of the terminal. |
| 232 | aDy := dy * 2 |
| 233 | ax := absF(dx) |
| 234 | ay := absF(aDy) |
| 235 | switch { |
| 236 | case ax > 1.8*ay: |
| 237 | return '─' |
| 238 | case ay > 1.8*ax: |
| 239 | return '│' |
| 240 | case dx*dy < 0: // up-right or down-left → `/` |
| 241 | return '╱' |
| 242 | default: // down-right or up-left → `\` |
| 243 | return '╲' |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | func absF(x float32) float32 { |
| 248 | if x < 0 { |