0.0
No commit activity in last 3 years
No release in over 3 years
This calculates distance between two parts of the earth via Haversine formula at the speed of C
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

 Project Readme

HaversineFast

This takes advantage of C being faster at calculating double floating point values then say ruby. A project necessitated the haversine calculation frequently which would be sub optimal in ruby. There were gems that I found that did this which were either old (2+ years,) or they ran on ruby which defeated the purpose, or did a lot more then just calculate the minimum distance between two points on an ellipsoid. Either way this was a nice exercise to remove external dependencies and optimize a continuous calculation.

Per wikipedia:

Installation

Add this line to your application's Gemfile:

gem 'haversine_fast'

And then execute:

$ bundle

Or install it yourself as:

$ gem install haversine_fast

Usage

For a given starting location of lat-1, lng-1 and an ending location of lat-2, lng-2, use:

HaversineFast.calc_distance(30.1959496, -81.5497181, 30.279191, -81.3895320)

Examples via the rails console:

rails console
[2] pry(main)> HaversineFast.calc_distance(30.1959496, -81.5497181, 30.279191, -81.3895320)
=> 17.8579022904856
[3] pry(main)>

Note: The above result is in kilometers. To perform a calculation for miles, you can use the following:

[3] pry(main)> ( 0.62137 * HaversineFast.calc_distance(30.1959496, -81.5497181, 30.279191, -81.3895320) ).floor
=> 11
[4] pry(main)>

Contributing

  1. Fork it ( https://github.com/[my-github-username]/haversine_fast/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request