geodesic_wgs84 1.32.8 → 1.32.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/geodesic_wgs84/geodesic_wgs84.c +41 -15
- data/lib/geodesic_wgs84/version.rb +1 -1
- data/spec/geodesic_wgs84_spec.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 38b320a18564a13c896c99ae9197afec51c6aed7
|
|
4
|
+
data.tar.gz: 12dc71705229f817c9cc7bbf0b160955547a2217
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d619778b1cf345ed9a373d9ec0b9a846855c29273d0811387aabfb5cec60662689c68ce3368cbad457537971531697c2bbae76da51c795e10eb8ccba1b57f72a
|
|
7
|
+
data.tar.gz: 0f6df837997db14480304ea1a6ee27fdfa7c5004313a7c2f9fc560eeec423e7280e9c56bb517ec4de45315eb015e36123d4c25f5f61f02ce0a337e67ca9b326f
|
|
@@ -63,6 +63,45 @@ wgs84_get_value(VALUE arg)
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
|
|
66
|
+
static void
|
|
67
|
+
wgs84_make_dms(double val, char *buf)
|
|
68
|
+
{
|
|
69
|
+
char *ptr;
|
|
70
|
+
|
|
71
|
+
sprintf(buf, "%d.", (int) trunc(val));
|
|
72
|
+
ptr = buf + strlen(buf);
|
|
73
|
+
sprintf(ptr, "%d.", (int) fmod(trunc(fabs(val) * 60.0), 60.0));
|
|
74
|
+
ptr = buf + strlen(buf);
|
|
75
|
+
sprintf(ptr, "%.1lf", fmod(fabs(val) * 3600.0, 60.0));
|
|
76
|
+
if ((ptr = strchr(ptr, '.')) != NULL)
|
|
77
|
+
*ptr = ',';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
static VALUE
|
|
82
|
+
wgs84_as_deg(VALUE klass, VALUE arg)
|
|
83
|
+
{
|
|
84
|
+
double val;
|
|
85
|
+
|
|
86
|
+
val = wgs84_get_value(arg);
|
|
87
|
+
|
|
88
|
+
return rb_float_new(val);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
static VALUE
|
|
93
|
+
wgs84_as_dms(VALUE klass, VALUE arg)
|
|
94
|
+
{
|
|
95
|
+
double val;
|
|
96
|
+
char buf[64];
|
|
97
|
+
|
|
98
|
+
val = wgs84_get_value(arg);
|
|
99
|
+
wgs84_make_dms(val, buf);
|
|
100
|
+
|
|
101
|
+
return rb_str_new2(buf);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
66
105
|
static VALUE
|
|
67
106
|
wgs84_lat_lon(int argc, VALUE *argv, VALUE klass)
|
|
68
107
|
{
|
|
@@ -87,21 +126,6 @@ wgs84_lat_lon(int argc, VALUE *argv, VALUE klass)
|
|
|
87
126
|
}
|
|
88
127
|
|
|
89
128
|
|
|
90
|
-
static void
|
|
91
|
-
wgs84_make_dms(double val, char *buf)
|
|
92
|
-
{
|
|
93
|
-
char *ptr;
|
|
94
|
-
|
|
95
|
-
sprintf(buf, "%d.", (int) trunc(val));
|
|
96
|
-
ptr = buf + strlen(buf);
|
|
97
|
-
sprintf(ptr, "%d.", (int) fmod(trunc(fabs(val) * 60.0), 60.0));
|
|
98
|
-
ptr = buf + strlen(buf);
|
|
99
|
-
sprintf(ptr, "%.1lf", fmod(fabs(val) * 3600.0, 60.0));
|
|
100
|
-
if ((ptr = strchr(ptr, '.')) != NULL)
|
|
101
|
-
*ptr = ',';
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
129
|
static VALUE
|
|
106
130
|
wgs84_lat_lon_dms(int argc, VALUE *argv, VALUE klass)
|
|
107
131
|
{
|
|
@@ -258,6 +282,8 @@ Init_geodesic_wgs84(void)
|
|
|
258
282
|
{
|
|
259
283
|
cWGS84 = rb_define_class("Wgs84", rb_cObject);
|
|
260
284
|
rb_define_method(cWGS84, "initialize", wgs84_init, 0);
|
|
285
|
+
rb_define_method(cWGS84, "as_deg", wgs84_as_deg, 1);
|
|
286
|
+
rb_define_method(cWGS84, "as_dms", wgs84_as_dms, 1);
|
|
261
287
|
rb_define_method(cWGS84, "lat_lon", wgs84_lat_lon, -1);
|
|
262
288
|
rb_define_method(cWGS84, "lat_lon_dms", wgs84_lat_lon_dms, -1);
|
|
263
289
|
rb_define_method(cWGS84, "distance", wgs84_distance, -1);
|
data/spec/geodesic_wgs84_spec.rb
CHANGED
|
@@ -6,6 +6,22 @@ class TestGeodesicWgs84 < MiniTest::Test
|
|
|
6
6
|
@wgs84 = Wgs84.new
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
def test_deg_as_deg
|
|
10
|
+
assert_equal 50.833833, @wgs84.as_deg(50.833833)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_dms_as_deg
|
|
14
|
+
assert_equal 50.833833, @wgs84.as_deg("50.50.01,8")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_deg_as_dms
|
|
18
|
+
assert_equal "50.50.1,8", @wgs84.as_dms(50.833833)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_dms_as_dms
|
|
22
|
+
assert_equal "50.50.1,8", @wgs84.as_dms("50.50.01,8")
|
|
23
|
+
end
|
|
24
|
+
|
|
9
25
|
def test_lat_lon_two_doubles
|
|
10
26
|
assert_equal [50.833833, 8.769333], @wgs84.lat_lon(50.833833, 8.769333)
|
|
11
27
|
end
|