geodesic_wgs84 1.32.13 → 1.32.14
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 +24 -14
- data/lib/geodesic_wgs84/version.rb +1 -1
- data/spec/geodesic_wgs84_spec.rb +21 -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: 5096166b267e94e2c95955b0e28fede57d76f4da
|
|
4
|
+
data.tar.gz: 4c68dfcaa423c772a6bdbae8eab21fbad0c82cb0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0ecde825e2fb0d054daa731125ebe82f6992f00f7790bfcd53ea1d6228ba5d78bf78e9aaee5e5cafe76a0405050797d0a2b2b746474ef875eefe1a2e864defb9
|
|
7
|
+
data.tar.gz: 8002c67ae0a928f3be2361e1588b542a4d789dbc6bdc6b45fb26b704a358b38c71eb7bc897bac4adbfa1d65305815a824eff85128e7c93a64bee8ee4689c9b01
|
|
@@ -61,40 +61,49 @@ wgs84_get_value(VALUE arg)
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
static
|
|
65
|
-
|
|
64
|
+
static VALUE
|
|
65
|
+
wgs84_as_deg(VALUE klass, VALUE arg)
|
|
66
66
|
{
|
|
67
|
-
|
|
67
|
+
double val;
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
ptr = buf + strlen(buf);
|
|
73
|
-
sprintf(ptr, "%.1lf", fmod(fabs(val) * 3600.0, 60.0));
|
|
69
|
+
val = wgs84_get_value(arg);
|
|
70
|
+
|
|
71
|
+
return rb_float_new(val);
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
|
|
77
75
|
static VALUE
|
|
78
|
-
|
|
76
|
+
wgs84_as_dms(VALUE klass, VALUE arg)
|
|
79
77
|
{
|
|
80
78
|
double val;
|
|
79
|
+
char buf[64], *ptr;
|
|
81
80
|
|
|
82
81
|
val = wgs84_get_value(arg);
|
|
82
|
+
memset(buf, 0, sizeof(buf));
|
|
83
|
+
sprintf(buf, "%d ", (int) trunc(val));
|
|
84
|
+
ptr = buf + strlen(buf);
|
|
85
|
+
sprintf(ptr, "%d ", (int) fmod(trunc(fabs(val) * 60.0), 60.0));
|
|
86
|
+
ptr = buf + strlen(buf);
|
|
87
|
+
sprintf(ptr, "%.1lf", fmod(fabs(val) * 3600.0, 60.0));
|
|
83
88
|
|
|
84
|
-
return
|
|
89
|
+
return rb_str_new2(buf);
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
|
|
88
93
|
static VALUE
|
|
89
|
-
|
|
94
|
+
wgs84_as_bigdec(VALUE klass, VALUE arg)
|
|
90
95
|
{
|
|
91
96
|
double val;
|
|
92
|
-
char buf[64];
|
|
97
|
+
char buf[64], *ptr;
|
|
93
98
|
|
|
94
99
|
val = wgs84_get_value(arg);
|
|
95
|
-
|
|
100
|
+
memset(buf, 0, sizeof(buf));
|
|
101
|
+
sprintf(buf, "%07.0lf", round(val * 1000000.0));
|
|
102
|
+
ptr = buf + (strlen(buf) - 6);
|
|
103
|
+
memmove(ptr + 1, ptr, 6);
|
|
104
|
+
*ptr = '.';
|
|
96
105
|
|
|
97
|
-
return rb_str_new2(buf);
|
|
106
|
+
return rb_funcall(rb_path2class("BigDecimal"), rb_intern("new"), 1, rb_str_new2(buf));
|
|
98
107
|
}
|
|
99
108
|
|
|
100
109
|
|
|
@@ -259,6 +268,7 @@ Init_geodesic_wgs84(void)
|
|
|
259
268
|
rb_define_method(cWGS84, "initialize", wgs84_init, 0);
|
|
260
269
|
rb_define_method(cWGS84, "as_deg", wgs84_as_deg, 1);
|
|
261
270
|
rb_define_method(cWGS84, "as_dms", wgs84_as_dms, 1);
|
|
271
|
+
rb_define_method(cWGS84, "as_bigdec", wgs84_as_bigdec, 1);
|
|
262
272
|
rb_define_method(cWGS84, "lat_lon", wgs84_lat_lon, -1);
|
|
263
273
|
rb_define_method(cWGS84, "distance", wgs84_distance, -1);
|
|
264
274
|
rb_define_method(cWGS84, "average", wgs84_average, 2);
|
data/spec/geodesic_wgs84_spec.rb
CHANGED
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
require 'minitest/autorun'
|
|
2
2
|
require 'geodesic_wgs84'
|
|
3
|
+
require 'bigdecimal'
|
|
3
4
|
|
|
4
5
|
class TestGeodesicWgs84 < MiniTest::Test
|
|
5
6
|
def setup
|
|
6
7
|
@wgs84 = Wgs84.new
|
|
7
8
|
end
|
|
8
9
|
|
|
10
|
+
def test_bigdec_1
|
|
11
|
+
assert_equal 50.833833, @wgs84.as_bigdec(50.833833).to_f
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_bigdec_2
|
|
15
|
+
assert_equal 50.833833, @wgs84.as_bigdec(50.8338332).to_f
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_bigdec_3
|
|
19
|
+
assert_equal 50.833834, @wgs84.as_bigdec(50.8338337).to_f
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_bigdec_4
|
|
23
|
+
assert_equal 0.0, @wgs84.as_bigdec(0).to_f
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_bigdec_5
|
|
27
|
+
assert_equal -1.0, @wgs84.as_bigdec(-1).to_f
|
|
28
|
+
end
|
|
29
|
+
|
|
9
30
|
def test_deg_as_deg
|
|
10
31
|
assert_equal 50.833833, @wgs84.as_deg(50.833833)
|
|
11
32
|
end
|