forked from otto-dev/coordinate-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coordinate-number.js
111 lines (96 loc) · 3.22 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
109
110
111
// Generated by CoffeeScript 1.10.0
var CoordinateNumber;
CoordinateNumber = (function() {
function CoordinateNumber(coordinateNumbers) {
coordinateNumbers = this.normalizeCoordinateNumbers(coordinateNumbers);
this.degrees = coordinateNumbers[0], this.minutes = coordinateNumbers[1], this.seconds = coordinateNumbers[2], this.milliseconds = coordinateNumbers[3];
this.sign = this.normalizedSignOf(this.degrees);
this.degrees = Math.abs(this.degrees);
}
CoordinateNumber.prototype.normalizeCoordinateNumbers = function(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;
};
CoordinateNumber.prototype.normalizedSignOf = function(number) {
if (number >= 0) {
return 1;
} else {
return -1;
}
};
CoordinateNumber.prototype.detectSpecialFormats = function() {
if (this.degreesCanBeSpecial()) {
if (this.degreesCanBeMilliseconds()) {
return this.degreesAsMilliseconds();
} else if (this.degreesCanBeDegreesMinutesAndSeconds()) {
return this.degreesAsDegreesMinutesAndSeconds();
} else if (this.degreesCanBeDegreesAndMinutes()) {
return this.degreesAsDegreesAndMinutes();
}
}
};
CoordinateNumber.prototype.degreesCanBeSpecial = function() {
var canBe;
canBe = false;
if (!this.minutes && !this.seconds) {
canBe = true;
}
return canBe;
};
CoordinateNumber.prototype.degreesCanBeMilliseconds = function() {
var canBe;
if (this.degrees > 909090) {
canBe = true;
} else {
canBe = false;
}
return canBe;
};
CoordinateNumber.prototype.degreesAsMilliseconds = function() {
this.milliseconds = this.degrees;
return this.degrees = 0;
};
CoordinateNumber.prototype.degreesCanBeDegreesMinutesAndSeconds = function() {
var canBe;
if (this.degrees > 9090) {
canBe = true;
} else {
canBe = false;
}
return canBe;
};
CoordinateNumber.prototype.degreesAsDegreesMinutesAndSeconds = function() {
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;
};
CoordinateNumber.prototype.degreesCanBeDegreesAndMinutes = function() {
var canBe;
if (this.degrees > 360) {
canBe = true;
} else {
canBe = false;
}
return canBe;
};
CoordinateNumber.prototype.degreesAsDegreesAndMinutes = function() {
var newDegrees;
newDegrees = Math.floor(this.degrees / 100);
this.minutes = this.degrees - newDegrees * 100;
return this.degrees = newDegrees;
};
CoordinateNumber.prototype.toDecimal = function() {
var decimalCoordinate;
decimalCoordinate = this.sign * (this.degrees + this.minutes / 60 + this.seconds / 3600 + this.milliseconds / 3600000);
return decimalCoordinate;
};
return CoordinateNumber;
})();
module.exports = CoordinateNumber;