-
Notifications
You must be signed in to change notification settings - Fork 0
/
dogma.ts
73 lines (59 loc) · 1.92 KB
/
dogma.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
/* This is free and unencumbered software released into the public domain. */
export class Angle {
private readonly _radians: number;
public constructor(radians: number) {
this._radians = radians;
}
public static fromDegrees(degrees: number): Angle {
return new Angle(degrees / 180 * Math.PI);
}
public static fromRadians(radians: number): Angle {
return new Angle(radians);
}
public static fromTurns(turns: number): Angle {
return new Angle(turns * 2 * Math.PI);
}
public get degrees(): number {
return this._radians / Math.PI * 180;
}
public get radians(): number {
return this._radians;
}
public get turns(): number {
return this._radians / (2 * Math.PI);
}
}
export class Latitude extends Angle {
public static readonly MIN_DEGREES: number = -90;
public static readonly MAX_DEGREES: number = 90;
public constructor(degrees: number) {
if (degrees < Latitude.MIN_DEGREES) {
throw new RangeError(`Latitude bounds are ±90°, but got ${degrees}°`);
}
if (degrees > Latitude.MAX_DEGREES) {
throw new RangeError(`Latitude bounds are ±90°, but got ${degrees}°`);
}
super(degrees / 180 * Math.PI);
}
}
export class Longitude extends Angle {
public static readonly MIN_DEGREES: number = -180;
public static readonly MAX_DEGREES: number = 180;
public constructor(degrees: number) {
if (degrees < Longitude.MIN_DEGREES) {
throw new RangeError(`Longitude bounds are ±180°, but got ${degrees}°`);
}
if (degrees > Longitude.MAX_DEGREES) {
throw new RangeError(`Longitude bounds are ±180°, but got ${degrees}°`);
}
super(degrees / 180 * Math.PI);
}
}
export class Location {
public readonly latitude: Latitude;
public readonly longitude: Longitude;
public constructor(latitude: number, longitude: number) {
this.latitude = new Latitude(latitude);
this.longitude = new Longitude(longitude);
}
}