Greiner-Hormann polygon clipping in Ruby
Uses the Greiner-Hormann clipping algorithm.
Installation
Add this line to your application's Gemfile:
gem 'greiner_hormann'
And then execute:
$ bundle
Or install it yourself as:
$ gem install greiner_hormann
Usage
require 'greiner_hormann'
poly1 = [[0, 0], [0, 1], [1, 1], [1, 0]]
poly2 = [[0.5, 0.5], [0.5, 1.5], [1.5, 1.5], [1.5, 0.5]]
GreinerHormann.union(poly1, poly2)
# => [[[0.5, 1.0], [0, 1], [0, 0], [1, 0], [1.0, 0.5], [1.5, 0.5], [1.5, 1.5], [0.5, 1.5]]]
GreinerHormann.intersection(poly1, poly2)
# => [[[0.5, 1.0], [1, 1], [1.0, 0.5], [0.5, 0.5]]]
GreinerHormann.difference(poly1, poly2)
# => [[[0.5, 1.0], [0, 1], [0, 0], [1, 0], [1.0, 0.5], [0.5, 0.5]]]
Contributing
- Fork it ( http://github.com/daveallie/greiner_hormann/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request