import { ICoordinates, IEntityWithId, IEntityWithTimestamp } from "./SharedEntities"; export interface IRoute extends IEntityWithId, IEntityWithTimestamp { name: string; color: string; polylineCoordinates: ICoordinates[]; systemId: string; } export interface IStop extends IEntityWithId, IEntityWithTimestamp { name: string; systemId: string; coordinates: ICoordinates; } export interface IShuttle extends IEntityWithId, IEntityWithTimestamp { coordinates: ICoordinates; name: string; routeId: string; systemId: string; orientationInDegrees: number; } export interface IEta extends IEntityWithTimestamp { secondsRemaining: number; shuttleId: string; stopId: string; systemId: string; } export interface IOrderedStop extends IEntityWithTimestamp { nextStop?: IOrderedStop; previousStop?: IOrderedStop; routeId: string; stopId: string; position: number; 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; }