| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# csgeom/polyclip.h

Go to the documentation of this file.

    00001 /*
    00002     Crystal Space polygon clipping routines
    00003     Copyright (C) 1998 by Jorrit Tyberghein
    00004     Contributed by Ivan Avramovic <ivan@avramovic.com> and
    00005                    Andrew Zabolotny <bit@eltech.ru>
    00006
    00007     This library is free software; you can redistribute it and/or
    00008     modify it under the terms of the GNU Library General Public
    00009     License as published by the Free Software Foundation; either
    00010     version 2 of the License, or (at your option) any later version.
    00011
    00012     This library is distributed in the hope that it will be useful,
    00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015     Library General Public License for more details.
    00016
    00017     You should have received a copy of the GNU Library General Public
    00018     License along with this library; if not, write to the Free
    00019     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00020 */
    00021
    00022 #ifndef __CS_POLYCLIP_H__
    00023 #define __CS_POLYCLIP_H__
    00024
    00025
    00026 #include "csextern.h"
    00027
    00028 #include "csgeom/box.h"
    00029
    00030 #include "igeom/clip2d.h"
    00031
    00032 #include "csutil/scf_implementation.h"
    00033
    00034 class csPoly2DPool;
    00035
    00046 class CS_CRYSTALSPACE_EXPORT csClipper :
    00047   public scfImplementation1<csClipper,iClipper2D>
    00048 {
    00049 protected:
    00051   static csPoly2DPool *polypool;
    00052
    00054   uint8 mrClipping;
    00055
    00056 public:
    00057   static csPoly2DPool *GetSharedPool ();
    00058
    00059 public:
    00061   csClipper ();
    00062
    00064   virtual ~csClipper ();
    00065
    00067   virtual uint8 ClipInPlace (csVector2 *InPolygon, size_t &InOutCount,
    00068         csBox2 &BoundingBox);
    00069
    00071   uint8 LastClipResult () { return mrClipping; }
    00072 };
    00073
    00078 class CS_CRYSTALSPACE_EXPORT csBoxClipper : public csClipper
    00079 {
    00081   csBox2 region;
    00083   csVector2 ClipBox [4];
    00084
    00086   inline void InitClipBox ()
    00087   {
    00088     ClipBox [0].Set (region.MinX (), region.MinY ());
    00089     ClipBox [1].Set (region.MinX (), region.MaxY ());
    00090     ClipBox [2].Set (region.MaxX (), region.MaxY ());
    00091     ClipBox [3].Set (region.MaxX (), region.MinY ());
    00092   }
    00093
    00094 public:
    00096   csBoxClipper (const csBox2& b) : region (b)
    00097   { InitClipBox (); }
    00099   csBoxClipper (float x1, float y1, float x2, float y2) : region (x1,y1,x2,y2)
    00100   { InitClipBox (); }
    00101
    00103   virtual uint8 Clip (csVector2 *InPolygon, size_t InCount,
    00104     csVector2 *OutPolygon, size_t &OutCount);
    00105
    00107   virtual uint8 Clip (csVector2 *InPolygon, size_t InCount,
    00108     csVector2 *OutPolygon, size_t &OutCount, csBox2 &BoundingBox);
    00109
    00111   virtual uint8 Clip (csVector2 *InPolygon, size_t InCount,
    00112     csVector2 *OutPolygon, size_t &OutCount, csVertexStatus *OutStatus);
    00113
    00115   virtual int ClassifyBox (const csBox2 &box);
    00116
    00118   virtual bool IsInside (const csVector2& v)
    00119   { return region.In (v.x, v.y); }
    00120
    00122   virtual size_t GetVertexCount ()
    00123   { return 4; }
    00124
    00126   virtual csVector2 *GetClipPoly ()
    00127   { return ClipBox; }
    00128
    00129   virtual ClipperType GetClipperType() const { return clipperBox; }
    00130 };
    00131
    00142 class CS_CRYSTALSPACE_EXPORT csPolygonClipper : public csClipper
    00143 {
    00145   csVector2 *ClipData;
    00147   csVector2 *ClipPoly;
    00149   csPoly2D *ClipPoly2D;
    00151   size_t ClipPolyVertices;
    00153   csBox2 ClipBox;
    00154
    00156   void Prepare ();
    00157
    00158 public:
    00160   csPolygonClipper (csPoly2D *Clipper, bool mirror = false,
    00161     bool copy = false);
    00163   csPolygonClipper (csVector2 *Clipper, size_t Count, bool mirror = false,
    00164     bool copy = false);
    00166   virtual ~csPolygonClipper ();
    00167
    00169   virtual uint8 Clip (csVector2 *InPolygon, size_t InCount,
    00170     csVector2 *OutPolygon, size_t &OutCount);
    00171
    00173   virtual uint8 Clip (csVector2 *InPolygon, size_t InCount,
    00174     csVector2 *OutPolygon, size_t &OutCount, csBox2 &BoundingBox);
    00175
    00177   virtual uint8 Clip (csVector2 *InPolygon, size_t InCount,
    00178     csVector2 *OutPolygon, size_t &OutCount, csVertexStatus *OutStatus);
    00179
    00181   virtual int ClassifyBox (const csBox2 &box);
    00182
    00184   virtual bool IsInside (const csVector2& v);
    00185
    00187   virtual size_t GetVertexCount () { return ClipPolyVertices; }
    00188
    00190   virtual csVector2 *GetClipPoly ()
    00191   { return ClipPoly; }
    00192
    00193   virtual ClipperType GetClipperType() const { return clipperPoly; }
    00194 };
    00198 #endif // __CS_POLYCLIP_H__