00001 #include "HTL/Even_Partition.h"
00002
00003
00004
00005
00006
00007
00008
00009 #define TEMPLATE___
00010 #define CLASS___ Even_Partition
00011 #define T_Point double
00012
00013
00014 TEMPLATE___
00015 CLASS___::Even_Partition( Size a_bin_count,
00016 T_Point a_leftmost_point, T_Point a_rightmost_point,
00017 End_Point_Convention a_convention )
00018 #ifdef HTL_USE_EXCEPTIONS
00019 throw (HTLExceptions::WrongLimits,HTLExceptions::WrongBins)
00020 #endif //HTL_USE_EXCEPTIONS
00021 : I_Partition()
00022 {
00023 if (a_leftmost_point < a_rightmost_point) {
00024 if (a_bin_count > 0) {
00025 count_ = a_bin_count;
00026 lower_point_ = a_leftmost_point;
00027 upper_point_ = a_rightmost_point;
00028 bin_width_ = (upper_point_ - lower_point_) / count_;
00029 end_point_convention_ = a_convention;
00030
00031 if (!( (bin_width_ > 0) && (count_ > 0) ))
00032 HTL_ERR("(bin_width_ > 0) && (count_ > 0)");
00033 } else {
00034 HTL_ERR("The number of bins is not greater than 0 ");
00035 #ifdef HTL_USE_EXCEPTIONS
00036 throw HTLExceptions::WrongBins();
00037 #endif //HTL_USE_EXCEPTIONS
00038 }
00039 } else {
00040 HTL_ERR("The histogram low limit is greater than the high limit");
00041 #ifdef HTL_USE_EXCEPTIONS
00042 throw HTLExceptions::WrongLimits();
00043 #endif //HTL_USE_EXCEPTIONS
00044 }
00045 }
00046
00047
00048 TEMPLATE___
00049 CLASS___::Even_Partition( I_Partition &another )
00050 #ifdef HTL_USE_EXCEPTIONS
00051 throw (HTLExceptions::IncompatiblePartition)
00052 #endif //HTL_USE_EXCEPTIONS
00053 : count_( another.bin_count() )
00054 , lower_point_( T_Point( another.i_lower_point() ) )
00055 , upper_point_( T_Point( another.i_upper_point() ) )
00056 , end_point_convention_( another.end_point_convention() )
00057
00058 {
00059 bin_width_ = (upper_point_ - lower_point_) / count_;
00060
00061
00062
00063
00064
00065 for( Index i=1; i<count_; i++ ) {
00066 if (!(bin_width_ == T_Point( another.i_bin_width(i)))) {
00067 HTL_ERR("*Uneven_Partition arg can't match an Even_Partition");
00068 #ifdef HTL_USE_EXCEPTIONS
00069 throw HTLExceptions::IncompatiblePartition();
00070 #endif //HTL_USE_EXCEPTIONS
00071 }
00072 }
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 TEMPLATE___
00093 void CLASS___::map_index1( T_Point a_point, Index &an_index,
00094 Extra_Index &an_extra_index )
00095 {
00096
00097
00098
00099
00100
00101
00102
00103
00104 if( a_point < lower_point() ) {
00105
00106 an_extra_index = H_UNDERFLOW;
00107 return;
00108
00109 } else if( a_point > upper_point() ) {
00110
00111 an_extra_index = H_OVERFLOW;
00112 return;
00113 }
00114
00115
00116 if (!( a_point >= lower_point() && a_point <= upper_point() )) {
00117 HTL_ERR("a_point >= lower_point() && a_point <= upper_point()");
00118 return;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127 an_index = Index( (a_point - lower_point()) / bin_width_ );
00128
00129 if (!( an_index >= 0 && an_index <= count_ )) {
00130 HTL_ERR("( an_index >= 0 && an_index <= count_ )");
00131 return;
00132 }
00133
00134
00135
00136
00137
00138
00139
00140 if( end_point_convention_ == LEFT_OPEN ) {
00141 if( (upper_point() == a_point) ||
00142 (lower_point(an_index) == a_point) )
00143 {
00144
00145
00146
00147
00148 an_index --;
00149 }
00150 }
00151
00152 if( an_index < 0 ) {
00153
00154
00155 an_extra_index = H_UNDERFLOW;
00156 return;
00157
00158 } else if( an_index >= bin_count() ) {
00159
00160
00161
00162 an_extra_index = H_OVERFLOW;
00163 return;
00164 }
00165
00166
00167
00168 an_extra_index = H_IN_RANGE;
00169
00170
00171 if (! (an_index >= 0) && (an_index < count_))
00172 HTL_ERR("(an_index >= 0) && (an_index < count_)");
00173
00174 }
00175
00176
00177
00178
00179
00180
00181 #undef double
00182 #undef CLASS___
00183 #undef TEMPLATE___
00184
00185