diff --git a/apps/planner/app/lib/brouter.ts b/apps/planner/app/lib/brouter.ts index b772c3c..4e0bfd6 100644 --- a/apps/planner/app/lib/brouter.ts +++ b/apps/planner/app/lib/brouter.ts @@ -52,7 +52,7 @@ export async function computeRoute(request: RouteRequest): Promise): Map { - const pts = area.points; - if (pts.length === 0) return null; - // Centroid - const cLat = pts.reduce((s, p) => s + p.lat, 0) / pts.length; - const cLon = pts.reduce((s, p) => s + p.lon, 0) / pts.length; - // Max distance from centroid in meters (approximate) - const maxDist = Math.max( - ...pts.map((p) => haversineMeters(cLat, cLon, p.lat, p.lon)), - ); - return `${cLon},${cLat},${Math.ceil(maxDist)}`; + if (area.points.length < 3) return null; + return area.points.map((p) => `${p.lon},${p.lat}`).join(","); }) .filter(Boolean) .join("|"); } -function haversineMeters(lat1: number, lon1: number, lat2: number, lon2: number): number { - const R = 6371000; - const dLat = ((lat2 - lat1) * Math.PI) / 180; - const dLon = ((lon2 - lon1) * Math.PI) / 180; - const a = - Math.sin(dLat / 2) ** 2 + - Math.cos((lat1 * Math.PI) / 180) * - Math.cos((lat2 * Math.PI) / 180) * - Math.sin(dLon / 2) ** 2; - return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); -} - export function getBRouterUrl(): string { return BROUTER_URL; } diff --git a/openspec/specs/no-go-areas/spec.md b/openspec/specs/no-go-areas/spec.md index 91dfdb0..dd6bfe4 100644 --- a/openspec/specs/no-go-areas/spec.md +++ b/openspec/specs/no-go-areas/spec.md @@ -9,7 +9,8 @@ Users SHALL be able to draw polygons on the map that BRouter avoids when computi #### Scenario: Route avoids no-go area - **WHEN** a route is computed and a no-go area intersects the direct path -- **THEN** BRouter routes around the no-go area +- **THEN** BRouter request includes the polygon vertices via the `polygons` parameter +- **AND** BRouter routes around the no-go area #### Scenario: Delete no-go area - **WHEN** a user deletes a no-go area polygon