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



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

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



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

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