-
Notifications
You must be signed in to change notification settings - Fork 9
/
coordinate-number.js
108 lines (94 loc) · 2.68 KB
/
coordinate-number.js
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
// Generated by CoffeeScript 2.5.1
var CoordinateNumber;
CoordinateNumber = class CoordinateNumber {
constructor(coordinateNumbers) {
coordinateNumbers = this.normalizeCoordinateNumbers(coordinateNumbers);
this.sign = this.normalizedSignOf(coordinateNumbers[0]);
[this.degrees, this.minutes, this.seconds, this.milliseconds] = coordinateNumbers.map(Math.abs);
}
normalizeCoordinateNumbers(coordinateNumbers) {
var currentNumber, i, j, len, normalizedNumbers;
normalizedNumbers = [0, 0, 0, 0];
for (i = j = 0, len = coordinateNumbers.length; j < len; i = ++j) {
currentNumber = coordinateNumbers[i];
normalizedNumbers[i] = parseFloat(currentNumber);
}
return normalizedNumbers;
}
normalizedSignOf(number) {
if (number >= 0) {
return 1;
} else {
return -1;
}
}
detectSpecialFormats() {
if (this.degreesCanBeSpecial()) {
if (this.degreesCanBeMilliseconds()) {
return this.degreesAsMilliseconds();
} else if (this.degreesCanBeDegreesMinutesAndSeconds()) {
return this.degreesAsDegreesMinutesAndSeconds();
} else if (this.degreesCanBeDegreesAndMinutes()) {
return this.degreesAsDegreesAndMinutes();
}
}
}
degreesCanBeSpecial() {
var canBe;
canBe = false;
if (!this.minutes && !this.seconds) {
canBe = true;
}
return canBe;
}
degreesCanBeMilliseconds() {
var canBe;
if (this.degrees > 909090) {
canBe = true;
} else {
canBe = false;
}
return canBe;
}
degreesAsMilliseconds() {
this.milliseconds = this.degrees;
return this.degrees = 0;
}
degreesCanBeDegreesMinutesAndSeconds() {
var canBe;
if (this.degrees > 9090) {
canBe = true;
} else {
canBe = false;
}
return canBe;
}
degreesAsDegreesMinutesAndSeconds() {
var newDegrees;
newDegrees = Math.floor(this.degrees / 10000);
this.minutes = Math.floor((this.degrees - newDegrees * 10000) / 100);
this.seconds = Math.floor(this.degrees - newDegrees * 10000 - this.minutes * 100);
return this.degrees = newDegrees;
}
degreesCanBeDegreesAndMinutes() {
var canBe;
if (this.degrees > 360) {
canBe = true;
} else {
canBe = false;
}
return canBe;
}
degreesAsDegreesAndMinutes() {
var newDegrees;
newDegrees = Math.floor(this.degrees / 100);
this.minutes = this.degrees - newDegrees * 100;
return this.degrees = newDegrees;
}
toDecimal() {
var decimalCoordinate;
decimalCoordinate = this.sign * (this.degrees + this.minutes / 60 + this.seconds / 3600 + this.milliseconds / 3600000);
return decimalCoordinate;
}
};
module.exports = CoordinateNumber;