mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2025-12-31 10:02:42 +00:00
refactor to ddh, first commit
This commit is contained in:
19
old/modules/geography/domain/entities/coordinate.ts
Normal file
19
old/modules/geography/domain/entities/coordinate.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { AutoMap } from '@automapper/classes';
|
||||
import { IsLatitude, IsLongitude, IsNumber } from 'class-validator';
|
||||
|
||||
export class Coordinate {
|
||||
constructor(lon: number, lat: number) {
|
||||
this.lon = lon;
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
@IsNumber()
|
||||
@IsLongitude()
|
||||
@AutoMap()
|
||||
lon: number;
|
||||
|
||||
@IsNumber()
|
||||
@IsLatitude()
|
||||
@AutoMap()
|
||||
lat: number;
|
||||
}
|
||||
48
old/modules/geography/domain/entities/route.ts
Normal file
48
old/modules/geography/domain/entities/route.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
};
|
||||
}
|
||||
13
old/modules/geography/domain/entities/spacetime-point.ts
Normal file
13
old/modules/geography/domain/entities/spacetime-point.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Coordinate } from './coordinate';
|
||||
|
||||
export class SpacetimePoint {
|
||||
coordinate: Coordinate;
|
||||
duration: number;
|
||||
distance: number;
|
||||
|
||||
constructor(coordinate: Coordinate, duration: number, distance: number) {
|
||||
this.coordinate = coordinate;
|
||||
this.duration = duration;
|
||||
this.distance = distance;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user