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:
parent
2b14e836f1
commit
1cf92b2166
1 changed files with 11 additions and 1 deletions
|
|
@ -113,23 +113,33 @@ function rangeEstimate(score, detail) {
|
||||||
*/
|
*/
|
||||||
function propagationReach(gridLookup, startLat, startLon, minScore) {
|
function propagationReach(gridLookup, startLat, startLon, minScore) {
|
||||||
const step = 0.125
|
const step = 0.125
|
||||||
|
const maxKm = 300
|
||||||
const snap = (v) => (Math.round(v / step) * step).toFixed(3)
|
const snap = (v) => (Math.round(v / step) * step).toFixed(3)
|
||||||
|
|
||||||
const startKey = `${snap(startLat)},${snap(startLon)}`
|
const startKey = `${snap(startLat)},${snap(startLon)}`
|
||||||
const startScore = gridLookup.get(startKey)
|
const startScore = gridLookup.get(startKey)
|
||||||
if (startScore == null || startScore < minScore) return []
|
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 visited = new Set()
|
||||||
const reachable = []
|
const reachable = []
|
||||||
const queue = [startKey]
|
const queue = [startKey]
|
||||||
visited.add(startKey)
|
visited.add(startKey)
|
||||||
|
|
||||||
// BFS flood fill through grid
|
// BFS flood fill through grid, capped at maxKm from origin
|
||||||
while (queue.length > 0) {
|
while (queue.length > 0) {
|
||||||
const key = queue.shift()
|
const key = queue.shift()
|
||||||
const [latStr, lonStr] = key.split(",")
|
const [latStr, lonStr] = key.split(",")
|
||||||
const lat = parseFloat(latStr)
|
const lat = parseFloat(latStr)
|
||||||
const lon = parseFloat(lonStr)
|
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 })
|
reachable.push({ lat, lon })
|
||||||
|
|
||||||
// Check 4 neighbors
|
// Check 4 neighbors
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue