Page 1 of 1

Ruby Polygon Tools: rbclipper and rbpoly2tri

Posted: Tue Oct 12, 2010 7:49 pm
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

Re: Ruby Polygon Tools: rbclipper and rbpoly2tri

Posted: Wed Oct 13, 2010 8:39 am
by slembcke
That's pretty cool. Thanks.