Module: RGeo::Cartesian::PointMethods

Included in:
PointImpl
Defined in:
lib/rgeo/cartesian/feature_methods.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#buffer(distance) ⇒ Object


34
35
36
37
38
39
40
41
42
# File 'lib/rgeo/cartesian/feature_methods.rb', line 34

def buffer(distance)
  point_count = factory.property(:buffer_resolution) * 4
  angle = -::Math::PI * 2.0 / point_count
  points = (0...point_count).map do |i|
    r = angle * i
    factory.point(@x + distance * Math.cos(r), @y + distance * Math.sin(r))
  end
  factory.polygon(factory.linear_ring(points))
end

#distance(rhs) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rgeo/cartesian/feature_methods.rb', line 22

def distance(rhs)
  rhs = RGeo::Feature.cast(rhs, @factory)
  case rhs
  when PointImpl
    dx = @x - rhs.x
    dy = @y - rhs.y
    Math.sqrt(dx * dx + dy * dy)
  else
    super
  end
end