mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2025-12-31 08:22:41 +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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Coordinate } from '../entities/coordinate';
|
||||
|
||||
export interface IEncodeDirection {
|
||||
encode(coordinates: Coordinate[]): string;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export interface IGeodesic {
|
||||
inverse(
|
||||
lon1: number,
|
||||
lat1: number,
|
||||
lon2: number,
|
||||
lat2: number,
|
||||
): {
|
||||
azimuth: number;
|
||||
distance: number;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { IGeorouter } from './georouter.interface';
|
||||
|
||||
export interface ICreateGeorouter {
|
||||
create(type: string, url: string): IGeorouter;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { GeorouterSettings } from '../types/georouter-settings.type';
|
||||
import { NamedRoute } from '../types/named-route';
|
||||
import { Path } from '../types/path.type';
|
||||
|
||||
export interface IGeorouter {
|
||||
route(paths: Path[], settings: GeorouterSettings): Promise<NamedRoute[]>;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface IFindTimezone {
|
||||
timezones(lon: number, lat: number): string[];
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export type GeorouterSettings = {
|
||||
withPoints: boolean;
|
||||
withTime: boolean;
|
||||
withDistance: boolean;
|
||||
};
|
||||
6
old/modules/geography/domain/types/named-route.ts
Normal file
6
old/modules/geography/domain/types/named-route.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Route } from '../entities/route';
|
||||
|
||||
export type NamedRoute = {
|
||||
key: string;
|
||||
route: Route;
|
||||
};
|
||||
6
old/modules/geography/domain/types/path.type.ts
Normal file
6
old/modules/geography/domain/types/path.type.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Point } from './point.type';
|
||||
|
||||
export type Path = {
|
||||
key: string;
|
||||
points: Point[];
|
||||
};
|
||||
7
old/modules/geography/domain/types/point-type.enum.ts
Normal file
7
old/modules/geography/domain/types/point-type.enum.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export enum PointType {
|
||||
HOUSE_NUMBER = 'HOUSE_NUMBER',
|
||||
STREET_ADDRESS = 'STREET_ADDRESS',
|
||||
LOCALITY = 'LOCALITY',
|
||||
VENUE = 'VENUE',
|
||||
OTHER = 'OTHER',
|
||||
}
|
||||
6
old/modules/geography/domain/types/point.type.ts
Normal file
6
old/modules/geography/domain/types/point.type.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { PointType } from './point-type.enum';
|
||||
import { Coordinate } from '../entities/coordinate';
|
||||
|
||||
export type Point = Coordinate & {
|
||||
type?: PointType;
|
||||
};
|
||||
6
old/modules/geography/domain/types/timezoner.ts
Normal file
6
old/modules/geography/domain/types/timezoner.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { IFindTimezone } from '../interfaces/timezone-finder.interface';
|
||||
|
||||
export type Timezoner = {
|
||||
timezone: string;
|
||||
finder: IFindTimezone;
|
||||
};
|
||||
Reference in New Issue
Block a user