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



56
57
58
59
60
61
62
63
64
# File 'lib/rgeo/cartesian/feature_methods.rb', line 56

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



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rgeo/cartesian/feature_methods.rb', line 44

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