## Public API Reference

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

- File List
- File Members

# 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 #include "csutil/array.h"
    00033
    00034 #ifdef CS_DEBUG
    00035 // defining this causes the csRectRegionDebug class to be compiled in
    00036 //#define CS_DEBUG_RECT_REG
    00037 #endif
    00038
    00039 #ifdef CS_DEBUG_RECT_REG
    00040   class csRandomGen;
    00041 #endif
    00042
    00055 class CS_CRYSTALSPACE_EXPORT csRectRegion
    00056 {
    00057 protected:
    00058   static const size_t FRAGMENT_BUFFER_SIZE=64;
    00059
    00061   csArray<csRect> region;
    00063   csRect fragment[FRAGMENT_BUFFER_SIZE];
    00065   size_t gather_mark;
    00066
    00071   void fragmentRect(csRect&, csRect&, int mode);
    00072   void nkSplit(csRect& r1, csRect& r2);
    00074   void fragmentContainedRect(csRect &r1, csRect &r2);
    00076   void markForGather();
    00078   void gatherFragments();
    00079
    00080 public:
    00082   csRectRegion();
    00084   ~csRectRegion();
    00085
    00090   void Include(const csRect &rect);
    00092   void Exclude(const csRect &rect);
    00094   void ClipTo(csRect &clip);
    00095
    00097   inline size_t Count() const { return region.GetSize(); }
    00099   inline const csRect& RectAt(size_t i) const { return region[i]; }
    00101   void MakeEmpty();
    00102 };
    00103
    00104
    00105
    00106 #ifdef CS_DEBUG_RECT_REG
    00107
    00108 // this class is an alternate implementation of rectRegion
    00109 // it uses a 100 x 100 bool array to represent which pixels
    00110 // in that area are contained in a rectangle. This class is
    00111 // intended solely to aid in debugging the csRectRegion class.
    00112
    00113 #define CS_RECT_REG_SIZE 100
    00114
    00115 class CS_CRYSTALSPACE_EXPORT csRectRegionDebug
    00116 {
    00117 private:
    00118   bool area[CS_RECT_REG_SIZE][CS_RECT_REG_SIZE];
    00119   csRandomGen* rand;
    00120
    00121   // these values ought to help someone with a debugger
    00122   // quickly locate and reproduce failed tests.
    00123   unsigned int rand_seed;
    00124   int num_tests_complete;
    00125
    00126 public:
    00127   csRectRegionDebug();
    00128   ~csRectRegionDebug();
    00129
    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
    00149   void AssertEqual(const csRectRegion &r);
    00150
    00152   bool CheckBounds(const csRect &clip);
    00153
    00155   void UnitTest();
    00156
    00158   csRect RandRect();
    00159
    00161   csRect RandNonEmptyRect();
    00162 };
    00163
    00164 #endif // CS_DEBUG
    00165
    00169 #endif // __CS_CSRECTREGION_H__