qwt_interval.h
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
10 #ifndef QWT_INTERVAL_H
11 #define QWT_INTERVAL_H
12 
13 #include "qwt_global.h"
14 #include <qmetatype.h>
15 
16 #ifndef QT_NO_DEBUG_STREAM
17 #include <qdebug.h>
18 #endif
19 
27 {
28 public:
34  {
36  IncludeBorders = 0x00,
37 
39  ExcludeMinimum = 0x01,
40 
42  ExcludeMaximum = 0x02,
43 
45  ExcludeBorders = ExcludeMinimum | ExcludeMaximum
46  };
47 
49  typedef QFlags<BorderFlag> BorderFlags;
50 
51  QwtInterval();
52  QwtInterval( double minValue, double maxValue,
53  BorderFlags = IncludeBorders );
54 
55  void setInterval( double minValue, double maxValue,
56  BorderFlags = IncludeBorders );
57 
58  QwtInterval normalized() const;
59  QwtInterval inverted() const;
60  QwtInterval limited( double minValue, double maxValue ) const;
61 
62  bool operator==( const QwtInterval & ) const;
63  bool operator!=( const QwtInterval & ) const;
64 
65  void setBorderFlags( BorderFlags );
66  BorderFlags borderFlags() const;
67 
68  double minValue() const;
69  double maxValue() const;
70 
71  double width() const;
72  long double widthL() const;
73 
74  void setMinValue( double );
75  void setMaxValue( double );
76 
77  bool contains( double value ) const;
78 
79  bool intersects( const QwtInterval & ) const;
80  QwtInterval intersect( const QwtInterval & ) const;
81  QwtInterval unite( const QwtInterval & ) const;
82 
83  QwtInterval operator|( const QwtInterval & ) const;
84  QwtInterval operator&( const QwtInterval & ) const;
85 
88 
89  QwtInterval extend( double value ) const;
90  QwtInterval operator|( double ) const;
91  QwtInterval &operator|=( double );
92 
93  bool isValid() const;
94  bool isNull() const;
95  void invalidate();
96 
97  QwtInterval symmetrize( double value ) const;
98 
99 private:
100  double d_minValue;
101  double d_maxValue;
102  BorderFlags d_borderFlags;
103 };
104 
105 Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE);
106 
114  d_minValue( 0.0 ),
115  d_maxValue( -1.0 ),
116  d_borderFlags( IncludeBorders )
117 {
118 }
119 
130  double minValue, double maxValue, BorderFlags borderFlags ):
131  d_minValue( minValue ),
132  d_maxValue( maxValue ),
133  d_borderFlags( borderFlags )
134 {
135 }
136 
145  double minValue, double maxValue, BorderFlags borderFlags )
146 {
150 }
151 
159 {
161 }
162 
168 {
169  return d_borderFlags;
170 }
171 
177 inline void QwtInterval::setMinValue( double minValue )
178 {
180 }
181 
187 inline void QwtInterval::setMaxValue( double maxValue )
188 {
190 }
191 
193 inline double QwtInterval::minValue() const
194 {
195  return d_minValue;
196 }
197 
199 inline double QwtInterval::maxValue() const
200 {
201  return d_maxValue;
202 }
203 
211 inline bool QwtInterval::isValid() const
212 {
213  if ( ( d_borderFlags & ExcludeBorders ) == 0 )
214  return d_minValue <= d_maxValue;
215  else
216  return d_minValue < d_maxValue;
217 }
218 
228 inline double QwtInterval::width() const
229 {
230  return isValid() ? ( d_maxValue - d_minValue ) : 0.0;
231 }
232 
242 inline long double QwtInterval::widthL() const
243 {
244  if ( !isValid() )
245  return 0.0;
246 
247  return static_cast<long double>( d_maxValue )
248  - static_cast<long double>( d_minValue );
249 }
250 
260  const QwtInterval &other ) const
261 {
262  return intersect( other );
263 }
264 
274  const QwtInterval &other ) const
275 {
276  return unite( other );
277 }
278 
285 inline bool QwtInterval::operator==( const QwtInterval &other ) const
286 {
287  return ( d_minValue == other.d_minValue ) &&
288  ( d_maxValue == other.d_maxValue ) &&
289  ( d_borderFlags == other.d_borderFlags );
290 }
297 inline bool QwtInterval::operator!=( const QwtInterval &other ) const
298 {
299  return ( !( *this == other ) );
300 }
301 
309 inline QwtInterval QwtInterval::operator|( double value ) const
310 {
311  return extend( value );
312 }
313 
315 inline bool QwtInterval::isNull() const
316 {
317  return isValid() && d_minValue >= d_maxValue;
318 }
319 
327 {
328  d_minValue = 0.0;
329  d_maxValue = -1.0;
330 }
331 
332 Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags )
333 Q_DECLARE_METATYPE( QwtInterval )
334 
335 #ifndef QT_NO_DEBUG_STREAM
336 QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval & );
337 #endif
338 
339 #endif
bool operator!=(const QwtInterval &) const
Compare two intervals.
Definition: qwt_interval.h:297
QFlags< BorderFlag > BorderFlags
Border flags.
Definition: qwt_interval.h:49
chars_format & operator|=(chars_format &lhs, chars_format rhs)
constexpr chars_format operator|(chars_format lhs, chars_format rhs)
A class representing an interval.
Definition: qwt_interval.h:26
#define QWT_EXPORT
Definition: qwt_global.h:38
bool operator==(optional< T > const &x, optional< T > const &y)
Definition: optional.hpp:854
double minValue() const
Definition: qwt_interval.h:193
long double widthL() const
Return the width of an interval as long double.
Definition: qwt_interval.h:242
double maxValue() const
Definition: qwt_interval.h:199
QWT_EXPORT QDebug operator<<(QDebug, const QwtInterval &)
QwtInterval unite(const QwtInterval &) const
Unite 2 intervals.
TFSIMD_FORCE_INLINE Vector3 normalized() const
QwtInterval operator|(const QwtInterval &) const
Definition: qwt_interval.h:273
void setInterval(double minValue, double maxValue, BorderFlags=IncludeBorders)
Definition: qwt_interval.h:144
QwtInterval operator&(const QwtInterval &) const
Intersection of two intervals.
Definition: qwt_interval.h:259
QwtInterval intersect(const QwtInterval &) const
Intersect 2 intervals.
bool isValid() const
Definition: qwt_interval.h:211
bool isNull() const
Definition: qwt_interval.h:315
QwtInterval()
Default Constructor.
Definition: qwt_interval.h:113
BorderFlags d_borderFlags
Definition: qwt_interval.h:102
Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE)
void setBorderFlags(BorderFlags)
Definition: qwt_interval.h:158
BorderFlags borderFlags() const
Definition: qwt_interval.h:167
bool operator==(const QwtInterval &) const
Compare two intervals.
Definition: qwt_interval.h:285
double d_maxValue
Definition: qwt_interval.h:101
constexpr chars_format operator&(chars_format lhs, chars_format rhs)
void setMinValue(double)
Definition: qwt_interval.h:177
void invalidate()
Definition: qwt_interval.h:326
QwtInterval extend(double value) const
Extend the interval.
double d_minValue
Definition: qwt_interval.h:100
Min/Max values are not included in the interval.
Definition: qwt_interval.h:45
chars_format & operator&=(chars_format &lhs, chars_format rhs)
double width() const
Return the width of an interval.
Definition: qwt_interval.h:228
void setMaxValue(double)
Definition: qwt_interval.h:187
bool operator!=(optional< T > const &x, optional< T > const &y)
Definition: optional.hpp:859


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17