Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

poly2d.h

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 "csgeom/math2d.h"
00023 #include "csgeom/box.h"
00024 
00025 struct iClipper2D;
00026 
00031 class csPoly2D
00032 {
00033 protected:
00035   csVector2* vertices;
00037   int num_vertices;
00039   int max_vertices;
00040 
00042   csBox2 bbox;
00043 
00044 public:
00048   csPoly2D (int start_size = 10);
00049 
00051   csPoly2D (const csPoly2D& copy);
00052 
00054   virtual ~csPoly2D ();
00055 
00057   csPoly2D& operator= (const csPoly2D& other);
00058 
00062   void MakeEmpty ();
00063 
00067   int GetVertexCount () { return num_vertices; }
00068 
00072   int GetVertexCount () const { return num_vertices; }
00073 
00077   csVector2* GetVertices () { return vertices; }
00078 
00082   csVector2* GetVertex (int i)
00083   {
00084     if (i<0 || i>=num_vertices) return NULL;
00085     return &vertices[i];
00086   }
00087 
00091   csVector2& operator[] (int i)
00092   {
00093     CS_ASSERT (i >= 0 && i < num_vertices);
00094     return vertices[i];
00095   }
00096 
00100   const csVector2& operator[] (int i) const
00101   {
00102     CS_ASSERT (i >= 0 && i < num_vertices);
00103     return vertices[i];
00104   }
00105 
00109   csVector2* GetFirst ()
00110   { if (num_vertices<=0) return NULL;  else return vertices; }
00111 
00115   csVector2* GetLast ()
00116   { if (num_vertices<=0) return NULL;  else return &vertices[num_vertices-1]; }
00117 
00121   bool In (const csVector2& v);
00122 
00126   static bool In (csVector2* poly, int num_poly, const csVector2& v);
00127 
00131   void MakeRoom (int new_max);
00132 
00136   void SetVertexCount (int n)
00137   {
00138     MakeRoom (n);
00139     num_vertices = n;
00140   }
00141 
00146   int AddVertex (const csVector2& v) { return AddVertex (v.x, v.y); }
00147 
00152   int AddVertex (float x, float y);
00153 
00158   void SetVertices (csVector2 const* v, int num)
00159   { MakeRoom (num); memcpy (vertices, v, (num_vertices = num) * sizeof (csVector2)); }
00160 
00162   void UpdateBoundingBox ();
00163 
00165   csBox2& GetBoundingBox () { return bbox; }
00166 
00175   bool ClipAgainst (iClipper2D* view);
00176 
00185   void Intersect (const csPlane2& plane, csPoly2D& left, csPoly2D& right) const;
00186 
00191   void ClipPlane (const csPlane2& plane, csPoly2D& right) const;
00192 
00201   void ExtendConvex (const csPoly2D& other, int this_edge);
00202 
00206   float GetSignedArea();
00207 
00213   void Random (int num, const csBox2& max_bbox);
00214 };
00215 
00221 class csPoly2DFactory
00222 {
00223 public:
00225    CS_DECLARE_STATIC_CLASSVAR(sharedFactory,SharedFactory,csPoly2DFactory)
00226 
00228   virtual csPoly2D* Create () { csPoly2D* p = new csPoly2D (); return p; }
00229 };
00230 
00231 #endif // __CS_POLY2D_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000