(
positions: Iterable<{ x: number; y: number }>,
)
| 62 | |
| 63 | /** Compute the bounding box of a set of positions. */ |
| 64 | export function computeBounds( |
| 65 | positions: Iterable<{ x: number; y: number }>, |
| 66 | ): Bounds { |
| 67 | let minX = Infinity, |
| 68 | maxX = -Infinity, |
| 69 | minY = Infinity, |
| 70 | maxY = -Infinity; |
| 71 | for (const p of positions) { |
| 72 | if (p.x < minX) minX = p.x; |
| 73 | if (p.x > maxX) maxX = p.x; |
| 74 | if (p.y < minY) minY = p.y; |
| 75 | if (p.y > maxY) maxY = p.y; |
| 76 | } |
| 77 | return { minX, maxX, minY, maxY }; |
| 78 | } |
| 79 | |
| 80 | /** Compute viewport that fits the given bounds into a canvas of (w, h). */ |
| 81 | export function fitBounds( |
no outgoing calls
no test coverage detected