spherical_mercator 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2c25752283cbaf577010569270ec2ca240d97a62
4
- data.tar.gz: f2aecd50cd93e790880921c098216008574f8853
2
+ SHA256:
3
+ metadata.gz: 665ccb30651f974478815cbfc896ee76d310c99c9bf270378c2078033bb4da0c
4
+ data.tar.gz: 8406e7fa6f88d8812e6ccd355a1ccbf67a805fb8a74665ac28a1a0945b0b6eb7
5
5
  SHA512:
6
- metadata.gz: adfdd9971e141456233f590684c200ae7577917402ca6ff31559dd8f235b3c72958ec893e166cfb67963475b2bd3dc0704bb7dfc55bcd5670719733df297ff86
7
- data.tar.gz: 1109a332fad241f5eecbf619ce2fbdfea81d411584c63c809693eaba2d75b95382a6d1f8453794b03b274af4375c4a0e5f5aaa5b65817dde14e98caad5ff72e3
6
+ metadata.gz: f3e834ae96fce835a4965040e1dd8696241d7222db5e275c4f61c7eec59b28cbec8e4f7a3a90e73b51e66ab0ca7bb6b1c9fda5396040bb84fa877d4574288cc5
7
+ data.tar.gz: 4e7a044bc20704dcf933dcd87ebfc5a1fcac1077fe2ac9ed1812d61d682a81f292d5ef020fe39850ca52a0a76d41fb67855065cd3eb8347c32c86bd792a1cab4
@@ -3,10 +3,11 @@ before_install: gem install bundler
3
3
  bundler_args: --without yard guard benchmarks
4
4
  script: "rake spec"
5
5
  rvm:
6
- - 2.0.0
7
- - 2.2.4
8
- - 2.3.3
9
- - 2.4.0
6
+ - 2.4
7
+ - 2.5
8
+ - 2.6
9
+ - 2.7
10
+ - 3.0
10
11
  - jruby-9.0.5.0
11
12
  - jruby-9.1.5.0
12
13
  - jruby-9.1.6.0
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Ruby port of Mapbox Spherical Mercator
2
2
  [![Gem Version](https://badge.fury.io/rb/spherical_mercator.svg)](http://badge.fury.io/rb/spherical_mercator)
3
3
  [![Build Status](https://travis-ci.org/nbulaj/spherical_mercator.svg?branch=master)](https://travis-ci.org/nbulaj/spherical_mercator)
4
- [![Dependency Status](https://gemnasium.com/nbulaj/spherical_mercator.svg)](https://gemnasium.com/nbulaj/spherical_mercator)
5
4
  [![Coverage Status](https://coveralls.io/repos/github/nbulaj/spherical_mercator/badge.svg)](https://coveralls.io/github/nbulaj/spherical_mercator)
6
5
  [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg)](#license)
7
6
 
@@ -32,6 +31,8 @@ Some datatypes are assumed to be arrays: `ll` is `[lon, lat]`, `xy` and `px` are
32
31
  ```ruby
33
32
  # By default, precomputes up to z30
34
33
  mercator = SphericalMercator.new(size: 256)
34
+ # Whether to round pixel values at integer zoom levels. Defaults to true.
35
+ mercator = SphericalMercator.new(round: false)
35
36
  ```
36
37
 
37
38
  ### `px(lon_lat, zoom)`
@@ -39,6 +40,8 @@ mercator = SphericalMercator.new(size: 256)
39
40
  Convert lon, lat to screen pixel x, y from 0, 0 origin, at a certain zoom level.
40
41
  The inverse of `ll`
41
42
 
43
+ Screen pixel values are rounded, unless the zoom level is a floating point value. To disable rounding on integer zoom levels, specify `round: false` when creating the SphericalMercator.
44
+
42
45
  ### `ll(px, zoom)`
43
46
 
44
47
  Convert screen pixel value to lon, lat, at a certain zoom level. The inverse
@@ -1,7 +1,10 @@
1
1
  require 'spherical_mercator/version'
2
2
 
3
3
  class SphericalMercator
4
+
4
5
  attr_reader :options
6
+ attr_accessor :size, :round
7
+
5
8
  # Closures including constants and other precalculated values.
6
9
 
7
10
  EPSLN = 1.0e-10
@@ -11,7 +14,7 @@ class SphericalMercator
11
14
  A = 6_378_137.0
12
15
  MAX_EXTENT = 20_037_508.342_789_244
13
16
 
14
- attr_accessor :size, :cache
17
+ attr_accessor :cache
15
18
 
16
19
  attr_accessor :ac, :bc, :cc, :zc
17
20
 
@@ -22,6 +25,8 @@ class SphericalMercator
22
25
  @options = opts || {}
23
26
 
24
27
  self.size = (options[:size] || 256).to_f
28
+ # Whether to round output values for integer zoom levels. Defaults to true.
29
+ self.round = (options[:round].nil?) ? true : options[:round]
25
30
 
26
31
  if cache[size].nil?
27
32
  size = self.size
@@ -60,7 +65,7 @@ class SphericalMercator
60
65
  # - `ll` {Array} `[lon, lat]` array of geographic coordinates.
61
66
  # - `zoom` {Number} zoom level.
62
67
  def px(lon_lat, zoom)
63
- if float?(zoom)
68
+ if float?(zoom) || !self.round
64
69
  size = @size * (2**zoom)
65
70
  d = size / 2
66
71
  bc = (size / 360)
@@ -9,7 +9,7 @@ class SphericalMercator
9
9
  # Minor version number
10
10
  MINOR = 1
11
11
  # Smallest version number
12
- TINY = 0
12
+ TINY = 1
13
13
 
14
14
  # Full version number
15
15
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
@@ -18,6 +18,7 @@ end
18
18
 
19
19
  describe SphericalMercator do
20
20
  let!(:sm) { SphericalMercator.new }
21
+ let!(:sm_round) { SphericalMercator.new(round: false) }
21
22
 
22
23
  context '#bbox' do
23
24
  it '[0,0,0] converted to proper bbox' do
@@ -117,6 +118,10 @@ describe SphericalMercator do
117
118
  it 'PX with float zoom value converts' do
118
119
  expect(sm.px([-179, 85], 8.6574)).to eq([287.12734093961626, 169.30444219392666])
119
120
  end
121
+
122
+ it 'PX with forced rounding' do
123
+ expect(sm_round.px([-179, 85], 9)).to eq([364.0888888888876, 214.68476683766494])
124
+ end
120
125
  end
121
126
 
122
127
  context 'high precision float' do
@@ -5,7 +5,6 @@ require 'spherical_mercator/version'
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'spherical_mercator'
7
7
  gem.version = SphericalMercator.gem_version
8
- gem.date = '2017-10-03'
9
8
  gem.summary = 'Spherical Mercator math in Ruby'
10
9
  gem.description = 'Spherical Mercator provides projection math for converting between mercator' \
11
10
  'meters, screen pixels (of 256x256 or configurable-size tiles), and latitude/longitude'
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.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Bulai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-03 00:00:00.000000000 Z
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  requirements: []
66
66
  rubyforge_project:
67
- rubygems_version: 2.6.11
67
+ rubygems_version: 2.7.9
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: Spherical Mercator math in Ruby