CrystalSpace

Public API Reference

csgeom/csrectrg.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2001 by Christopher Nelson
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_CSRECTREGION_H__
00020 #define __CS_CSRECTREGION_H__
00021 
00029 #include "csextern.h"
00030 
00031 #include "csgeom/csrect.h"
00032 
00033 #ifdef CS_DEBUG     
00034 // defining this causes the csRectRegionDebug class to be compiled in  
00035 //#define CS_DEBUG_RECT_REG 
00036 #endif
00037 
00038 #ifdef CS_DEBUG_RECT_REG
00039   class csRandomGen;
00040 #endif
00041 
00042 const int FRAGMENT_BUFFER_SIZE=64;
00043 
00056 class CS_CRYSTALSPACE_EXPORT csRectRegion
00057 {
00058 protected:
00060   csRect* region;
00062   int region_count;
00064   int region_max;
00066   csRect  fragment[FRAGMENT_BUFFER_SIZE];
00068   int gather_mark;
00069 
00071   void pushRect(csRect const &);
00073   void deleteRect(int);
00074 
00075 
00080   void fragmentRect(csRect&, csRect&, int mode);
00081   void nkSplit(csRect& r1, csRect& r2);
00083   void fragmentContainedRect(csRect &r1, csRect &r2);
00085   void markForGather();
00087   void gatherFragments();
00088 
00089 public:
00091   csRectRegion();
00093   ~csRectRegion();
00094 
00099   void Include(const csRect &rect);
00101   void Exclude(const csRect &rect);
00103   void ClipTo(csRect &clip);
00104 
00106   inline int Count() const { return region_count; }
00108   inline csRect& RectAt(int i) const {  return region[i]; }
00110   void makeEmpty();
00111 };
00112 
00113 
00114 
00115 #ifdef CS_DEBUG_RECT_REG
00116 
00117 // this class is an alternate implementation of rectRegion 
00118 // it uses a 100 x 100 bool array to represent which pixels
00119 // in that area are contained in a rectangle. This class is
00120 // intended solely to aid in debugging the csRectRegion class.
00121 
00122 #define CS_RECT_REG_SIZE 100
00123 
00124 class CS_CRYSTALSPACE_EXPORT csRectRegionDebug
00125 {
00126 private:
00127   bool area[CS_RECT_REG_SIZE][CS_RECT_REG_SIZE];
00128   csRandomGen* rand;
00129 
00130   // these values ought to help someone with a debugger
00131   // quickly locate and reproduce failed tests.
00132   unsigned int rand_seed;
00133   int num_tests_complete;
00134 
00135 public:
00136   csRectRegionDebug();
00137   ~csRectRegionDebug();
00138 
00143   void Include(const csRect &rect);
00144 
00146   void Exclude(const csRect &rect);
00147 
00149   void ClipTo(const csRect &clip);
00150   
00152   void MakeEmpty();
00153 
00158   void AssertEqual(const csRectRegion &r);
00159 
00161   bool CheckBounds(const csRect &clip);
00162 
00164   void UnitTest();
00165 
00167   csRect RandRect();
00168 
00170   csRect RandNonEmptyRect();
00171 };
00172 
00173 #endif // CS_DEBUG
00174 
00178 #endif // __CS_CSRECTREGION_H__

Generated for Crystal Space by doxygen 1.4.6