fix: find fire perimeters that overlap an area

Fire perimeters were placed at their average vertex, so a fire enclosing the
whole requested area was missed. Polygons now count when a vertex is inside
the area, an edge crosses it, or the polygon contains it outside any hole.
This commit is contained in:
Sameh Khamis committed 2026-10-02 15:21:36 -07:00
1 parent 4af15aa6a9
commit dd8ba562d2
4 files changed
+88 -1

No files matched your search

+21
View File
@@ -5,6 +5,7 @@ import {
areaContains,
distanceKm,
lineTouchesArea,
polygonsTouchArea,
resolveArea,
} from './area.js';
import { placeFromGeocodeResult } from './places.js';
@@ -224,3 +225,23 @@ test('lines touch an area when a segment crosses it with no vertex inside', asyn
),
);
});
test('polygons touch an area by vertex, crossing edge or enclosing it', async () => {
const box = await resolveArea({ bbox: [-1, -1, 1, 1] });
const square = (half, x = 0) => [
[
[x - half, -half],
[x + half, -half],
[x + half, half],
[x - half, half],
],
];
assert.ok(polygonsTouchArea([square(5)], box), 'encloses the area');
assert.ok(polygonsTouchArea([square(0.5)], box), 'inside the area');
assert.ok(polygonsTouchArea([square(1, 1.5)], box), 'overlaps an edge');
assert.ok(!polygonsTouchArea([square(0.5, 5)], box), 'elsewhere');
const ring = [...square(5), ...square(3)];
assert.ok(!polygonsTouchArea([ring], box), 'the area sits in a hole');
const circle = await resolveArea({ lat: 0, lon: 0, radius_km: 20 });
assert.ok(polygonsTouchArea([square(5)], circle));
});