Ruby Polygon Tools: rbclipper and rbpoly2tri

Share your projects and Chipmunk enhancements.
Post Reply
mieko
Posts: 4
Joined: Thu Aug 26, 2010 6:43 am
Contact:

Ruby Polygon Tools: rbclipper and rbpoly2tri

Post by mieko »

Chipmunk appears to be the physics engine of choice among Rubyists, so I thought I'd announce two sets of Ruby bindings I created to help me smash and slice polygons in my Chipmunk prototype project. Both of these extensions include their underlying library directly, because they're not readily packaged, and are only a few files large. The underlying libraries are both written in C++, but have no further dependencies outside of the C++ standard library. All BSD/MIT-style licensed.

rbclipper:
http://github.com/mieko/rbclipper

This is an all-inclusive set of bindings to Angus Johnson's "Clipper" library. I'm only using it to get a union of polygons before feeding them to Chipmunk as shapes, but quite a few boolean operations and winding/fill types are supported. The polygons returned will be oriented clockwise for shells and and counter-clockwise for holes. poly.reverse! as required.

rbpoly2tri:
http://github.com/mieko/rbpoly2tri

These are bindings to poly2tri, a pretty impressive implementation of Constrained Delaunay Triangulation. Turns non-convex shapes into a bunch of nice, fat triangles. It deals with holes through an add_hole function, so it doesn't care about orientation. Here's a comparison of poly2tri (left) vs gluTess (right):

ImageImage

(This shape was also read from the colored paths you see and unioned together using rbclipper.)

Both of these bindings are pretty much only a day old, but I dropped them into a pretty demanding situation, replacing gluTess and GEOS in a project. Documentation is little-to-none right now, but I plan on fixing that when I have more time.

-M
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Ruby Polygon Tools: rbclipper and rbpoly2tri

Post by slembcke »

That's pretty cool. Thanks.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests