• Stars
    star
    9
  • Rank 1,879,675 (Top 39 %)
  • Language
    Crystal
  • License
    MIT License
  • Created almost 4 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Google Polylines in Crystal!

Crystal Lang Polylines

Release Build Status Docs

A Crystal implementation of the Google polyline algorithm.

Greatly inspired by the Ruby implementation fast-polylines, it is mostly existing for performance comparison between Ruby C extensions and Crystal!

If you are curious: encoding is roughly the same, decoding is way faster in Crystal. If you are even more curious, make benchmark here and in fast-polylines πŸ˜‰. With a MacBook pro 1,4 GHz i5, here's the result:

β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” ENCODING β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

CrystalPolylines 706.82k (  1.41Β΅s) (Β± 4.42%)  466B/op  fastest

β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”  DECODING β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

CrystalPolylines   1.43M (699.73ns) (Β± 3.21%)  1.62kB/op  fastest

Installation

Add the dependency to your shard.yml:

dependencies:
  polylines:
    github: BuonOmo/polylines.cr

Run shards install

Usage

require "polylines"

Polylines.encode([{lat: 38.5, lng: -120.2}, {lat: 40.7, lng: -120.95}])
Polylines.encode([[38.5, -120.2], [40.7, -120.95]])
Polylines.encode([{38.5, -120.2}, {40.7, -120.95}])
# => "_p~iF~ps|U_ulLnnqC"

Polylines.decode("_p~iF~ps|U_ulLnnqC")
# => [{lat: 38.5, lng: -120.2}, {lat: 40.7, lng: -120.95}]

Polylines.encode([{lat: 12.1232493, lng: 2.9481493}, {lat: 13.8474392, lng: 16.8373924}], 7)
# => "yemffFi`lfw@uqj{_@}gi|gG"

Polylines.decode("yemffFi`lfw@uqj{_@}gi|gG", 7)
# => [{lat: 12.1232493, lng: 2.9481493}, {lat: 13.8474392, lng: 16.8373924}]

Contributing

  1. Fork it (BuonOmo/polylines.cr/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