CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | 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 
00028 #include "csextern.h"
00029 
00030 #include "csgeom/math2d.h"
00031 #include "csgeom/box.h"
00032 
00033 struct iClipper2D;
00034 
00038 class CS_CSGEOM_EXPORT csPoly2D
00039 {
00040 protected:
00042   csVector2* vertices;
00044   int num_vertices;
00046   int max_vertices;
00047 public:
00051   csPoly2D (int start_size = 10);
00052 
00054   csPoly2D (const csPoly2D& copy);
00055 
00057   ~csPoly2D ();
00058 
00060   csPoly2D& operator= (const csPoly2D& other);
00061 
00065   void MakeEmpty ();
00066 
00070   int GetVertexCount () const { return num_vertices; }
00071 
00075   csVector2* GetVertices () { return vertices; }
00076 
00080   const csVector2* GetVertices () const { return vertices; }
00081 
00085   csVector2* GetVertex (int i)
00086   {
00087     if (i<0 || i>=num_vertices) return 0;
00088     return &vertices[i];
00089   }
00090 
00094   csVector2& operator[] (int i)
00095   {
00096     CS_ASSERT (i >= 0 && i < num_vertices);
00097     return vertices[i];
00098   }
00099 
00103   const csVector2& operator[] (int i) const
00104   {
00105     CS_ASSERT (i >= 0 && i < num_vertices);
00106     return vertices[i];
00107   }
00108 
00112   csVector2* GetFirst ()
00113   { if (num_vertices<=0) return 0;  else return vertices; }
00114 
00118   csVector2* GetLast ()
00119   { if (num_vertices<=0) return 0;  else return &vertices[num_vertices-1]; }
00120 
00124   bool In (const csVector2& v);
00125 
00129   static bool In (csVector2* poly, int num_poly, const csVector2& v);
00130 
00134   void MakeRoom (int new_max);
00135 
00139   void SetVertexCount (int n)
00140   {
00141     MakeRoom (n);
00142     num_vertices = n;
00143   }
00144 
00149   int AddVertex (const csVector2& v) { return AddVertex (v.x, v.y); }
00150 
00155   int AddVertex (float x, float y);
00156 
00161   void SetVertices (csVector2 const* v, int num)
00162   {
00163     MakeRoom (num);
00164     memcpy (vertices, v, (num_vertices = num) * sizeof (csVector2));
00165   }
00166 
00175   bool ClipAgainst (iClipper2D* view);
00176 
00185   void Intersect (const csPlane2& plane, csPoly2D& left,
00186         csPoly2D& right) const;
00187 
00192   void ClipPlane (const csPlane2& plane, csPoly2D& right) const;
00193 
00202   void ExtendConvex (const csPoly2D& other, int this_edge);
00203 
00207   float GetSignedArea();
00208 
00214   void Random (int num, const csBox2& max_bbox);
00215 };
00216 
00222 class csPoly2DFactory
00223 {
00224 public:
00226    CS_DECLARE_STATIC_CLASSVAR(sharedFactory,SharedFactory,csPoly2DFactory)
00227 
00228   
00229   virtual csPoly2D* Create ()
00230   {
00231     csPoly2D* p = new csPoly2D ();
00232     return p;
00233   }
00234 };
00235 
00238 #endif // __CS_POLY2D_H__

Generated for Crystal Space by doxygen 1.3.9.1