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_CSGEOM_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 00077 void fragmentRect(csRect&, csRect&, int mode); 00078 void nkSplit(csRect& r1, csRect& r2); 00080 void fragmentContainedRect(csRect &r1, csRect &r2); 00082 void markForGather(); 00084 void gatherFragments(); 00085 00086 public: 00088 csRectRegion(); 00090 ~csRectRegion(); 00091 00093 void Include(const csRect &rect); 00095 void Exclude(const csRect &rect); 00097 void ClipTo(csRect &clip); 00098 00100 int Count() const { return region_count; } 00102 csRect& RectAt(int i) const { return region[i]; } 00104 void makeEmpty(); 00105 }; 00106 00107 00108 00109 #ifdef CS_DEBUG_RECT_REG 00110 00111 // this class is an alternate implementation of rectRegion 00112 // it uses a 100 x 100 bool array to represent which pixels 00113 // in that area are contained in a rectangle. This class is 00114 // intended solely to aid in debugging the csRectRegion class. 00115 00116 #define CS_RECT_REG_SIZE 100 00117 00118 class CS_CSGEOM_EXPORT csRectRegionDebug 00119 { 00120 private: 00121 bool area[CS_RECT_REG_SIZE][CS_RECT_REG_SIZE]; 00122 csRandomGen* rand; 00123 00124 // these values ought to help someone with a debugger 00125 // quickly locate and reproduce failed tests. 00126 unsigned int rand_seed; 00127 int num_tests_complete; 00128 00129 public: 00130 csRectRegionDebug(); 00131 ~csRectRegionDebug(); 00132 00134 void Include(const csRect &rect); 00135 00137 void Exclude(const csRect &rect); 00138 00140 void ClipTo(const csRect &clip); 00141 00143 void MakeEmpty(); 00144 00147 void AssertEqual(const csRectRegion &r); 00148 00150 bool CheckBounds(const csRect &clip); 00151 00153 void UnitTest(); 00154 00156 csRect RandRect(); 00157 00159 csRect RandNonEmptyRect(); 00160 }; 00161 00162 #endif // CS_DEBUG 00163 00167 #endif // __CS_CSRECTREGION_H__
Generated for Crystal Space by doxygen 1.2.18