CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

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 "csgeom/csrect.h"
00030 
00031 #ifdef CS_DEBUG     
00032 // defining this causes the csRectRegionDebug class to be compiled in  
00033 //#define CS_DEBUG_RECT_REG 
00034 #endif
00035 
00036 #ifdef CS_DEBUG_RECT_REG
00037   class csRandomGen;
00038 #endif
00039 
00040 const int FRAGMENT_BUFFER_SIZE=64;
00041 
00054 class csRectRegion
00055 {
00056 protected:
00058   csRect* region;
00060   int region_count;
00062   int region_max;
00064   csRect  fragment[FRAGMENT_BUFFER_SIZE];
00066   int gather_mark;
00067 
00069   void pushRect(csRect const &);
00071   void deleteRect(int);
00072 
00073 
00075   void fragmentRect(csRect&, csRect&, int mode);
00076   void nkSplit(csRect& r1, csRect& r2);
00078   void fragmentContainedRect(csRect &r1, csRect &r2);
00080   void markForGather();
00082   void gatherFragments();
00083 
00084 public:
00086   csRectRegion();
00088   ~csRectRegion();
00089 
00091   void Include(const csRect &rect);
00093   void Exclude(const csRect &rect);
00095   void ClipTo(csRect &clip);
00096 
00098   int Count() const { return region_count; }
00100   csRect& RectAt(int i) const {  return region[i]; }
00102   void makeEmpty();
00103 };
00104 
00105 
00106 
00107 #ifdef CS_DEBUG_RECT_REG
00108 
00109 // this class is an alternate implementation of rectRegion 
00110 // it uses a 100 x 100 bool array to represent which pixels
00111 // in that area are contained in a rectangle. This class is
00112 // intended solely to aid in debugging the csRectRegion class.
00113 
00114 #define CS_RECT_REG_SIZE 100
00115 
00116 class csRectRegionDebug
00117 {
00118 private:
00119   bool area[CS_RECT_REG_SIZE][CS_RECT_REG_SIZE];
00120   csRandomGen* rand;
00121 
00122   // these values ought to help someone with a debugger
00123   // quickly locate and reproduce failed tests.
00124   unsigned int rand_seed;
00125   int num_tests_complete;
00126 
00127 public:
00128   csRectRegionDebug();
00129   ~csRectRegionDebug();
00130 
00132   void Include(const csRect &rect);
00133 
00135   void Exclude(const csRect &rect);
00136 
00138   void ClipTo(const csRect &clip);
00139   
00141   void MakeEmpty();
00142 
00145   void AssertEqual(const csRectRegion &r);
00146 
00148   bool CheckBounds(const csRect &clip);
00149 
00151   void UnitTest();
00152 
00154   csRect RandRect();
00155 
00157   csRect RandNonEmptyRect();
00158 };
00159 
00160 #endif // CS_DEBUG
00161 
00165 #endif // __CS_CSRECTREGION_H__

Generated for Crystal Space by doxygen 1.2.14