csgeom/poly2d.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 1998,2000 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_POLY2D_H__ 00020 #define __CS_POLY2D_H__ 00021 00028 #include "csgeom/math2d.h" 00029 #include "csgeom/box.h" 00030 00031 struct iClipper2D; 00032 00037 class csPoly2D 00038 { 00039 protected: 00041 csVector2* vertices; 00043 int num_vertices; 00045 int max_vertices; 00046 00048 csBox2 bbox; 00049 00050 public: 00054 csPoly2D (int start_size = 10); 00055 00057 csPoly2D (const csPoly2D& copy); 00058 00060 virtual ~csPoly2D (); 00061 00063 csPoly2D& operator= (const csPoly2D& other); 00064 00068 void MakeEmpty (); 00069 00073 int GetVertexCount () { return num_vertices; } 00074 00078 int GetVertexCount () const { return num_vertices; } 00079 00083 csVector2* GetVertices () { return vertices; } 00084 00088 const csVector2* GetVertices () const { return vertices; } 00089 00093 csVector2* GetVertex (int i) 00094 { 00095 if (i<0 || i>=num_vertices) return 0; 00096 return &vertices[i]; 00097 } 00098 00102 csVector2& operator[] (int i) 00103 { 00104 CS_ASSERT (i >= 0 && i < num_vertices); 00105 return vertices[i]; 00106 } 00107 00111 const csVector2& operator[] (int i) const 00112 { 00113 CS_ASSERT (i >= 0 && i < num_vertices); 00114 return vertices[i]; 00115 } 00116 00120 csVector2* GetFirst () 00121 { if (num_vertices<=0) return 0; else return vertices; } 00122 00126 csVector2* GetLast () 00127 { if (num_vertices<=0) return 0; else return &vertices[num_vertices-1]; } 00128 00132 bool In (const csVector2& v); 00133 00137 static bool In (csVector2* poly, int num_poly, const csVector2& v); 00138 00142 void MakeRoom (int new_max); 00143 00147 void SetVertexCount (int n) 00148 { 00149 MakeRoom (n); 00150 num_vertices = n; 00151 } 00152 00157 int AddVertex (const csVector2& v) { return AddVertex (v.x, v.y); } 00158 00163 int AddVertex (float x, float y); 00164 00169 void SetVertices (csVector2 const* v, int num) 00170 { MakeRoom (num); memcpy (vertices, v, (num_vertices = num) * sizeof (csVector2)); } 00171 00173 void UpdateBoundingBox (); 00174 00176 csBox2& GetBoundingBox () { return bbox; } 00177 00186 bool ClipAgainst (iClipper2D* view); 00187 00196 void Intersect (const csPlane2& plane, csPoly2D& left, csPoly2D& right) const; 00197 00202 void ClipPlane (const csPlane2& plane, csPoly2D& right) const; 00203 00212 void ExtendConvex (const csPoly2D& other, int this_edge); 00213 00217 float GetSignedArea(); 00218 00224 void Random (int num, const csBox2& max_bbox); 00225 }; 00226 00232 class csPoly2DFactory 00233 { 00234 public: 00236 CS_DECLARE_STATIC_CLASSVAR(sharedFactory,SharedFactory,csPoly2DFactory) 00237 00238 00239 virtual csPoly2D* Create () { csPoly2D* p = new csPoly2D (); return p; } 00240 }; 00241 00244 #endif // __CS_POLY2D_H__
Generated for Crystal Space by doxygen 1.2.18