Primitives is a gem for performing Boolean operations with 2D geometry primitives. Made by MMCS students as a lab work.
Add this line to your application's Gemfile:
gem 'primitives'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install primitives
You can perform a boolean operation only for pair of shapes of the same type:
p1t1 = Point.new(1.0, 1.0)
p2t1 = Point.new(4.0, 1.0)
p3t1 = Point.new(3.0, 3.0)
t1 = Triangle.new(p1t1, p2t1, p3t1)
p1t2 = Point.new(3.0, 2.0)
p2t2 = Point.new(7.0, 2.0)
p3t2 = Point.new(5.0, 4.0)
t2 = Triangle.new(p1t2, p2t2, p3t2)
triangles = PolygonSet.new([t1, t2])
plot(triangles)
intersection_result = intersect_triangles(t1, t2)
plot(intersection_result)
line1 = StraightLine.new(3, 2, 1) #the line is given by the equation Ax + By + C = 0
point = Point.new(1, 1)
#find shortest distance from point to line
len = line1.shortest_distance_point point
#check if lines intersect return Point if true, otherwise return nil
line2 = StraightLine.new(5, 6, -1)
intersect_point = line1.line_inersection line2
You can use primitives function:
p1 = Point.new(1.0, 7.0)
p2 = Point.new(9.0, 7.0)
distance = distance_points(p1, p2)
p11 = Point.new(1.0, 7.0)
p22 = Point.new(9.0, 7.0)
p33 = Point.new(29.0, 17.0)
bool = one_line?(p11, p22,p33)
str1 = new.StraightLine(2,5,7)
str2 = new.StraightLine(12,15,75)
angle = angle_straight_lines(str1,str2)
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/mmcs-ruby/primitives. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Primitives project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.