Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_interval.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_interval.cpp (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_interval.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_interval.h" 11 #include "qwt_math.h" 12 #include <qalgorithms.h> 13 14 /*! 15 \brief Normalize the limits of the interval 16 17 If maxValue() < minValue() the limits will be inverted. 18 \return Normalized interval 19 20 \sa isValid(), inverted() 21 */ 11 12 namespace 13 { 14 static const struct RegisterQwtInterval 15 { 16 inline RegisterQwtInterval() { qRegisterMetaType< QwtInterval >(); } 17 18 } qwtRegisterQwtInterval; 19 } 20 21 /*! 22 \brief Normalize the limits of the interval 23 24 If maxValue() < minValue() the limits will be inverted. 25 \return Normalized interval 26 27 \sa isValid(), inverted() 28 */ 22 29 QwtInterval QwtInterval::normalized() const 23 30 { 24 if ( d_minValue >d_maxValue )31 if ( m_minValue > m_maxValue ) 25 32 { 26 33 return inverted(); 27 34 } 28 if ( d_minValue ==d_maxValue &&d_borderFlags == ExcludeMinimum )35 if ( m_minValue == m_maxValue && m_borderFlags == ExcludeMinimum ) 29 36 { 30 37 return inverted(); … … 35 42 36 43 /*! 37 Invert the limits of the interval 38 \return Inverted interval 39 \sa normalized() 40 */ 44 Invert the limits of the interval 45 \return Inverted interval 46 \sa normalized() 47 */ 41 48 QwtInterval QwtInterval::inverted() const 42 49 { 43 50 BorderFlags borderFlags = IncludeBorders; 44 if ( d_borderFlags & ExcludeMinimum ) 51 52 if ( m_borderFlags & ExcludeMinimum ) 45 53 borderFlags |= ExcludeMaximum; 46 if ( d_borderFlags & ExcludeMaximum ) 54 55 if ( m_borderFlags & ExcludeMaximum ) 47 56 borderFlags |= ExcludeMinimum; 48 57 49 return QwtInterval( d_maxValue,d_minValue, borderFlags );50 } 51 52 /*! 53 Test if a value is inside an interval 54 55 \param value Value 56 \return true, if value >= minValue() && value <= maxValue()57 */ 58 return QwtInterval( m_maxValue, m_minValue, borderFlags ); 59 } 60 61 /*! 62 Test if a value is inside an interval 63 64 \param value Value 65 \return true, if value lies inside the boundaries 66 */ 58 67 bool QwtInterval::contains( double value ) const 59 68 { … … 61 70 return false; 62 71 63 if ( value < d_minValue||value >d_maxValue )64 return false; 65 66 if ( value == d_minValue&& d_borderFlags & ExcludeMinimum )67 return false; 68 69 if ( value == d_maxValue&& d_borderFlags & ExcludeMaximum )72 if ( ( value < m_minValue ) || ( value > m_maxValue ) ) 73 return false; 74 75 if ( ( value == m_minValue ) && ( m_borderFlags & ExcludeMinimum ) ) 76 return false; 77 78 if ( ( value == m_maxValue ) && ( m_borderFlags & ExcludeMaximum ) ) 70 79 return false; 71 80 … … 73 82 } 74 83 84 /*! 85 Test if an interval is inside an interval 86 87 \param interval Interval 88 \return true, if interval lies inside the boundaries 89 */ 90 bool QwtInterval::contains( const QwtInterval& interval ) const 91 { 92 if ( !isValid() || !interval.isValid() ) 93 return false; 94 95 if ( ( interval.m_minValue < m_minValue ) || ( interval.m_maxValue > m_maxValue ) ) 96 return false; 97 98 if ( m_borderFlags ) 99 { 100 if ( interval.m_minValue == m_minValue ) 101 { 102 if ( ( m_borderFlags & ExcludeMinimum ) 103 && !( interval.m_borderFlags & ExcludeMinimum ) ) 104 { 105 return false; 106 } 107 } 108 109 if ( interval.m_maxValue == m_maxValue ) 110 { 111 if ( ( m_borderFlags & ExcludeMaximum ) 112 && !( interval.m_borderFlags & ExcludeMaximum ) ) 113 { 114 return false; 115 } 116 } 117 } 118 119 return true; 120 } 121 75 122 //! Unite 2 intervals 76 QwtInterval QwtInterval::unite( const QwtInterval &other ) const123 QwtInterval QwtInterval::unite( const QwtInterval& other ) const 77 124 { 78 125 /* 79 If one of the intervals is invalid return the other one. 80 If both are invalid return an invalid default interval 126 If one of the intervals is invalid return the other one. 127 If both are invalid return an invalid default interval 81 128 */ 82 129 if ( !isValid() ) … … 94 141 95 142 // minimum 96 if ( d_minValue < other.minValue() )97 { 98 united.setMinValue( d_minValue );99 flags &= d_borderFlags & ExcludeMinimum;100 } 101 else if ( other.minValue() < d_minValue )143 if ( m_minValue < other.minValue() ) 144 { 145 united.setMinValue( m_minValue ); 146 flags &= m_borderFlags & ExcludeMinimum; 147 } 148 else if ( other.minValue() < m_minValue ) 102 149 { 103 150 united.setMinValue( other.minValue() ); 104 151 flags &= other.borderFlags() & ExcludeMinimum; 105 152 } 106 else // d_minValue == other.minValue()107 { 108 united.setMinValue( d_minValue );109 flags &= ( d_borderFlags & other.borderFlags() ) & ExcludeMinimum;153 else // m_minValue == other.minValue() 154 { 155 united.setMinValue( m_minValue ); 156 flags &= ( m_borderFlags & other.borderFlags() ) & ExcludeMinimum; 110 157 } 111 158 112 159 // maximum 113 if ( d_maxValue > other.maxValue() )114 { 115 united.setMaxValue( d_maxValue );116 flags &= d_borderFlags & ExcludeMaximum;117 } 118 else if ( other.maxValue() > d_maxValue )160 if ( m_maxValue > other.maxValue() ) 161 { 162 united.setMaxValue( m_maxValue ); 163 flags &= m_borderFlags & ExcludeMaximum; 164 } 165 else if ( other.maxValue() > m_maxValue ) 119 166 { 120 167 united.setMaxValue( other.maxValue() ); 121 168 flags &= other.borderFlags() & ExcludeMaximum; 122 169 } 123 else // d_maxValue == other.maxValue() )124 { 125 united.setMaxValue( d_maxValue );126 flags &= d_borderFlags & other.borderFlags() & ExcludeMaximum;170 else // m_maxValue == other.maxValue() ) 171 { 172 united.setMaxValue( m_maxValue ); 173 flags &= m_borderFlags & other.borderFlags() & ExcludeMaximum; 127 174 } 128 175 … … 132 179 133 180 /*! 134 \brief Intersect 2 intervals 135 136 \param other Interval to be intersect with 137 \return Intersection 138 */ 139 QwtInterval QwtInterval::intersect( const QwtInterval &other ) const181 \brief Intersect 2 intervals 182 183 \param other Interval to be intersect with 184 \return Intersection 185 */ 186 QwtInterval QwtInterval::intersect( const QwtInterval& other ) const 140 187 { 141 188 if ( !other.isValid() || !isValid() ) … … 199 246 200 247 /*! 201 \brief Unite this interval with the given interval. 202 203 \param other Interval to be united with 204 \return This interval 205 */ 206 QwtInterval& QwtInterval::operator|=( const QwtInterval &other )248 \brief Unite this interval with the given interval. 249 250 \param other Interval to be united with 251 \return This interval 252 */ 253 QwtInterval& QwtInterval::operator|=( const QwtInterval& other ) 207 254 { 208 255 *this = *this | other; … … 211 258 212 259 /*! 213 \brief Intersect this interval with the given interval. 214 215 \param other Interval to be intersected with 216 \return This interval 217 */ 218 QwtInterval& QwtInterval::operator&=( const QwtInterval &other )260 \brief Intersect this interval with the given interval. 261 262 \param other Interval to be intersected with 263 \return This interval 264 */ 265 QwtInterval& QwtInterval::operator&=( const QwtInterval& other ) 219 266 { 220 267 *this = *this & other; … … 223 270 224 271 /*! 225 \brief Test if two intervals overlap 226 227 \param other Interval 228 \return True, when the intervals are intersecting 229 */ 230 bool QwtInterval::intersects( const QwtInterval &other ) const272 \brief Test if two intervals overlap 273 274 \param other Interval 275 \return True, when the intervals are intersecting 276 */ 277 bool QwtInterval::intersects( const QwtInterval& other ) const 231 278 { 232 279 if ( !isValid() || !other.isValid() ) … … 244 291 } 245 292 else if ( i1.minValue() == i2.minValue() && 246 i1.borderFlags() & ExcludeMinimum )293 i1.borderFlags() & ExcludeMinimum ) 247 294 { 248 295 qSwap( i1, i2 ); … … 256 303 { 257 304 return !( ( i1.borderFlags() & ExcludeMaximum ) || 258 ( i2.borderFlags() & ExcludeMinimum ) ); 305 ( i2.borderFlags() & ExcludeMinimum ) ); 259 306 } 260 307 return false; … … 262 309 263 310 /*! 264 Adjust the limit that is closer to value, so that value becomes 265 the center of the interval. 266 267 \param value Center 268 \return Interval with value as center 269 */ 311 Adjust the limit that is closer to value, so that value becomes 312 the center of the interval. 313 314 \param value Center 315 \return Interval with value as center 316 */ 270 317 QwtInterval QwtInterval::symmetrize( double value ) const 271 318 { … … 274 321 275 322 const double delta = 276 qMax( qAbs( value - d_maxValue ), qAbs( value -d_minValue ) );323 qMax( qAbs( value - m_maxValue ), qAbs( value - m_minValue ) ); 277 324 278 325 return QwtInterval( value - delta, value + delta ); … … 280 327 281 328 /*! 282 Limit the interval, keeping the border modes 283 284 \param lowerBound Lower limit 285 \param upperBound Upper limit 286 287 \return Limited interval 288 */ 329 Limit the interval, keeping the border modes 330 331 \param lowerBound Lower limit 332 \param upperBound Upper limit 333 334 \return Limited interval 335 */ 289 336 QwtInterval QwtInterval::limited( double lowerBound, double upperBound ) const 290 337 { … … 292 339 return QwtInterval(); 293 340 294 double minValue = qMax( d_minValue, lowerBound );341 double minValue = qMax( m_minValue, lowerBound ); 295 342 minValue = qMin( minValue, upperBound ); 296 343 297 double maxValue = qMax( d_maxValue, lowerBound );344 double maxValue = qMax( m_maxValue, lowerBound ); 298 345 maxValue = qMin( maxValue, upperBound ); 299 346 300 return QwtInterval( minValue, maxValue, d_borderFlags );301 } 302 303 /*! 304 \brief Extend the interval 305 306 If value is below minValue(), value becomes the lower limit. 307 If value is above maxValue(), value becomes the upper limit. 308 309 extend() has no effect for invalid intervals 310 311 \param value Value 312 \return extended interval 313 314 \sa isValid() 315 */ 347 return QwtInterval( minValue, maxValue, m_borderFlags ); 348 } 349 350 /*! 351 \brief Extend the interval 352 353 If value is below minValue(), value becomes the lower limit. 354 If value is above maxValue(), value becomes the upper limit. 355 356 extend() has no effect for invalid intervals 357 358 \param value Value 359 \return extended interval 360 361 \sa isValid() 362 */ 316 363 QwtInterval QwtInterval::extend( double value ) const 317 364 { … … 319 366 return *this; 320 367 321 return QwtInterval( qMin( value, d_minValue ),322 qMax( value, d_maxValue ),d_borderFlags );323 } 324 325 /*! 326 Extend an interval 327 328 \param value Value 329 \return Reference of the extended interval 330 331 \sa extend() 332 */ 368 return QwtInterval( qMin( value, m_minValue ), 369 qMax( value, m_maxValue ), m_borderFlags ); 370 } 371 372 /*! 373 Extend an interval 374 375 \param value Value 376 \return Reference of the extended interval 377 378 \sa extend() 379 */ 333 380 QwtInterval& QwtInterval::operator|=( double value ) 334 381 { … … 339 386 #ifndef QT_NO_DEBUG_STREAM 340 387 341 QDebug operator<<( QDebug debug, const QwtInterval &interval ) 388 #include <qdebug.h> 389 390 QDebug operator<<( QDebug debug, const QwtInterval& interval ) 342 391 { 343 392 const int flags = interval.borderFlags(); 344 393 345 394 debug.nospace() << "QwtInterval(" 346 << ( ( flags & QwtInterval::ExcludeMinimum ) ? "]" : "[" )347 << interval.minValue() << "," << interval.maxValue() 348 << ( ( flags & QwtInterval::ExcludeMaximum ) ? "[" : "]" )349 << ")"; 395 << ( ( flags& QwtInterval::ExcludeMinimum ) ? "]" : "[" ) 396 << interval.minValue() << "," << interval.maxValue() 397 << ( ( flags& QwtInterval::ExcludeMaximum ) ? "[" : "]" ) 398 << ")"; 350 399 351 400 return debug.space();
Note:
See TracChangeset
for help on using the changeset viewer.
