spherical_mercator 1.1.1 → 1.2.0
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/.travis.yml +2 -1
- data/lib/spherical_mercator/version.rb +2 -2
- data/lib/spherical_mercator.rb +4 -3
- data/spec/spherical_mercator/spherical_mercator_spec.rb +17 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dbf43b62894c3f78d1428ca447dcbfed50177cd5d0a42c960bbd3083d908990
|
4
|
+
data.tar.gz: d0426320d9ad903a88ea1bcac75d799940290766e070a7ae7491cd44a774d193
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 783046478b7cfc59ce43d505da9283b1f179b56b4876a65886658a447f64125f066389a63f0ca322ef7837801cf2fd1f307e616c458a1f8374647000fbb28486
|
7
|
+
data.tar.gz: beb53639950ecf4a1a2619bb8d66b1fd34a96e37da1fb0055d7fadc1692343cbde9e91fce02a075e05e290858adc348239098436a59ed7789f4dadcbab37df71
|
data/.travis.yml
CHANGED
data/lib/spherical_mercator.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spherical_mercator/version'
|
|
3
3
|
class SphericalMercator
|
4
4
|
|
5
5
|
attr_reader :options
|
6
|
-
attr_accessor :size, :round
|
6
|
+
attr_accessor :size, :round, :expansion
|
7
7
|
|
8
8
|
# Closures including constants and other precalculated values.
|
9
9
|
|
@@ -25,6 +25,7 @@ class SphericalMercator
|
|
25
25
|
@options = opts || {}
|
26
26
|
|
27
27
|
self.size = (options[:size] || 256).to_f
|
28
|
+
self.expansion = (options[:antimeridian] == true) ? 2 : 1
|
28
29
|
# Whether to round output values for integer zoom levels. Defaults to true.
|
29
30
|
self.round = (options[:round].nil?) ? true : options[:round]
|
30
31
|
|
@@ -74,7 +75,7 @@ class SphericalMercator
|
|
74
75
|
f = [[Math.sin(D2R * lon_lat[1]), -0.9999].max, 0.9999].min
|
75
76
|
x = d + lon_lat[0] * bc
|
76
77
|
y = d + 0.5 * Math.log((1 + f) / (1 - f)) * -cc
|
77
|
-
(x > ac) && (x = ac)
|
78
|
+
(x > ac * self.expansion) && (x = ac * self.expansion)
|
78
79
|
(y > ac) && (y = ac)
|
79
80
|
# (x < 0) && (x = 0)
|
80
81
|
# (y < 0) && (y = 0)
|
@@ -85,7 +86,7 @@ class SphericalMercator
|
|
85
86
|
f = [[Math.sin(D2R * lon_lat[1]), -0.9999].max, 0.9999].min
|
86
87
|
x = (d + lon_lat[0] * @bc[zoom]).round
|
87
88
|
y = (d + 0.5 * Math.log((1 + f) / (1 - f)) * (-@cc[zoom])).round
|
88
|
-
(x > @ac[zoom]) && (x = @ac[zoom])
|
89
|
+
(x > @ac[zoom] * self.expansion) && (x = @ac[zoom] * self.expansion)
|
89
90
|
(y > @ac[zoom]) && (y = @ac[zoom])
|
90
91
|
|
91
92
|
# (x < 0) && (x = 0)
|
@@ -19,6 +19,7 @@ end
|
|
19
19
|
describe SphericalMercator do
|
20
20
|
let!(:sm) { SphericalMercator.new }
|
21
21
|
let!(:sm_round) { SphericalMercator.new(round: false) }
|
22
|
+
let!(:antiM) { SphericalMercator.new(antimeridian: true) }
|
22
23
|
|
23
24
|
context '#bbox' do
|
24
25
|
it '[0,0,0] converted to proper bbox' do
|
@@ -122,6 +123,22 @@ describe SphericalMercator do
|
|
122
123
|
it 'PX with forced rounding' do
|
123
124
|
expect(sm_round.px([-179, 85], 9)).to eq([364.0888888888876, 214.68476683766494])
|
124
125
|
end
|
126
|
+
|
127
|
+
it 'Clamps PX by default when lon >180' do
|
128
|
+
expect(sm.px([250, 3], 4)).to eq([4096, 2014])
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'PX with lon > 180 converts when antimeridian=true' do
|
132
|
+
expect(antiM.px([250, 3], 4)).to eq([4892, 2014])
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'PX for lon 360 and antimeridian=true' do
|
136
|
+
expect(antiM.px([400, 3], 4)).to eq([6599, 2014])
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'Clamps PX when lon >360 and antimeridian=true' do
|
140
|
+
expect(antiM.px([400, 3], 4)).to eq([6599, 2014])
|
141
|
+
end
|
125
142
|
end
|
126
143
|
|
127
144
|
context 'high precision float' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spherical_mercator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Bulai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -63,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
|
-
|
67
|
-
rubygems_version: 2.7.9
|
66
|
+
rubygems_version: 3.0.8
|
68
67
|
signing_key:
|
69
68
|
specification_version: 4
|
70
69
|
summary: Spherical Mercator math in Ruby
|