CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound 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 "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   csVector2* GetVertex (int i)
00089   {
00090     if (i<0 || i>=num_vertices) return 0;
00091     return &vertices[i];
00092   }
00093 
00097   csVector2& operator[] (int i)
00098   {
00099     CS_ASSERT (i >= 0 && i < num_vertices);
00100     return vertices[i];
00101   }
00102 
00106   const csVector2& operator[] (int i) const
00107   {
00108     CS_ASSERT (i >= 0 && i < num_vertices);
00109     return vertices[i];
00110   }
00111 
00115   csVector2* GetFirst ()
00116   { if (num_vertices<=0) return 0;  else return vertices; }
00117 
00121   csVector2* GetLast ()
00122   { if (num_vertices<=0) return 0;  else return &vertices[num_vertices-1]; }
00123 
00127   bool In (const csVector2& v);
00128 
00132   static bool In (csVector2* poly, int num_poly, const csVector2& v);
00133 
00137   void MakeRoom (int new_max);
00138 
00142   void SetVertexCount (int n)
00143   {
00144     MakeRoom (n);
00145     num_vertices = n;
00146   }
00147 
00152   int AddVertex (const csVector2& v) { return AddVertex (v.x, v.y); }
00153 
00158   int AddVertex (float x, float y);
00159 
00164   void SetVertices (csVector2 const* v, int num)
00165   { MakeRoom (num); memcpy (vertices, v, (num_vertices = num) * sizeof (csVector2)); }
00166 
00168   void UpdateBoundingBox ();
00169 
00171   csBox2& GetBoundingBox () { return bbox; }
00172 
00181   bool ClipAgainst (iClipper2D* view);
00182 
00191   void Intersect (const csPlane2& plane, csPoly2D& left, csPoly2D& right) const;
00192 
00197   void ClipPlane (const csPlane2& plane, csPoly2D& right) const;
00198 
00207   void ExtendConvex (const csPoly2D& other, int this_edge);
00208 
00212   float GetSignedArea();
00213 
00219   void Random (int num, const csBox2& max_bbox);
00220 };
00221 
00227 class csPoly2DFactory
00228 {
00229 public:
00231    CS_DECLARE_STATIC_CLASSVAR(sharedFactory,SharedFactory,csPoly2DFactory)
00232 
00234   virtual csPoly2D* Create () { csPoly2D* p = new csPoly2D (); return p; }
00235 };
00236 
00239 #endif // __CS_POLY2D_H__

Generated for Crystal Space by doxygen 1.2.14