/* * Copyright (c) 2007 Eric Jordan * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. */ #ifndef B2_POLYGON_H #define B2_POLYGON_H #include "b2Triangle.h" #include "stdio.h" #include #include namespace b2ConvexDecomp { static bool B2_POLYGON_REPORT_ERRORS = false; class b2Polygon; int32 remainder(int32 x, int32 modulus); int32 TriangulatePolygon(float32* xv, float32* yv, int32 vNum, b2Triangle* results); bool IsEar(int32 i, float32* xv, float32* yv, int32 xvLength); //Not for external use int32 PolygonizeTriangles(b2Triangle* triangulated, int32 triangulatedLength, b2Polygon* polys, int32 polysLength); int32 DecomposeConvex(b2Polygon* p, b2Polygon* results, int32 maxPolys); //void DecomposeConvexAndAddTo(b2Polygon* p, b2Body* bd, b2FixtureDef* prototype); void ReversePolygon(float32* x, float32* y, int n); b2Polygon TraceEdge(b2Polygon* p); //For use with self-intersecting polygons, finds outline class b2Polygon { public: const static int32 maxVerticesPerPolygon = b2_maxPolygonVertices; float32* x; //vertex arrays float32* y; int32 nVertices; float32 area; bool areaIsSet; b2Polygon(float32* _x, float32* _y, int32 nVert); b2Polygon(b2Vec2* v, int32 nVert); b2Polygon(); ~b2Polygon(); float32 GetArea(); void MergeParallelEdges(float32 tolerance); b2Vec2* GetVertexVecs(); b2Polygon(b2Triangle& t); void Set(const b2Polygon& p); bool IsConvex(); bool IsCCW(); bool IsUsable(bool printError); bool IsUsable(); bool IsSimple(); // void AddTo(b2FixtureDef& pd); b2Polygon* Add(b2Triangle& t); void print(){ printFormatted(); // for (int32 i=0; i