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 "csextern.h" 00029 00030 #include "csgeom/math2d.h" 00031 #include "csgeom/box.h" 00032 00033 struct iClipper2D; 00034 00039 class CS_CSGEOM_EXPORT csPoly2D 00040 { 00041 protected: 00043 csVector2* vertices; 00045 int num_vertices; 00047 int max_vertices; 00048 00050 csBox2 bbox; 00051 00052 public: 00056 csPoly2D (int start_size = 10); 00057 00059 csPoly2D (const csPoly2D& copy); 00060 00062 virtual ~csPoly2D (); 00063 00065 csPoly2D& operator= (const csPoly2D& other); 00066 00070 void MakeEmpty (); 00071 00075 int GetVertexCount () { return num_vertices; } 00076 00080 int GetVertexCount () const { return num_vertices; } 00081 00085 csVector2* GetVertices () { return vertices; } 00086 00090 const csVector2* GetVertices () const { return vertices; } 00091 00095 csVector2* GetVertex (int i) 00096 { 00097 if (i<0 || i>=num_vertices) return 0; 00098 return &vertices[i]; 00099 } 00100 00104 csVector2& operator[] (int i) 00105 { 00106 CS_ASSERT (i >= 0 && i < num_vertices); 00107 return vertices[i]; 00108 } 00109 00113 const csVector2& operator[] (int i) const 00114 { 00115 CS_ASSERT (i >= 0 && i < num_vertices); 00116 return vertices[i]; 00117 } 00118 00122 csVector2* GetFirst () 00123 { if (num_vertices<=0) return 0; else return vertices; } 00124 00128 csVector2* GetLast () 00129 { if (num_vertices<=0) return 0; else return &vertices[num_vertices-1]; } 00130 00134 bool In (const csVector2& v); 00135 00139 static bool In (csVector2* poly, int num_poly, const csVector2& v); 00140 00144 void MakeRoom (int new_max); 00145 00149 void SetVertexCount (int n) 00150 { 00151 MakeRoom (n); 00152 num_vertices = n; 00153 } 00154 00159 int AddVertex (const csVector2& v) { return AddVertex (v.x, v.y); } 00160 00165 int AddVertex (float x, float y); 00166 00171 void SetVertices (csVector2 const* v, int num) 00172 { MakeRoom (num); memcpy (vertices, v, (num_vertices = num) * sizeof (csVector2)); } 00173 00175 void UpdateBoundingBox (); 00176 00178 csBox2& GetBoundingBox () { return bbox; } 00179 00188 bool ClipAgainst (iClipper2D* view); 00189 00198 void Intersect (const csPlane2& plane, csPoly2D& left, csPoly2D& right) const; 00199 00204 void ClipPlane (const csPlane2& plane, csPoly2D& right) const; 00205 00214 void ExtendConvex (const csPoly2D& other, int this_edge); 00215 00219 float GetSignedArea(); 00220 00226 void Random (int num, const csBox2& max_bbox); 00227 }; 00228 00234 class csPoly2DFactory 00235 { 00236 public: 00238 CS_DECLARE_STATIC_CLASSVAR(sharedFactory,SharedFactory,csPoly2DFactory) 00239 00240 00241 virtual csPoly2D* Create () { csPoly2D* p = new csPoly2D (); return p; } 00242 }; 00243 00246 #endif // __CS_POLY2D_H__
Generated for Crystal Space by doxygen 1.2.18