cdistance 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59fe0e25378d182575643d32ece813daf5f0ff18
4
+ data.tar.gz: 373b946a520e4f0a846d485eea069888c9b173b8
5
+ SHA512:
6
+ metadata.gz: 81e8fc20aae6879ff3f42757dc07bbe18bb4c014d2bfb93e573fb8492aa675e0951763d13a8689a8215cecc8087c9dcba2e8b889e4ac5a3cc51605fb5ff0bfc0
7
+ data.tar.gz: e1c35c28c941bc9796263edae91fc609ec3b97f9602db9f10300f9638d20633e50520ad69003216ed058bd0e50abfd897784f79442031a6f88e28ac2aebfd4a0
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ Makefile
2
+ *.o
3
+ *.bundle
4
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cdistance.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cdistance (0.0.1)
5
+ ffi
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ffi (1.9.6)
11
+ rake (10.4.2)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.7)
18
+ cdistance!
19
+ rake (~> 10.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Cainã Costa
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Cdistance
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cdistance'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cdistance
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/cdistance/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/cdistance.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cdistance/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cdistance"
8
+ spec.version = Cdistance::VERSION
9
+ spec.authors = ["Cainã Costa"]
10
+ spec.email = ["cainan.costa@gmail.com"]
11
+ spec.summary = %q{Distance between two geographic points in pure C.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.require_paths = ["lib"]
17
+ spec.extensions = ["ext/cdistance/extconf.rb"]
18
+
19
+ spec.add_dependency "ffi"
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,35 @@
1
+ #include "distance.h"
2
+
3
+ GeoPoint make_GeoPoint(float x, float y) {
4
+ GeoPoint result;
5
+
6
+ result.lat = x;
7
+ result.lng = y;
8
+
9
+ return result;
10
+ };
11
+
12
+ GeoPoint to_radians(GeoPoint origin) {
13
+ float x, y;
14
+
15
+ x = origin.lat * (M_PI / 180);
16
+ y = origin.lng * (M_PI / 180);
17
+
18
+ return make_GeoPoint(x, y);
19
+ };
20
+
21
+ float distance_between(GeoPoint first_point, GeoPoint second_point) {
22
+ GeoPoint p1 = to_radians(first_point);
23
+ GeoPoint p2 = to_radians(second_point);
24
+
25
+ float delta_lat = p2.lat - p1.lat;
26
+ float delta_lng = p2.lng - p1.lng;
27
+
28
+ float a =
29
+ pow(sin(delta_lat / 2.0), 2.0) + cos(p1.lat) *
30
+ pow(sin(delta_lng / 2.0), 2.0)* cos(p2.lat);
31
+
32
+ float c = 2.0 * atan2(sqrt(a), sqrt(1.0 - a));
33
+
34
+ return c * EARTH_RADIUS;
35
+ };
@@ -0,0 +1,17 @@
1
+ #ifndef _H_DISTANCE
2
+ #define _H_DISTANCE
3
+
4
+ #include <math.h>
5
+ #include <stdio.h>
6
+
7
+ #define EARTH_RADIUS 6371.0
8
+
9
+ typedef struct {
10
+ float lat;
11
+ float lng;
12
+ } GeoPoint;
13
+
14
+ GeoPoint make_GeoPoint(float, float);
15
+ GeoPoint to_radians(GeoPoint);
16
+ float distance_between(GeoPoint, GeoPoint);
17
+ #endif
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ $CFLAGS = "-shared"
4
+
5
+ dir_config 'ext/cdistance'
6
+ create_makefile 'ext/cdistance'
@@ -0,0 +1,3 @@
1
+ module Cdistance
2
+ VERSION = '0.0.1'
3
+ end
data/lib/cdistance.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'bundler/setup'
2
+ require 'ffi'
3
+
4
+ module Cdistance
5
+ extend FFI::Library
6
+
7
+ lib_file = File.expand_path('../ext/cdistance/cdistance', File.dirname(__FILE__))
8
+
9
+ if FFI::Platform.mac?
10
+ lib_file << '.bundle'
11
+ end
12
+
13
+ ffi_lib FFI.map_library_name(lib_file)
14
+
15
+ def self.distance(point1, point2)
16
+ geo_point1 = GeoPoint.new(*point1)
17
+ geo_point2 = GeoPoint.new(*point2)
18
+
19
+ distance_between(geo_point1, geo_point2)
20
+ end
21
+
22
+ class GeoPoint < FFI::Struct
23
+ layout :lat, :float,
24
+ :lng, :float
25
+
26
+ def initialize(lat, lng)
27
+ super()
28
+ self[:lat] = lat
29
+ self[:lng] = lng
30
+ end
31
+ end
32
+
33
+ attach_function 'to_radians', [ GeoPoint.by_value ], :float
34
+ attach_function 'distance_between', [ GeoPoint.by_value, GeoPoint.by_value ], :float
35
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cdistance
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Cainã Costa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - cainan.costa@gmail.com
58
+ executables: []
59
+ extensions:
60
+ - ext/cdistance/extconf.rb
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - cdistance.gemspec
70
+ - ext/cdistance/distance.c
71
+ - ext/cdistance/distance.h
72
+ - ext/cdistance/extconf.rb
73
+ - lib/cdistance.rb
74
+ - lib/cdistance/version.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Distance between two geographic points in pure C.
99
+ test_files: []