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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed536b8bf5290792069be154595f80c905433157
4
- data.tar.gz: 09af4b468561369f8b9c7b41d275d5e22d826083
3
+ metadata.gz: 5096166b267e94e2c95955b0e28fede57d76f4da
4
+ data.tar.gz: 4c68dfcaa423c772a6bdbae8eab21fbad0c82cb0
5
5
  SHA512:
6
- metadata.gz: 3abbbb9ea956b9681f9c30f1125bc8d597a1a0c874ee7b208d14836fc513378e77e5a56fd59c8175bea8e5fd537fbf12bafe52aaaed80ff5bc186dc8d777708c
7
- data.tar.gz: 983a583aa804672d815b4a5fd93cde5c3756e0dfb4827e1adc400c6df2fb7cd1676f2f8b03d7d397e47af3c17826261709092fca831cea49574fe944fae9a2bf
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 void
65
- wgs84_make_dms(double val, char *buf)
64
+ static VALUE
65
+ wgs84_as_deg(VALUE klass, VALUE arg)
66
66
  {
67
- char *ptr;
67
+ double val;
68
68
 
69
- sprintf(buf, "%d ", (int) trunc(val));
70
- ptr = buf + strlen(buf);
71
- sprintf(ptr, "%d ", (int) fmod(trunc(fabs(val) * 60.0), 60.0));
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
- wgs84_as_deg(VALUE klass, VALUE arg)
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 rb_float_new(val);
89
+ return rb_str_new2(buf);
85
90
  }
86
91
 
87
92
 
88
93
  static VALUE
89
- wgs84_as_dms(VALUE klass, VALUE arg)
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
- wgs84_make_dms(val, buf);
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);
@@ -1,3 +1,3 @@
1
1
  module GeodesicWgs84
2
- VERSION = "1.32.13"
2
+ VERSION = "1.32.14"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geodesic_wgs84
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.32.13
4
+ version: 1.32.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volker Wiegand