-
Notifications
You must be signed in to change notification settings - Fork 1
/
MPPoint.ts
164 lines (152 loc) · 3.98 KB
/
MPPoint.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import MPGeometry from "./MPGeometry";
import MPUtils from "./MPUtils";
/**
* MPPoint is a representation of {@link latitude} and {@link longitude} coordinates packaged with
* a Z-axis representation in {@link floorIndex}.
*
* @export
* @class MPPoint
* @typedef {MPPoint}
* @extends {MPGeometry}
*/
export default class MPPoint extends MPGeometry {
/**
* Latitude coordinate.
*
* @public
* @readonly
* @type {number}
*/
public readonly latitude: number;
/**
* Longitude coordinate.
*
* @public
* @readonly
* @type {number}
*/
public readonly longitude: number;
/**
* Optional index that defines what floor this point is placed on.
*
* If 0 it is placed on the ground floor, or outside.
*
* @public
* @readonly
* @type {?number}
*/
public readonly floorIndex?: number;
/**
* Creates an instance of MPPoint.
*
* @constructor
* @public
* @param {number} latitude The position of the point on the latitudal axis (N/S).
* @param {number} longitude The position of the point on the longitudal axis (E/W).
* @param {number} [floorIndex=0] The floor index of the point, Will default to 0 if not provided.
*/
public constructor(latitude: number, longitude: number, floorIndex: number = 0) {
super();
this.latitude = latitude;
this.longitude = longitude;
this.floorIndex = floorIndex;
}
/**
* Creator for MPPoint, used to decode JSON from the MapsIndoors SDK.
*
* @public
* @static
* @param {MPPointParams} pointParams
* @returns {MPPoint}
*/
public static create(pointParams: MPPointParams): MPPoint | undefined {
if (pointParams?.coordinates) {
return new MPPoint(pointParams.coordinates[1], pointParams.coordinates[0], pointParams.coordinates[2]);
} else if (pointParams as unknown as number[]){
const pp = pointParams as unknown as number[]
return new MPPoint(pp[1], pp[0], pp[2]);
}else {
return null;
}
}
/**
* Calculates the angle between this point and another [MPPoint] in degrees from north.
*
* @public
* @async
* @param {MPPoint} other
* @returns {Promise<number>}
*/
public async angleBetween(other: MPPoint): Promise<number> {
return MPUtils.pointAngleBetween(this, other);
}
/**
* Calculates the shortest distance to another point from this point.
*
* @public
* @async
* @param {MPPoint} other
* @returns {Promise<number>}
*/
public async distanceTo(other: MPPoint): Promise<number> {
return MPUtils.pointDistanceTo(this, other);
}
/**
* {@link MPGeometry} override, returns this object.
*
* @public
* @readonly
* @type {MPPoint}
*/
public get position(): MPPoint {
return this;
}
/**
* Get the type of the point. see {@link MPGeometry#point}.
*
* @public
* @readonly
* @type {string}
*/
public get type(): string {
return MPGeometry.point;
}
/**
* {@link MPGeometry} override, resolves to a non-zero value.
*
* @public
* @async
* @returns {Promise<number>}
*/
public async getArea(): Promise<number> {
return Promise.resolve(0.5);
}
/**
* Parses the object to a JSON object that is compatible with the MapsIndoors SDK.
*
* @public
* @returns {MPPointParams}
*/
public toJSON(): MPPointParams {
return {
coordinates: [this.longitude, this.latitude, this.floorIndex ?? 0],
};
}
}
/**
* Parameter interface for {@link MPPoint}.
*
* @export
* @interface MPPointParams
* @typedef {MPPointParams}
*/
export interface MPPointParams {
/**
* Coordinate holder for point, on the form:.
*
* [LNG, LAT, FLOOR]
*
* @type {number[]}
*/
coordinates: number[],
}