-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMPGeometry.ts
91 lines (87 loc) · 1.89 KB
/
MPGeometry.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
import MPPoint from "./MPPoint";
import MPPolygon from "./MPPolygon";
import MPMultiPolygon from "./MPMultiPolygon";
import MPUtils from "./MPUtils";
/**
* Superclass of all MapsIndoors geometry classes.
*
* @export
* @abstract
* @class MPGeometry
* @typedef {MPGeometry}
*/
export default abstract class MPGeometry {
/**
* Typename for {@link MPPoint}.
*
* @public
* @static
* @readonly
* @type {string}
*/
public static readonly point: string = "Point";
/**
* Typename for {@link MPPolygon}.
*
* @public
* @static
* @readonly
* @type {string}
*/
public static readonly polygon: string = "Polygon";
/**
* Typename for {@link MPMultiPolygon}.
*
* @public
* @static
* @readonly
* @type {string}
*/
public static readonly multiPolygon: string = "MultiPolygon";
/**
* Position of geometry, used as anchor for markers.
*
* @public
* @abstract
* @readonly
* @type {MPPoint}
*/
public abstract readonly position: MPPoint;
/**
* Type of geometry, see {@link point}.
*
* @public
* @abstract
* @readonly
* @type {string}
*/
public abstract readonly type: string;
/**
* Computes the area of the geometry.
*
* @public
* @abstract
* @returns {Promise<number>}
*/
public abstract getArea(): Promise<number>;
/**
* Checks whether a point is contained within the geometry.
*
* @public
* @async
* @param {MPPoint} point
* @returns {Promise<boolean>}
*/
public async contains(point: MPPoint): Promise<boolean> {
return MPUtils.geometryIsInside(point, this);
}
/**
* Stringifies the geometry to JSON.
*
* @public
* @returns {string}
*/
public toJson(): string {
return JSON.stringify(this);
}
}