2023-05-11 15:47:55 +00:00
|
|
|
import { IGeodesic } from '../interfaces/geodesic.interface';
|
|
|
|
import { Point } from '../types/point.type';
|
2023-04-19 15:32:42 +00:00
|
|
|
import { SpacetimePoint } from './spacetime-point';
|
|
|
|
|
|
|
|
export class Route {
|
|
|
|
distance: number;
|
|
|
|
duration: number;
|
|
|
|
fwdAzimuth: number;
|
|
|
|
backAzimuth: number;
|
|
|
|
distanceAzimuth: number;
|
2023-04-26 12:14:46 +00:00
|
|
|
points: Point[];
|
|
|
|
spacetimePoints: 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.points = [];
|
|
|
|
this.spacetimePoints = [];
|
2023-04-21 15:17:14 +00:00
|
|
|
this.geodesic = geodesic;
|
2023-04-19 15:32:42 +00:00
|
|
|
}
|
|
|
|
|
2023-04-26 12:14:46 +00:00
|
|
|
setPoints = (points: 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-26 12:14:46 +00:00
|
|
|
setSpacetimePoints = (spacetimePoints: 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-05-11 15:47:55 +00:00
|
|
|
protected setAzimuth = (points: Point[]): void => {
|
2023-04-21 15:17:14 +00:00
|
|
|
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
|
|
|
}
|