Don't worry, I'll take anything from SVN with a nugget of salt - in any case I'm certainly not the one to apologize to about being quick on the commit-trigger, we're already all the way up to revision 70+ with the Java port, and we're just translating code that you've already debugged!
Back on topic, I've got the decomposition stuff working right, as far as I can tell, in the Java port now. I put it all into a Polygon class (plus a Triangle class with one method - boolean isInside(Vec2) ) and I have it living in the subpackage util.nonconvex, but the location doesn't matter much and can easily be changed. Here are the important public methods:
public Polygon(float x, float y)
public Polygon(Vec2 v)
public Vec2 getVertexVecs() - Polygon stores list of floats, not Vec2s, this returns a list of Vec2s
public boolean isConvex()
public boolean isSimple()
public Polygon add(Triangle t) - adds a triangle to the polygon if touching
public void addTo(PolyDef pd) - adds the polygon to a PolyDef
public static Triangle triangulatePolygon(float xv, float yv, int nVert) - turn polygon into a triangle
public static Polygon polygonizeTriangles(Triangle triangulated) - turn connected triangles into list of convex polys
public static Polygon decomposeConvex(Polygon p) - triangulates then polygonizes the result
public static void decomposeConvexAndAddTo(Polygon p, BodyDef bd, PolyDef prototype)
public static Polygon convexHull(Vec2 cloud, int nVert)
public static Polygon convexHull(float cloudX, float cloudY, int nVert)
Any of the methods that return arrays will need to be reworked in C++ - I'm up for suggestions as to the best way to do that, for now I assume the user passes in an allocated array pointer and the return value is the length of the result (only problem - the length is usually unknown in advance, so how much space should be allocated? Would a linked list be more appropriate here?). The only function that probably needs any explanation is decomposeConvexAndAddTo, which takes the non-convex polygon p, decomposes it, and adds all the resulting pieces to bd using prototype to fill in the details like density, friction, restitution, etc. This would be the function you would usually use to create a nonconvex polygon as simply as possible, but the others are available in case people want to store the results.
Any suggestions for name, method signature, or functionality changes would be most happily received while I'm still in Java mode and can refactor with a click... At some point I can put together an aggressive decomposition function that attempts to find a near-minimal decomposition (much slower, though, O(N^3) or worse) if you think it might be useful.