00001 //================================================================================================== 00002 // Copyright (C) 2010 Brian Tietz sdbtietz at yahoo dot com 00003 // 00004 // This program is free software; you can redistribute it and/or modify it under the terms of the 00005 // GNU General Public License as published by the Free Software Foundation, version 2.0 of the 00006 // License. 00007 // 00008 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 00009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00010 // General Public License for more details. 00011 // 00012 // You should have received a copy of the GNU General Public License along with this program; if 00013 // not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00014 // 02110-1301, USA. 00015 // 00016 // For commercial software, the copyright holder (Brian Tietz, email sdbtietz at yahoo dot com) 00017 // reserves the right and is willing to waive the proprietary source code disclosure aspects of that 00018 // license as applied to the UT library in exchange for either substantial contributions to the 00019 // development of the UT library or other forms of compensation. Any such waiver must be 00020 // established in writing between the copyright holder and the commercial entity obtaining such a 00021 // waiver. 00022 //================================================================================================== 00023 00024 00025 //================================================================================================== 00026 //=== Project headers 00027 //================================================================================================== 00028 #include "UTGeometry.h" 00029 #include "UTPoolAllocator.h" 00030 00031 00032 // \cond DOXYGEN_DOCUMENT_NEVER 00033 00034 00035 //================================================================================================== 00036 struct RegionHStripeRect_t 00037 //================================================================================================== 00038 { 00039 float left; 00040 float right; 00041 }; 00042 00043 00044 //================================================================================================== 00045 class RegionHStripe_t 00046 //================================================================================================== 00047 : public BTreeNode_t< RegionHStripe_t, float > 00048 { 00049 //---------------------------------------------------------------------------------------------- 00050 public: 00051 //---------------------------------------------------------------------------------------------- 00052 RegionHStripe_t( const Rect_t& rect, PoolAllocator_t* allocator ); 00053 RegionHStripe_t( const RegionHStripe_t& copy_x, 00054 float top, 00055 float bottom, 00056 PoolAllocator_t* allocator ); 00057 inline ~RegionHStripe_t(); // Should never be called. Instead... 00058 inline void Delete(PoolAllocator_t* allocator); 00059 00060 inline void* operator new( size_t size, PoolAllocator_t* allocator ); 00061 inline void operator delete( void* block, PoolAllocator_t* allocator ); 00062 00063 inline int Compare(float other_top) const; 00064 inline operator float() const; 00065 00066 bool Contains( float left, float right ); 00067 // Returns true if the stripe ENTIRELY contains from left to right 00068 bool Contains(float x); 00069 // Returns true if the stripe contains the x value 00070 bool Overlapping( float left, float right ); 00071 // Returns true if the stripe PARTIALLY contains from left to right 00072 inline bool Excludes( float left, float right ); 00073 // Returns true if the stripe DOES NOT contain ANY of the space from 00074 // left to right 00075 bool Add( float left, float right, PoolAllocator_t* allocator ); 00076 // Returns true if anything was changed 00077 bool Remove( float left, float right, PoolAllocator_t* allocator ); 00078 // Returns true if anything was changed 00079 bool ConstrainSides( float left, float right ); 00080 // Returns true if anything was changed 00081 void Shift(const Point_t& offset); 00082 bool EqualInXDomain(const RegionHStripe_t& other); 00083 00084 //---------------------------------------------------------------------------------------------- 00085 private: 00086 //---------------------------------------------------------------------------------------------- 00087 void MakeRoomToAddOne(PoolAllocator_t* allocator); 00088 00089 //---------------------------------------------------------------------------------------------- 00090 private: 00091 //---------------------------------------------------------------------------------------------- 00092 float m_top; 00093 float m_bottom; 00094 int m_base_index; 00095 int m_num_allocated_stripe_left_right_pairs; 00096 RegionHStripeRect_t* m_rects_left_right_pairs; 00097 int m_num_valid_stripe_left_right_pairs; 00098 00099 friend class Region_t; 00100 }; 00101 00102 00103 00104 00105 //================================================================================================== 00106 //================================================================================================== 00107 //=== 00108 //=== Inline function implementations: class RegionHStripe_t 00109 //=== 00110 //================================================================================================== 00111 //================================================================================================== 00112 inline void* 00113 RegionHStripe_t::operator new( size_t size, PoolAllocator_t* allocator ) 00114 { 00115 return allocator->Allocate(size); 00116 } 00117 00118 00119 inline 00120 RegionHStripe_t::~RegionHStripe_t() 00121 { 00122 // GCC 4.3.2 supports the syntax for placement operator delete to be declared, but not for it 00123 // to be invoked. Some cursory research shows that if placement operator delete was 00124 // standardized, that was fairly recent. 00125 00126 // From: Bjarne Stroustrup's C++ Style and Technique FAQ 00127 // http://public.research.att.com/~bs/bs_faq2.html#placement-delete 00128 // Q: Is there a "placement delete"? 00129 // A: No but if you need one you can write your own. 00130 00131 // Placement delete is defined for this class not to implement it, but to assure that Delete is 00132 // called instead. The real destructor should never be invoked. 00133 rel_assert("This should never be called"); 00134 } 00135 00136 00137 inline void 00138 RegionHStripe_t::operator delete( void* block, PoolAllocator_t* allocator ) 00139 { 00140 // Placement delete is defined for this class not to implement it, but to assure that Release 00141 // is called instead. See above. 00142 00143 rel_assert("This should never be called"); 00144 } 00145 00146 00147 inline void 00148 RegionHStripe_t::Delete(PoolAllocator_t* allocator) 00149 { 00150 if(m_rects_left_right_pairs) 00151 allocator->Release(m_rects_left_right_pairs); 00152 allocator->Release(this); 00153 } 00154 00155 00156 inline int 00157 RegionHStripe_t::Compare(float other_top) const 00158 { 00159 if(m_top < other_top) 00160 return -1; 00161 if(m_top > other_top) 00162 return 1; 00163 return 0; 00164 } 00165 00166 00167 inline 00168 RegionHStripe_t::operator float() const 00169 { 00170 return m_top; 00171 } 00172 00173 00174 inline bool 00175 RegionHStripe_t::Excludes( float left, float right ) 00176 { 00177 return !Overlapping( left, right ); 00178 } 00179 00180 00181 // \endcond