49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { IGeodesic } from '../interfaces/geodesic.interface';
|
|
import { Point } from '../types/point.type';
|
|
import { SpacetimePoint } from './spacetime-point';
|
|
|
|
export class Route {
|
|
distance: number;
|
|
duration: number;
|
|
fwdAzimuth: number;
|
|
backAzimuth: number;
|
|
distanceAzimuth: number;
|
|
points: Point[];
|
|
spacetimePoints: SpacetimePoint[];
|
|
private geodesic: IGeodesic;
|
|
|
|
constructor(geodesic: IGeodesic) {
|
|
this.distance = undefined;
|
|
this.duration = undefined;
|
|
this.fwdAzimuth = undefined;
|
|
this.backAzimuth = undefined;
|
|
this.distanceAzimuth = undefined;
|
|
this.points = [];
|
|
this.spacetimePoints = [];
|
|
this.geodesic = geodesic;
|
|
}
|
|
|
|
setPoints = (points: Point[]): void => {
|
|
this.points = points;
|
|
this.setAzimuth(points);
|
|
};
|
|
|
|
setSpacetimePoints = (spacetimePoints: SpacetimePoint[]): void => {
|
|
this.spacetimePoints = spacetimePoints;
|
|
};
|
|
|
|
protected setAzimuth = (points: Point[]): 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;
|
|
};
|
|
}
|