CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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 
00022 #include "csextern.h"
00023 
00024 #include "csgeom/vector2.h"
00031 class csBox2;
00032 class csPlane2;
00033 
00034 struct iClipper2D;
00035 
00039 class CS_CRYSTALSPACE_EXPORT csPoly2D
00040 {
00041 protected:
00043   csVector2* vertices;
00045   size_t num_vertices;
00047   size_t max_vertices;
00048 public:
00052   csPoly2D (size_t start_size = 10);
00053 
00055   csPoly2D (const csPoly2D& copy);
00056 
00058   ~csPoly2D ();
00059 
00061   csPoly2D& operator= (const csPoly2D& other);
00062 
00066   void MakeEmpty ();
00067 
00071   size_t GetVertexCount () const { return num_vertices; }
00072 
00076   csVector2* GetVertices () { return vertices; }
00077 
00081   const csVector2* GetVertices () const { return vertices; }
00082 
00086   csVector2* GetVertex (size_t i)
00087   {
00088     if (i>=num_vertices) return 0;
00089     return &vertices[i];
00090   }
00091 
00095   csVector2& operator[] (size_t i)
00096   {
00097     CS_ASSERT (i < num_vertices);
00098     return vertices[i];
00099   }
00100 
00104   const csVector2& operator[] (size_t i) const
00105   {
00106     CS_ASSERT (i < num_vertices);
00107     return vertices[i];
00108   }
00109 
00113   csVector2* GetFirst ()
00114   { if (num_vertices<=0) return 0;  else return vertices; }
00115 
00119   csVector2* GetLast ()
00120   { if (num_vertices<=0) return 0;  else return &vertices[num_vertices-1]; }
00121 
00125   bool In (const csVector2& v);
00126 
00130   static bool In (csVector2* poly, size_t num_poly, const csVector2& v);
00131 
00135   void MakeRoom (size_t new_max);
00136 
00140   void SetVertexCount (size_t n)
00141   {
00142     MakeRoom (n);
00143     num_vertices = n;
00144   }
00145 
00150   size_t AddVertex (const csVector2& v) { return AddVertex (v.x, v.y); }
00151 
00156   size_t AddVertex (float x, float y);
00157 
00162   void SetVertices (csVector2 const* v, size_t num)
00163   {
00164     MakeRoom (num);
00165     memcpy (vertices, v, (num_vertices = num) * sizeof (csVector2));
00166   }
00167 
00176   bool ClipAgainst (iClipper2D* view);
00177 
00186   void Intersect (const csPlane2& plane, csPoly2D& left,
00187         csPoly2D& right) const;
00188 
00193   void ClipPlane (const csPlane2& plane, csPoly2D& right) const;
00194 
00203   void ExtendConvex (const csPoly2D& other, size_t this_edge);
00204 
00208   float GetSignedArea();
00209 
00215   void Random (size_t num, const csBox2& max_bbox);
00216 };
00217 
00223 class csPoly2DFactory
00224 {
00225 public:
00226   // Needed for GCC4. Otherwise emits a flood of "virtual functions but
00227   // non-virtual destructor" warnings.
00228   virtual ~csPoly2DFactory() {}
00229 
00231    CS_DECLARE_STATIC_CLASSVAR(sharedFactory,SharedFactory,csPoly2DFactory)
00232 
00233   
00234   virtual csPoly2D* Create ()
00235   {
00236     csPoly2D* p = new csPoly2D ();
00237     return p;
00238   }
00239 };
00240 
00243 #endif // __CS_POLY2D_H__

Generated for Crystal Space by doxygen 1.4.4