geomagic 0.0.1.alpha → 0.0.2
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.
    
        data/lib/geomagic/extensions.rb
    CHANGED
    
    
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            module Geomagic
         | 
| 2 | 
            +
              module Extensions
         | 
| 3 | 
            +
                module GeoRubyExt
         | 
| 4 | 
            +
                  module Utility
         | 
| 5 | 
            +
                    class GeoRuby::SimpleFeatures::Polygon
         | 
| 6 | 
            +
                      def to_coordinates
         | 
| 7 | 
            +
                        _points = []
         | 
| 8 | 
            +
                        self.rings.each do |points|
         | 
| 9 | 
            +
                          points.each do |point|
         | 
| 10 | 
            +
                            _points << [point.lat, point.lng]
         | 
| 11 | 
            +
                          end 
         | 
| 12 | 
            +
                        end
         | 
| 13 | 
            +
                        _points
         | 
| 14 | 
            +
                      end
         | 
| 15 | 
            +
                      
         | 
| 16 | 
            +
                      
         | 
| 17 | 
            +
                      
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
    
        data/lib/geomagic/version.rb
    CHANGED
    
    
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
            require 'geo_ruby'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            describe "Utility" do
         | 
| 5 | 
            +
              describe "polygon method" do
         | 
| 6 | 
            +
                it "retrives coordinates" 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.to_coordinates.should == [[-80.190262, 25.774252], [-66.118292, 18.466465], [-64.75737, 32.321384], [-80.190262, 25.774252]]
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,8 +1,8 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: geomagic
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 5 | 
            -
              prerelease:  | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| 8 8 | 
             
            - Arturs Braucs
         | 
| @@ -11,11 +11,11 @@ authors: | |
| 11 11 | 
             
            autorequire: 
         | 
| 12 12 | 
             
            bindir: bin
         | 
| 13 13 | 
             
            cert_chain: []
         | 
| 14 | 
            -
            date: 2012-03- | 
| 14 | 
            +
            date: 2012-03-16 00:00:00.000000000 Z
         | 
| 15 15 | 
             
            dependencies:
         | 
| 16 16 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 17 17 | 
             
              name: rspec
         | 
| 18 | 
            -
              requirement: & | 
| 18 | 
            +
              requirement: &2156606640 !ruby/object:Gem::Requirement
         | 
| 19 19 | 
             
                none: false
         | 
| 20 20 | 
             
                requirements:
         | 
| 21 21 | 
             
                - - ! '>='
         | 
| @@ -23,10 +23,10 @@ dependencies: | |
| 23 23 | 
             
                    version: '0'
         | 
| 24 24 | 
             
              type: :development
         | 
| 25 25 | 
             
              prerelease: false
         | 
| 26 | 
            -
              version_requirements: * | 
| 26 | 
            +
              version_requirements: *2156606640
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: geokit-rails3
         | 
| 29 | 
            -
              requirement: & | 
| 29 | 
            +
              requirement: &2156605180 !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                none: false
         | 
| 31 31 | 
             
                requirements:
         | 
| 32 32 | 
             
                - - ! '>='
         | 
| @@ -34,10 +34,10 @@ dependencies: | |
| 34 34 | 
             
                    version: '0'
         | 
| 35 35 | 
             
              type: :runtime
         | 
| 36 36 | 
             
              prerelease: false
         | 
| 37 | 
            -
              version_requirements: * | 
| 37 | 
            +
              version_requirements: *2156605180
         | 
| 38 38 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 39 39 | 
             
              name: geocoder
         | 
| 40 | 
            -
              requirement: & | 
| 40 | 
            +
              requirement: &2156604080 !ruby/object:Gem::Requirement
         | 
| 41 41 | 
             
                none: false
         | 
| 42 42 | 
             
                requirements:
         | 
| 43 43 | 
             
                - - ! '>='
         | 
| @@ -45,10 +45,10 @@ dependencies: | |
| 45 45 | 
             
                    version: '0'
         | 
| 46 46 | 
             
              type: :runtime
         | 
| 47 47 | 
             
              prerelease: false
         | 
| 48 | 
            -
              version_requirements: * | 
| 48 | 
            +
              version_requirements: *2156604080
         | 
| 49 49 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 50 50 | 
             
              name: GeoRuby
         | 
| 51 | 
            -
              requirement: & | 
| 51 | 
            +
              requirement: &2156602760 !ruby/object:Gem::Requirement
         | 
| 52 52 | 
             
                none: false
         | 
| 53 53 | 
             
                requirements:
         | 
