feat(routing): increase tolerance for off-route
This commit is contained in:
@ -178,7 +178,7 @@ async function tickRoute() {
|
||||
}
|
||||
|
||||
// Check if the user is on the route
|
||||
if (!isOnShape(loc, polyline)) {
|
||||
if (!isOnShape(loc, polyline, 30)) {
|
||||
console.log("Off route!");
|
||||
if (!info.isOffRoute) {
|
||||
say(m["routing.off-route"]());
|
||||
@ -303,9 +303,10 @@ function isOnLine(
|
||||
location: WorldLocation,
|
||||
from: WorldLocation,
|
||||
to: WorldLocation,
|
||||
toleranceMeters = 12,
|
||||
) {
|
||||
// Convert the 12-meter tolerance to degrees (approximation)
|
||||
const tolerance = 12 / 111320; // 1 degree latitude ≈ 111.32 km
|
||||
// Convert the tolerance to degrees (approximation)
|
||||
const tolerance = toleranceMeters / 111320; // 1 degree latitude ≈ 111.32 km
|
||||
|
||||
// Calculate the vector components
|
||||
const dx = to.lon - from.lon;
|
||||
@ -347,10 +348,9 @@ function isOnPoint(location: WorldLocation, point: WorldLocation) {
|
||||
return distance <= tolerance;
|
||||
}
|
||||
|
||||
function isOnShape(location: WorldLocation, shape: WorldLocation[]) {
|
||||
// Check if the location is on the line between from and to (3 meter tolerance)
|
||||
function isOnShape(location: WorldLocation, shape: WorldLocation[], toleranceMeters = 12) {
|
||||
for (let i = 0; i < shape.length - 1; i++) {
|
||||
if (isOnLine(location, shape[i], shape[i + 1])) {
|
||||
if (isOnLine(location, shape[i], shape[i + 1], toleranceMeters)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user