Sha256: a7f0e458808c3225b684135174bcb37395647966d0a40e3efef63e986309ab47

Contents?: true

Size: 498 Bytes

Versions: 1

Compression:

Stored size: 498 Bytes

Contents

module Clusterable
  class Point < Hash
    def initialize(latitude, longitude)
      self[:latitude]  = latitude
      self[:longitude] = longitude
    end
    
    def latitude
      self[:latitude]
    end
    
    def longitude
      self[:longitude]
    end
    
    def distance_to(target)
      Math.sqrt(
        ((latitude  - target.latitude ) ** 2) +
        ((longitude - target.longitude) ** 2)
      )
    end
    
    def to_s
      [latitude, longitude].join(", ")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clusterable-0.0.1 lib/clusterable/point.rb