geomagic 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.3-p125@rails32"
8
+
9
+ #
10
+ # Uncomment the following lines if you want to verify rvm version per project
11
+ #
12
+ # rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+ #
18
+
19
+ #
20
+ # Uncomment following line if you want options to be set only for given project.
21
+ #
22
+ # PROJECT_JRUBY_OPTS=( --1.9 )
23
+ #
24
+ # The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
25
+ #
26
+ # chmod +x ${rvm_path}/hooks/after_use_jruby_opts
27
+ #
28
+
29
+ #
30
+ # First we attempt to load the desired environment directly from the environment
31
+ # file. This is very fast and efficient compared to running through the entire
32
+ # CLI and selector. If you want feedback on which environment was used then
33
+ # insert the word 'use' after --create as this triggers verbose mode.
34
+ #
35
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
36
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
37
+ then
38
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
39
+
40
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
41
+ then
42
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
43
+ fi
44
+ else
45
+ # If the environment file has not yet been created, use the RVM CLI to select.
46
+ if ! rvm --create use "$environment_id"
47
+ then
48
+ echo "Failed to create RVM environment '${environment_id}'."
49
+ return 1
50
+ fi
51
+ fi
52
+
53
+ #
54
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
55
+ # it be automatically loaded. Uncomment the following and adjust the filename if
56
+ # necessary.
57
+ #
58
+ # filename=".gems"
59
+ # if [[ -s "$filename" ]]
60
+ # then
61
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
62
+ # fi
63
+
64
+ # If you use bundler, this might be useful to you:
65
+ # if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
66
+ # then
67
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
68
+ # gem install bundler
69
+ # fi
70
+ # if [[ -s Gemfile ]] && command -v bundle
71
+ # then
72
+ # bundle install
73
+ # fi
74
+
75
+ if [[ $- == *i* ]] # check for interactive shells
76
+ then
77
+ echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
78
+ else
79
+ echo "Using: $GEM_HOME" # don't use colors in interactive shells
80
+ fi
81
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ ## 0.0.1 2012-03-14
2
+
3
+ * Initial release
4
+
5
+ ### Features & Enhancements
6
+
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ ### Test Suite
12
+
13
+ * RSpec
14
+
15
+ ### Contributors
16
+
17
+ * Creative Mobile
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in geomagic.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Creative Mobile
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,39 @@
1
+ # Geomagic
2
+
3
+ Plugin for working with Geo locations in serverside.
4
+ Includes:
5
+
6
+ * geokit-rails3
7
+ * geocoder
8
+ * GeoRuby
9
+ * spatial_adapter
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'geomagic'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install geomagic
24
+
25
+ ## Usage
26
+
27
+
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
36
+
37
+ Questions or problems? Please post them on the [issue tracker](https://github.com/CreativeMobile/geomagic/issues).
38
+
39
+ This gem is created by Arturs Braucs in Creative Mobile and is under the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/geomagic.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/geomagic/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Arturs Braucs", "Edgars Kaukis", "Creative Mobile"]
6
+ gem.email = ["arturs@creo.mobi"]
7
+ gem.description = %q{Plugin for working with Geo locations in serverside.}
8
+ gem.summary = %q{Plugin for working with Geo locations in serverside.}
9
+ gem.homepage = "https://github.com/CreativeMobile/geomagic"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "geomagic"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Geomagic::VERSION
17
+
18
+ gem.add_development_dependency "rspec"
19
+
20
+ gem.add_dependency "geokit-rails3"
21
+ gem.add_dependency "geocoder"
22
+ gem.add_dependency "GeoRuby"
23
+
24
+ gem.add_dependency "activesupport", "~> 3.2.2"
25
+ gem.add_dependency "rails", "~> 3.2.2"
26
+ end
@@ -0,0 +1,23 @@
1
+ module Geomagic
2
+ module ActsAsGeomagic
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ end
7
+
8
+ module ClassMethods
9
+ def acts_as_geomagic
10
+
11
+ include InstanceMethodsOnActivation
12
+
13
+ end
14
+
15
+ end
16
+
17
+ module InstanceMethodsOnActivation
18
+
19
+ end
20
+ end
21
+ end
22
+
23
+ ActiveRecord::Base.send :include, Geomagic::ActsAsGeomagic
@@ -0,0 +1,5 @@
1
+ module Authorizme
2
+ class Engine < Rails::Engine
3
+ config.geomagic = Geomagic
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ module Geomagic
2
+ module Extensions
3
+ module GeoRubyExt
4
+ module PointInPolygon
5
+ class GeoRuby::SimpleFeatures::Polygon
6
+
7
+ def includes? point
8
+ self.each do |linear_ring|
9
+ return true if linear_ring.contains_point? point
10
+ end
11
+ false
12
+ end
13
+
14
+ end
15
+
16
+ class GeoRuby::SimpleFeatures::LinearRing
17
+
18
+ def contains_point? point
19
+ return false if outside_bounding_box? point
20
+ i = -1
21
+ j = self.size-1
22
+ contains_point = false
23
+ while (i += 1) < self.size
24
+ a_point_on_polygon = self[i]
25
+ trailing_point_on_polygon = self[j]
26
+ if point_is_between_the_ys_of_the_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon)
27
+ if ray_crosses_through_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon)
28
+ contains_point = !contains_point
29
+ end
30
+ end
31
+ j = i
32
+ end
33
+ contains_point
34
+ end
35
+
36
+ private
37
+
38
+ def point_is_between_the_ys_of_the_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon)
39
+ (a_point_on_polygon.lat <= point.lat && point.lat < trailing_point_on_polygon.lat) ||
40
+ (trailing_point_on_polygon.lat <= point.lat && point.lat < a_point_on_polygon.lat)
41
+ end
42
+
43
+ def ray_crosses_through_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon)
44
+ (point.lng < (trailing_point_on_polygon.lng - a_point_on_polygon.lng) * (point.lat - a_point_on_polygon.lat) /
45
+ (trailing_point_on_polygon.lat - a_point_on_polygon.lat) + a_point_on_polygon.lng)
46
+ end
47
+
48
+ def outside_bounding_box? point
49
+ bb_point_1, bb_point_2 = bounding_box
50
+ max_x = [bb_point_1.lng, bb_point_2.lng].max
51
+ max_y = [bb_point_1.lat, bb_point_2.lat].max
52
+ min_x = [bb_point_1.lng, bb_point_2.lng].min
53
+ min_y = [bb_point_1.lat, bb_point_2.lat].min
54
+
55
+ point.lng < min_x || point.lng > max_x || point.lat < min_y || point.lat > max_y
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Extensions
2
+ require "geomagic/extensions/geo_ruby_ext/point_in_polygon"
3
+ end
@@ -0,0 +1,57 @@
1
+ module Geomagic
2
+ module PointInPolygon
3
+ class GeoRuby::SimpleFeatures::Polygon
4
+
5
+ def includes? point
6
+ self.each do |linear_ring|
7
+ return true if linear_ring.contains_point? point
8
+ end
9
+ false
10
+ end
11
+
12
+ end
13
+
14
+ class GeoRuby::SimpleFeatures::LinearRing
15
+
16
+ def contains_point? point
17
+ return false if outside_bounding_box? point
18
+ i = -1
19
+ j = self.size-1
20
+ contains_point = false
21
+ while (i += 1) < self.size
22
+ a_point_on_polygon = self[i]
23
+ trailing_point_on_polygon = self[j]
24
+ if point_is_between_the_ys_of_the_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon)
25
+ if ray_crosses_through_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon)
26
+ contains_point = !contains_point
27
+ end
28
+ end
29
+ j = i
30
+ end
31
+ contains_point
32
+ end
33
+
34
+ private
35
+
36
+ def point_is_between_the_ys_of_the_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon)
37
+ (a_point_on_polygon.lat <= point.lat && point.lat < trailing_point_on_polygon.lat) ||
38
+ (trailing_point_on_polygon.lat <= point.lat && point.lat < a_point_on_polygon.lat)
39
+ end
40
+
41
+ def ray_crosses_through_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon)
42
+ (point.lng < (trailing_point_on_polygon.lng - a_point_on_polygon.lng) * (point.lat - a_point_on_polygon.lat) /
43
+ (trailing_point_on_polygon.lat - a_point_on_polygon.lat) + a_point_on_polygon.lng)
44
+ end
45
+
46
+ def outside_bounding_box? point
47
+ bb_point_1, bb_point_2 = bounding_box
48
+ max_x = [bb_point_1.lng, bb_point_2.lng].max
49
+ max_y = [bb_point_1.lat, bb_point_2.lat].max
50
+ min_x = [bb_point_1.lng, bb_point_2.lng].min
51
+ min_y = [bb_point_1.lat, bb_point_2.lat].min
52
+
53
+ point.lng < min_x || point.lng > max_x || point.lat < min_y || point.lat > max_y
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Geomagic
2
+ VERSION = "0.0.1.alpha"
3
+ end
data/lib/geomagic.rb ADDED
@@ -0,0 +1,24 @@
1
+ require "geomagic/version"
2
+
3
+ # Requires
4
+ require "rails"
5
+ require "active_support/dependencies"
6
+ require "active_record"
7
+ require "action_controller"
8
+
9
+ require "geokit-rails3"
10
+ require "geocoder"
11
+ require 'geo_ruby'
12
+
13
+ # require "geomagic/point_in_polygon"
14
+ require "geomagic/extensions"
15
+ require 'geomagic/acts_as_geomagic'
16
+
17
+ module Geomagic
18
+ def self.setup
19
+ yield self
20
+ end
21
+ end
22
+
23
+ # Require our engine
24
+ require "geomagic/engine"
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'geo_ruby'
3
+
4
+ describe "PointInPolygon" do
5
+ describe "Added point" do
6
+ it "is in the polygon" do
7
+ polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[25.774252, -80.190262], [18.466465, -66.118292],[32.321384, -64.75737],[25.774252, -80.190262]]])
8
+ polygon.includes?( GeoRuby::SimpleFeatures::Point.from_coordinates([25.774252, -70.190261]) ).should == true
9
+ end
10
+
11
+ it "is not in the polygon" do
12
+ polygon = GeoRuby::SimpleFeatures::Polygon.from_coordinates([[[25.774252, -80.190262], [18.466465, -66.118292],[32.321384, -64.75737],[25.774252, -80.190262]]])
13
+ polygon.includes?( GeoRuby::SimpleFeatures::Point.from_coordinates([25.774252, -65.190261]) ).should == false
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Geomagic do
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'geomagic'
2
+
3
+ RSpec.configure do |config|
4
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geomagic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Arturs Braucs
9
+ - Edgars Kaukis
10
+ - Creative Mobile
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-03-14 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ requirement: &81869790 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *81869790
27
+ - !ruby/object:Gem::Dependency
28
+ name: geokit-rails3
29
+ requirement: &81869300 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *81869300
38
+ - !ruby/object:Gem::Dependency
39
+ name: geocoder
40
+ requirement: &81868550 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *81868550
49
+ - !ruby/object:Gem::Dependency
50
+ name: GeoRuby
51
+ requirement: &81868160 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: *81868160
60
+ - !ruby/object:Gem::Dependency
61
+ name: activesupport
62
+ requirement: &81863730 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 3.2.2
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: *81863730
71
+ - !ruby/object:Gem::Dependency
72
+ name: rails
73
+ requirement: &81862930 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 3.2.2
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: *81862930
82
+ description: Plugin for working with Geo locations in serverside.
83
+ email:
84
+ - arturs@creo.mobi
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - .rspec
91
+ - .rvmrc
92
+ - CHANGELOG.md
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - geomagic.gemspec
98
+ - lib/geomagic.rb
99
+ - lib/geomagic/acts_as_geomagic.rb
100
+ - lib/geomagic/engine.rb
101
+ - lib/geomagic/extensions.rb
102
+ - lib/geomagic/extensions/geo_ruby_ext/point_in_polygon.rb
103
+ - lib/geomagic/point_in_polygon.rb
104
+ - lib/geomagic/version.rb
105
+ - spec/geomagic/point_in_polygon_spec.rb
106
+ - spec/geomagic_spec.rb
107
+ - spec/spec_helper.rb
108
+ homepage: https://github.com/CreativeMobile/geomagic
109
+ licenses: []
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>'
124
+ - !ruby/object:Gem::Version
125
+ version: 1.3.1
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.15
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Plugin for working with Geo locations in serverside.
132
+ test_files: []