import { IGeodesic } from '../../../../geography/domain/interfaces/geodesic.interface'; import { Point } from '../../../../geography/domain/types/point.type'; import { SpacetimePoint } from './spacetime-point'; import { Waypoint } from './waypoint'; export class Route { distance: number; duration: number; fwdAzimuth: number; backAzimuth: number; distanceAzimuth: number; waypoints: Array; points: Array; spacetimePoints: Array; private geodesic: IGeodesic; constructor(geodesic: IGeodesic) { this.distance = undefined; this.duration = undefined; this.fwdAzimuth = undefined; this.backAzimuth = undefined; this.distanceAzimuth = undefined; this.waypoints = []; this.points = []; this.spacetimePoints = []; this.geodesic = geodesic; } setWaypoints = (waypoints: Array): void => { this.waypoints = waypoints; this.setAzimuth(waypoints.map((waypoint) => waypoint.point)); }; setPoints = (points: Array): void => { this.points = points; this.setAzimuth(points); }; setSpacetimePoints = (spacetimePoints: Array): void => { this.spacetimePoints = spacetimePoints; }; private setAzimuth = (points: Array): void => { const inverse = this.geodesic.inverse( points[0].lon, points[0].lat, points[points.length - 1].lon, points[points.length - 1].lat, ); this.fwdAzimuth = inverse.azimuth >= 0 ? inverse.azimuth : 360 - Math.abs(inverse.azimuth); this.backAzimuth = this.fwdAzimuth > 180 ? this.fwdAzimuth - 180 : this.fwdAzimuth + 180; this.distanceAzimuth = inverse.distance; }; }