mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
Add a method to check whether a shuttle has arrived at a stop
This commit is contained in:
@@ -37,3 +37,15 @@ export interface IOrderedStop extends IEntityWithTimestamp {
|
||||
systemId: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a shuttle has arrived at a stop based on coordinate proximity.
|
||||
* Uses a threshold of 0.001 degrees (~111 meters at the equator).
|
||||
*/
|
||||
export function shuttleHasArrivedAtStop(shuttle: IShuttle, stop: IStop) {
|
||||
const isWithinLatitudeRange = shuttle.coordinates.latitude > stop.coordinates.latitude - 0.001
|
||||
&& shuttle.coordinates.latitude < stop.coordinates.latitude + 0.001;
|
||||
const isWithinLongitudeRange = shuttle.coordinates.longitude > stop.coordinates.longitude - 0.001
|
||||
&& shuttle.coordinates.longitude < stop.coordinates.longitude + 0.001
|
||||
return isWithinLatitudeRange && isWithinLongitudeRange;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user