2023-04-25 15:49:47 +00:00
|
|
|
import { IGeodesic } from '../../../../geography/domain/interfaces/geodesic.interface';
|
2023-04-26 10:10:22 +00:00
|
|
|
import { Point } from '../../../../geography/domain/types/point.type';
|
2023-04-19 15:32:42 +00:00
|
|
|
import { SpacetimePoint } from './spacetime-point';
|
|
|
|
import { Waypoint } from './waypoint';
|
|
|
|
|
|
|
|
export class Route {
|
|
|
|
distance: number;
|
|
|
|
duration: number;
|
|
|
|
fwdAzimuth: number;
|
|
|
|
backAzimuth: number;
|
|
|
|
distanceAzimuth: number;
|
|
|
|
waypoints: Array<Waypoint>;
|
2023-04-20 13:52:01 +00:00
|
|
|
points: Array<Point>;
|
2023-04-19 15:32:42 +00:00
|
|
|
spacetimePoints: Array<SpacetimePoint>;
|
2023-04-21 15:17:14 +00:00
|
|
|
private geodesic: IGeodesic;
|
2023-04-19 15:32:42 +00:00
|
|
|
|
|
|
|
constructor(geodesic: IGeodesic) {
|
|
|
|
this.distance = undefined;
|
|
|
|
this.duration = undefined;
|
|
|
|
this.fwdAzimuth = undefined;
|
|
|
|
this.backAzimuth = undefined;
|
|
|
|
this.distanceAzimuth = undefined;
|
|
|
|
this.waypoints = [];
|
|
|
|
this.points = [];
|
|
|
|
this.spacetimePoints = [];
|
2023-04-21 15:17:14 +00:00
|
|
|
this.geodesic = geodesic;
|
2023-04-19 15:32:42 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 13:52:01 +00:00
|
|
|
setWaypoints = (waypoints: Array<Waypoint>): void => {
|
2023-04-19 15:32:42 +00:00
|
|
|
this.waypoints = waypoints;
|
2023-04-21 15:17:14 +00:00
|
|
|
this.setAzimuth(waypoints.map((waypoint) => waypoint.point));
|
2023-04-20 13:52:01 +00:00
|
|
|
};
|
2023-04-19 15:32:42 +00:00
|
|
|
|
2023-04-20 13:52:01 +00:00
|
|
|
setPoints = (points: Array<Point>): void => {
|
2023-04-19 15:32:42 +00:00
|
|
|
this.points = points;
|
2023-04-21 15:17:14 +00:00
|
|
|
this.setAzimuth(points);
|
2023-04-20 13:52:01 +00:00
|
|
|
};
|
2023-04-19 15:32:42 +00:00
|
|
|
|
2023-04-20 13:52:01 +00:00
|
|
|
setSpacetimePoints = (spacetimePoints: Array<SpacetimePoint>): void => {
|
2023-04-19 15:32:42 +00:00
|
|
|
this.spacetimePoints = spacetimePoints;
|
2023-04-20 13:52:01 +00:00
|
|
|
};
|
2023-04-19 15:32:42 +00:00
|
|
|
|
2023-04-21 15:17:14 +00:00
|
|
|
private setAzimuth = (points: Array<Point>): void => {
|
|
|
|
const inverse = this.geodesic.inverse(
|
2023-04-20 13:52:01 +00:00
|
|
|
points[0].lon,
|
|
|
|
points[0].lat,
|
|
|
|
points[points.length - 1].lon,
|
|
|
|
points[points.length - 1].lat,
|
2023-04-19 15:32:42 +00:00
|
|
|
);
|
|
|
|
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;
|
2023-04-20 13:52:01 +00:00
|
|
|
};
|
2023-04-19 15:32:42 +00:00
|
|
|
}
|