Cap propagation reach flood fill to 300 km radius

Without a distance limit, the BFS would expand across the entire grid
when conditions were broadly favorable, producing a polygon covering
most of CONUS.
This commit is contained in:
Graham McIntire 2026-04-02 12:38:07 -05:00
parent 2b14e836f1
commit 1cf92b2166
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -113,23 +113,33 @@ function rangeEstimate(score, detail) {
*/
function propagationReach(gridLookup, startLat, startLon, minScore) {
const step = 0.125
const maxKm = 300
const snap = (v) => (Math.round(v / step) * step).toFixed(3)
const startKey = `${snap(startLat)},${snap(startLon)}`
const startScore = gridLookup.get(startKey)
if (startScore == null || startScore < minScore) return []
const cosLat = Math.cos(startLat * Math.PI / 180)
const kmPerDegLat = 111.0
const kmPerDegLon = 111.0 * cosLat
const visited = new Set()
const reachable = []
const queue = [startKey]
visited.add(startKey)
// BFS flood fill through grid
// BFS flood fill through grid, capped at maxKm from origin
while (queue.length > 0) {
const key = queue.shift()
const [latStr, lonStr] = key.split(",")
const lat = parseFloat(latStr)
const lon = parseFloat(lonStr)
const dLat = (lat - startLat) * kmPerDegLat
const dLon = (lon - startLon) * kmPerDegLon
if (Math.sqrt(dLat * dLat + dLon * dLon) > maxKm) continue
reachable.push({ lat, lon })
// Check 4 neighbors