grid-map 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = GridMap
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ task :default => :test
5
+
6
+ desc "Run all tests"
7
+ task :test do
8
+ exec "rspec --color"
9
+ end
@@ -0,0 +1,3 @@
1
+ module GridMap
2
+ VERSION = "0.0.1"
3
+ end
data/lib/grid-map.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'mathn'
2
+
3
+ module GridMap
4
+
5
+ EARTH_RADIUS = 6378137 # meters
6
+
7
+ def self.to_rad angle
8
+ angle/180 * Math::PI
9
+ end
10
+
11
+ def self.distance lat1, lon1, lat2, lon2
12
+ Math::acos(
13
+ (Math::sin(to_rad(lat1)) * Math::sin(to_rad(lat2))) +
14
+ (Math::cos(to_rad(lat1)) * Math::cos(to_rad(lat2))) * Math::cos(to_rad(lon2)-to_rad(lon1))
15
+ ) * EARTH_RADIUS
16
+ end
17
+
18
+ def self.square radius, lat, lon, array = false
19
+ r = radius*2/3
20
+ x = (distance(lat, lon, 90, 0)/r).ceil
21
+ y = (distance(lat, lon, 0, 180)/r).ceil
22
+ [x, y] if array
23
+ {x: x, y: y}
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :grid-map do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,114 @@
1
+ root = File.expand_path('../..', __FILE__)
2
+ require File.join(root, %w[lib grid-map])
3
+
4
+ require 'mathn'
5
+
6
+ describe GridMap do
7
+ describe "to_rad" do
8
+ it "should be 0" do
9
+ GridMap::to_rad(0).should == 0
10
+ end
11
+
12
+ it "should be PI" do
13
+ GridMap::to_rad(180).should == Math::PI
14
+ end
15
+
16
+ it "should be 2PI" do
17
+ GridMap::to_rad(360).should == 2*Math::PI
18
+ end
19
+ end
20
+
21
+ describe "distance" do
22
+ it "should be 0" do
23
+ GridMap::distance(0, 0, 0, 0).ceil.should == 0
24
+ end
25
+
26
+ it "should be 0" do
27
+ GridMap::distance(45, 90, 45, 90).ceil.should == 0
28
+ end
29
+
30
+ it "should be 0" do
31
+ GridMap::distance(90, 180, 90, 180).ceil.should == 0
32
+ end
33
+
34
+ it "should be 10018754" do
35
+ GridMap::distance(0, 0, 90, 180).ceil.should == 10018755
36
+ end
37
+
38
+ it "should be 10018754" do
39
+ GridMap::distance(0, 0, 90, 0).ceil.should == 10018755
40
+ end
41
+
42
+ it "should be 20037508" do
43
+ GridMap::distance(0, 0, 0, 180).ceil.should == 20037509
44
+ end
45
+ end
46
+
47
+ describe "square" do
48
+ it "should be [500938, 1001876]" do
49
+ GridMap::square(30, 0, 0)[:x].should == 500938
50
+ GridMap::square(30, 0, 0)[:y].should == 1001876
51
+ end
52
+
53
+ it "should be [0, 500938]" do
54
+ GridMap::square(30, 90, 0)[:x].should == 0
55
+ GridMap::square(30, 90, 0)[:y].should == 500938
56
+ end
57
+
58
+ it "should be [500938, 0]" do
59
+ GridMap::square(30, 0, 180)[:x].should == 500938
60
+ GridMap::square(30, 0, 180)[:y].should == 0
61
+ end
62
+
63
+ it "should be [0, 500938]" do
64
+ GridMap::square(30, 90, 180)[:x].should == 0
65
+ GridMap::square(30, 90, 180)[:y].should == 500938
66
+ end
67
+
68
+ it "should be [300563, 601126]" do
69
+ GridMap::square(50, 0, 0)[:x].should == 300563
70
+ GridMap::square(50, 0, 0)[:y].should == 601126
71
+ end
72
+
73
+ it "should be [150282, 300563]" do
74
+ GridMap::square(100, 0, 0)[:x].should == 150282
75
+ GridMap::square(100, 0, 0)[:y].should == 300563
76
+ end
77
+
78
+ it "should be [75141, 150282]" do
79
+ GridMap::square(200, 0, 0)[:x].should == 75141
80
+ GridMap::square(200, 0, 0)[:y].should == 150282
81
+ end
82
+
83
+ it "should be [50094, 100188]" do
84
+ GridMap::square(300, 0, 0)[:x].should == 50094
85
+ GridMap::square(300, 0, 0)[:y].should == 100188
86
+ end
87
+
88
+ it "should be [30057, 60113]" do
89
+ GridMap::square(500, 0, 0)[:x].should == 30057
90
+ GridMap::square(500, 0, 0)[:y].should == 60113
91
+ end
92
+
93
+ it "should be [15029, 30057]" do
94
+ GridMap::square(1000, 0, 0)[:x].should == 15029
95
+ GridMap::square(1000, 0, 0)[:y].should == 30057
96
+ end
97
+
98
+ it "should be [7515, 15029]" do
99
+ GridMap::square(2000, 0, 0)[:x].should == 7515
100
+ GridMap::square(2000, 0, 0)[:y].should == 15029
101
+ end
102
+
103
+ it "should be [5010, 10019]" do
104
+ GridMap::square(3000, 0, 0)[:x].should == 5010
105
+ GridMap::square(3000, 0, 0)[:y].should == 10019
106
+ end
107
+
108
+ it "should be [3006, 6012]" do
109
+ GridMap::square(5000, 0, 0)[:x].should == 3006
110
+ GridMap::square(5000, 0, 0)[:y].should == 6012
111
+ end
112
+
113
+ end
114
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grid-map
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Miguel Adolfo Barroso
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.7.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.7.0
30
+ description: Description of GridMap.
31
+ email:
32
+ - mabarroso
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/grid-map/version.rb
38
+ - lib/tasks/grid-map_tasks.rake
39
+ - lib/grid-map.rb
40
+ - MIT-LICENSE
41
+ - Rakefile
42
+ - README.rdoc
43
+ - spec/grid-map_spec.rb
44
+ homepage: https://github.com/mabarroso/grid-map
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 1.8.24
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Summary of GridMap.
68
+ test_files:
69
+ - spec/grid-map_spec.rb