diff --git a/assets/js/propagation_map_hook.js b/assets/js/propagation_map_hook.js index f1965ede..b68a837a 100644 --- a/assets/js/propagation_map_hook.js +++ b/assets/js/propagation_map_hook.js @@ -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