lib/mongoid/geospatial/wrappers/rgeo.rb in mongoid-geospatial-4.0.0 vs lib/mongoid/geospatial/wrappers/rgeo.rb in mongoid-geospatial-4.0.1
- old
+ new
@@ -2,42 +2,49 @@
require 'mongoid/geospatial/ext/rgeo_spherical_point_impl'
module Mongoid
module Geospatial
# Wrapper to Rgeo's Point
- class Point
+ Point.class_eval do
+ #
+ # With RGeo support
+ #
+ # @return (RGeo::SphericalFactory::Point)
def to_rgeo
RGeo::Geographic.spherical_factory.point x, y
end
+ #
+ # Distance with RGeo
+ #
+ # @return (Float)
def rgeo_distance(other)
to_rgeo.distance other.to_rgeo
end
end
# Rgeo's GeometryField concept
- class GeometryField
- private
+ GeometryField.class_eval do
def points
map do |pair|
RGeo::Geographic.spherical_factory.point(*pair)
end
end
end
- # Wrapper to Rgeo's Line
- class Line < GeometryField
+ # Wrapper to Rgeo's LineString
+ LineString.class_eval do
def to_rgeo
- RGeo::Geographic.spherical_factory.line_string points
+ RGeo::Geographic.spherical_factory.line_string(points)
end
end
# Wrapper to Rgeo's Polygon
- class Polygon < GeometryField
+ Polygon.class_eval do
def to_rgeo
- ring = RGeo::Geographic.spherical_factory.linear_ring points
- RGeo::Geographic.spherical_factory.polygon ring
+ ring = RGeo::Geographic.spherical_factory.linear_ring(points)
+ RGeo::Geographic.spherical_factory.polygon(ring)
end
end
end
end