| 54 54 | 
             
                - - ! '>='
         | 
| @@ -56,10 +56,10 @@ dependencies: | |
| 56 56 | 
             
                    version: '0'
         | 
| 57 57 | 
             
              type: :runtime
         | 
| 58 58 | 
             
              prerelease: false
         | 
| 59 | 
            -
              version_requirements: * | 
| 59 | 
            +
              version_requirements: *2156602760
         | 
| 60 60 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 61 61 | 
             
              name: activesupport
         | 
| 62 | 
            -
              requirement: & | 
| 62 | 
            +
              requirement: &2156601240 !ruby/object:Gem::Requirement
         | 
| 63 63 | 
             
                none: false
         | 
| 64 64 | 
             
                requirements:
         | 
| 65 65 | 
             
                - - ~>
         | 
| @@ -67,10 +67,10 @@ dependencies: | |
| 67 67 | 
             
                    version: 3.2.2
         | 
| 68 68 | 
             
              type: :runtime
         | 
| 69 69 | 
             
              prerelease: false
         | 
| 70 | 
            -
              version_requirements: * | 
| 70 | 
            +
              version_requirements: *2156601240
         | 
| 71 71 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 72 72 | 
             
              name: rails
         | 
| 73 | 
            -
              requirement: & | 
| 73 | 
            +
              requirement: &2156599780 !ruby/object:Gem::Requirement
         | 
| 74 74 | 
             
                none: false
         | 
| 75 75 | 
             
                requirements:
         | 
| 76 76 | 
             
                - - ~>
         | 
| @@ -78,7 +78,7 @@ dependencies: | |
| 78 78 | 
             
                    version: 3.2.2
         | 
| 79 79 | 
             
              type: :runtime
         | 
| 80 80 | 
             
              prerelease: false
         | 
| 81 | 
            -
              version_requirements: * | 
| 81 | 
            +
              version_requirements: *2156599780
         | 
| 82 82 | 
             
            description: Plugin for working with Geo locations in serverside.
         | 
| 83 83 | 
             
            email:
         | 
| 84 84 | 
             
            - arturs@creo.mobi
         | 
| @@ -100,9 +100,10 @@ files: | |
| 100 100 | 
             
            - lib/geomagic/engine.rb
         | 
| 101 101 | 
             
            - lib/geomagic/extensions.rb
         | 
| 102 102 | 
             
            - lib/geomagic/extensions/geo_ruby_ext/point_in_polygon.rb
         | 
| 103 | 
            -
            - lib/geomagic/ | 
| 103 | 
            +
            - lib/geomagic/extensions/geo_ruby_ext/utility.rb
         | 
| 104 104 | 
             
            - lib/geomagic/version.rb
         | 
| 105 105 | 
             
            - spec/geomagic/point_in_polygon_spec.rb
         | 
| 106 | 
            +
            - spec/geomagic/utility_spec.rb
         | 
| 106 107 | 
             
            - spec/geomagic_spec.rb
         | 
| 107 108 | 
             
            - spec/spec_helper.rb
         | 
| 108 109 | 
             
            homepage: https://github.com/CreativeMobile/geomagic
         | 
| @@ -120,13 +121,17 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 120 121 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 121 122 | 
             
              none: false
         | 
| 122 123 | 
             
              requirements:
         | 
| 123 | 
            -
              - - ! ' | 
| 124 | 
            +
              - - ! '>='
         | 
| 124 125 | 
             
                - !ruby/object:Gem::Version
         | 
| 125 | 
            -
                  version:  | 
| 126 | 
            +
                  version: '0'
         | 
| 126 127 | 
             
            requirements: []
         | 
| 127 128 | 
             
            rubyforge_project: 
         | 
| 128 | 
            -
            rubygems_version: 1.8. | 
| 129 | 
            +
            rubygems_version: 1.8.17
         | 
| 129 130 | 
             
            signing_key: 
         | 
| 130 131 | 
             
            specification_version: 3
         | 
| 131 132 | 
             
            summary: Plugin for working with Geo locations in serverside.
         | 
| 132 | 
            -
            test_files: | 
| 133 | 
            +
            test_files:
         | 
| 134 | 
            +
            - spec/geomagic/point_in_polygon_spec.rb
         | 
| 135 | 
            +
            - spec/geomagic/utility_spec.rb
         | 
| 136 | 
            +
            - spec/geomagic_spec.rb
         | 
| 137 | 
            +
            - spec/spec_helper.rb
         | 
| @@ -1,57 +0,0 @@ | |
| 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
         |