# HG changeset patch # User Extrawurst # Date 1291943427 -3600 # Node ID 4ceef5833c8c791ebf78110d5d09049c5d20d45e # Parent ed2c81f3d1df7a554705efed0dc9a1c65c41f10c updated to chipmunk 5.3.3 diff -r ed2c81f3d1df -r 4ceef5833c8c trunk/chipmunkd/chipmunk.d --- a/trunk/chipmunkd/chipmunk.d Thu Dec 09 22:25:04 2010 +0100 +++ b/trunk/chipmunkd/chipmunk.d Fri Dec 10 02:10:27 2010 +0100 @@ -6,6 +6,7 @@ import std.stdio; import std.string:format; import std.conv:to; +import std.math:PI; void cpMessage(string message, string condition, string file, int line, bool isError) @@ -92,8 +93,17 @@ cpFloat cpMomentForCircle(cpFloat m, cpFloat r1, cpFloat r2, cpVect offset) { - return (1.0f/2.0f)*m*(r1*r1 + r2*r2) + m*cpvdot(offset, offset); + return m*(0.5f*(r1*r1 + r2*r2) + cpvlengthsq(offset)); } + +/** + Calculate area of a hollow circle. +*/ +cpFloat cpAreaForCircle(cpFloat r1, cpFloat r2) +{ + return 2.0f*cast(cpFloat)PI*cpfabs(r1*r1 - r2*r2); +} + /** Calculate the moment of inertia for a line segment. Beveling radius is not supported. @@ -104,7 +114,16 @@ cpFloat length = cpvlength(cpvsub(b, a)); cpVect offset = cpvmult(cpvadd(a, b), 1.0f/2.0f); - return m*length*length/12.0f + m*cpvdot(offset, offset); + return m*(length*length/12.0f + cpvlengthsq(offset)); +} + +/** + Calculate the area of a fattened (capsule shaped) line segment. +*/ +cpFloat +cpAreaForSegment(cpVect a, cpVect b, cpFloat r) +{ + return 2.0f*r*(cast(cpFloat)PI*r + cpvdist(a, b)); } /** @@ -135,6 +154,51 @@ } /** + Calculate the signed area of a polygon. +*/ +cpFloat cpAreaForPoly(const int numVerts, const cpVect *verts) +{ + cpFloat area = 0.0f; + for(int i=0; i