21 return std::log( value ) / std::log( base );
33 std::pow( base, interval.
maxValue() ) );
39 static double qwtStepSize(
double intervalSize,
int maxSteps, uint base )
41 const double minStep =
47 const int numTicks =
qwtCeil( qAbs( intervalSize / minStep ) ) - 1;
51 qAbs( intervalSize ), intervalSize ) > 0 )
54 return 0.5 * intervalSize;
63 static double qwtStepSize(
double intervalSize,
int maxSteps, uint base )
70 for (
int numSteps = maxSteps; numSteps > 1; numSteps-- )
72 const double stepSize = intervalSize / numSteps;
74 const double p = std::floor( std::log( stepSize ) / std::log( base ) );
75 const double fraction = std::pow( base, p );
77 for ( uint n = base; n > 1; n /= 2 )
79 if ( qFuzzyCompare( stepSize, n * fraction ) )
82 if ( n == 3 && ( base % 2 ) == 0 )
84 if ( qFuzzyCompare( stepSize, 2 * fraction ) )
91 return intervalSize * 0.5;
96 static const double _eps = 1.0e-6;
109 double intervalSize )
111 const double eps =
_eps * intervalSize;
113 value = ( value - eps ) / intervalSize;
114 return std::ceil( value ) * intervalSize;
128 const double eps =
_eps * intervalSize;
130 value = ( value + eps ) / intervalSize;
131 return std::floor( value ) * intervalSize;
145 if ( numSteps == 0.0 || intervalSize == 0.0 )
148 return ( intervalSize - (
_eps * intervalSize ) ) / numSteps;
161 double intervalSize,
int numSteps, uint base )
170 const double lx =
qwtLog( base, std::fabs( v ) );
171 const double p = std::floor( lx );
173 const double fraction = std::pow( base, lx - p );
176 while ( ( n > 1 ) && ( fraction <= n / 2 ) )
179 double stepSize = n * std::pow( base, p );
181 stepSize = -stepSize;
193 referenceValue( 0.0 ),
252 delete m_data->transform;
253 m_data->transform = transform;
268 if ( m_data->transform )
282 return m_data->lowerMargin;
293 return m_data->upperMargin;
314 m_data->lowerMargin =
qwtMaxF( lower, 0.0 );
315 m_data->upperMargin =
qwtMaxF( upper, 0.0 );
327 double intervalSize,
int numSteps )
const 330 intervalSize, numSteps, m_data->base );
367 if ( !interval.
isValid() || ticks.count() == 0 )
370 if ( contains( interval, ticks.first() )
371 && contains( interval, ticks.last() ) )
377 for (
int i = 0; i < ticks.count(); i++ )
379 if ( contains( interval, ticks[i] ) )
380 strippedTicks += ticks[i];
382 return strippedTicks;
397 const double delta = ( value == 0.0 ) ? 0.5 : qAbs( 0.5 * value );
398 const double max = std::numeric_limits< double >::max();
400 if ( max - delta < value )
403 if ( -max + delta > value )
406 return QwtInterval( value - delta, value + delta );
420 m_data->attributes |= attribute;
422 m_data->attributes &= ~attribute;
433 return ( m_data->attributes & attribute );
444 m_data->attributes = attributes;
453 return m_data->attributes;
476 return m_data->referenceValue;
493 m_data->base = qMax( base, 2U );
532 double& x1,
double& x2,
double& stepSize )
const 546 if ( interval.
width() == 0.0 )
550 interval.
width(), qMax( maxNumSteps, 1 ),
base() );
553 interval =
align( interval, stepSize );
561 stepSize = -stepSize;
578 int maxMajorSteps,
int maxMinorSteps,
double stepSize )
const 582 if ( interval.
widthL() > std::numeric_limits< double >::max() )
584 qWarning() <<
"QwtLinearScaleEngine::divideScale: overflow";
588 if ( interval.
width() <= 0 )
591 stepSize = qAbs( stepSize );
592 if ( stepSize == 0.0 )
594 if ( maxMajorSteps < 1 )
598 interval.
width(), maxMajorSteps,
base() );
603 if ( stepSize != 0.0 )
606 buildTicks( interval, stepSize, maxMinorSteps, ticks );
628 const QwtInterval& interval,
double stepSize,
int maxMinorSteps,
636 if ( maxMinorSteps > 0 )
644 ticks[i] =
strip( ticks[i], interval );
648 for (
int j = 0; j < ticks[i].count(); j++ )
665 const QwtInterval& interval,
double stepSize )
const 667 int numTicks = qRound( interval.
width() / stepSize ) + 1;
668 if ( numTicks > 10000 )
672 ticks.reserve( numTicks );
675 for (
int i = 1; i < numTicks - 1; i++ )
676 ticks += interval.
minValue() + i * stepSize;
694 int maxMinorSteps,
double stepSize,
699 if ( minStep == 0.0 )
703 const int numTicks =
qwtCeil( qAbs( stepSize / minStep ) ) - 1;
707 medIndex = numTicks / 2;
711 for (
int i = 0; i < majorTicks.count(); i++ )
713 double val = majorTicks[i];
714 for (
int k = 0; k < numTicks; k++ )
718 double alignedValue = val;
723 mediumTicks += alignedValue;
725 minorTicks += alignedValue;
742 const QwtInterval& interval,
double stepSize )
const 750 const double eps = 0.000000000001;
751 const double max = std::numeric_limits< double >::max();
753 if ( -max + stepSize <= x1 )
756 if ( qAbs(x) <= eps || !qFuzzyCompare( x1, x ) )
760 if ( max - stepSize >= x2 )
763 if ( qAbs(x) <= eps || !qFuzzyCompare( x2, x ) )
798 double& x1,
double& x2,
double& stepSize )
const 803 const double logBase =
base();
817 linearScaler.
autoScale( maxNumSteps, x1, x2, stepSize );
820 linearInterval = linearInterval.
limited(
838 interval.
setInterval( logRef / delta, logRef * delta );
842 interval = interval.
extend( logRef );
846 if ( interval.
width() == 0.0 )
850 qMax( maxNumSteps, 1 ) );
851 if ( stepSize < 1.0 )
855 interval =
align( interval, stepSize );
863 stepSize = -stepSize;
880 int maxMajorSteps,
int maxMinorSteps,
double stepSize )
const 885 if ( interval.
width() <= 0 )
888 const double logBase =
base();
900 maxMajorSteps, maxMinorSteps, 0.0 );
903 stepSize = qAbs( stepSize );
904 if ( stepSize == 0.0 )
906 if ( maxMajorSteps < 1 )
911 if ( stepSize < 1.0 )
916 if ( stepSize != 0.0 )
919 buildTicks( interval, stepSize, maxMinorSteps, ticks );
941 const QwtInterval& interval,
double stepSize,
int maxMinorSteps,
949 if ( maxMinorSteps > 0 )
956 ticks[i] =
strip( ticks[i], interval );
968 const QwtInterval& interval,
double stepSize )
const 972 int numTicks = qRound( width / stepSize ) + 1;
973 if ( numTicks > 10000 )
976 const double lxmin = std::log( interval.
minValue() );
977 const double lxmax = std::log( interval.
maxValue() );
978 const double lstep = ( lxmax - lxmin ) /
double( numTicks - 1 );
981 ticks.reserve( numTicks );
985 for (
int i = 1; i < numTicks - 1; i++ )
986 ticks += std::exp( lxmin +
double( i ) * lstep );
1004 int maxMinorSteps,
double stepSize,
1008 const double logBase =
base();
1010 if ( stepSize < 1.1 )
1013 if ( minStep == 0.0 )
1016 const int numSteps = qRound( stepSize / minStep );
1018 int mediumTickIndex = -1;
1019 if ( ( numSteps > 2 ) && ( numSteps % 2 == 0 ) )
1020 mediumTickIndex = numSteps / 2;
1022 for (
int i = 0; i < majorTicks.count() - 1; i++ )
1024 const double v = majorTicks[i];
1025 const double s = logBase / numSteps;
1029 if ( !qFuzzyCompare( s, 1.0 ) )
1030 minorTicks += v * s;
1032 for (
int j = 2; j < numSteps; j++ )
1034 minorTicks += v * j * s;
1039 for (
int j = 1; j < numSteps; j++ )
1041 const double tick = v + j * v * ( logBase - 1 ) / numSteps;
1042 if ( j == mediumTickIndex )
1043 mediumTicks += tick;
1053 if ( minStep == 0.0 )
1056 if ( minStep < 1.0 )
1060 int numTicks = qRound( stepSize / minStep ) - 1;
1064 stepSize, stepSize ) > 0 )
1072 int mediumTickIndex = -1;
1073 if ( ( numTicks > 2 ) && ( numTicks % 2 ) )
1074 mediumTickIndex = numTicks / 2;
1077 const qreal minFactor =
qwtMaxF( std::pow( logBase, minStep ), logBase );
1079 for (
int i = 0; i < majorTicks.count(); i++ )
1081 double tick = majorTicks[i];
1082 for (
int j = 0; j < numTicks; j++ )
1086 if ( j == mediumTickIndex )
1087 mediumTicks += tick;
1107 const QwtInterval& interval,
double stepSize )
const void buildMinorTicks(const QList< double > &majorTicks, int maxMinorSteps, double stepSize, QList< double > &minorTicks, QList< double > &mediumTicks) const
Calculate minor/medium ticks for major ticks.
static QwtInterval qwtLogInterval(double base, const QwtInterval &interval)
void setTransformation(QwtTransform *)
QwtLinearScaleEngine(uint base=10)
int qwtFuzzyCompare(double value1, double value2, double intervalSize)
Compare 2 values, relative to an interval.
double lowerMargin() const
QwtInterval symmetrize(double value) const
A class representing an interval.
QWT_CONSTEXPR float qwtMaxF(float a, float b)
void setMargins(double lower, double upper)
Specify margins at the scale's endpoints.
static double divideEps(double intervalSize, double numSteps)
Divide an interval into steps.
QwtInterval extend(double value) const
Extend the interval.
virtual QwtScaleDiv divideScale(double x1, double x2, int maxMajorSteps, int maxMinorSteps, double stepSize=0.0) const QWT_OVERRIDE
Calculate a scale division for an interval.
double upperMargin() const
QwtInterval align(const QwtInterval &, double stepSize) const
Align an interval to a step size.
bool testAttribute(Attribute) const
virtual void autoScale(int maxNumSteps, double &x1, double &x2, double &stepSize) const QWT_OVERRIDE
A class representing a scale division.
Attributes attributes() const
QWT_CONSTEXPR float qwtMinF(float a, float b)
static double divideInterval(double intervalSize, int numSteps, uint base)
virtual ~QwtLogScaleEngine()
Destructor.
double divideInterval(double intervalSize, int numSteps) const
QwtScaleEngine(uint base=10)
static double qwtLog(double base, double value)
QwtInterval align(const QwtInterval &, double stepSize) const
Align an interval to a step size.
void buildTicks(const QwtInterval &, double stepSize, int maxMinorSteps, QList< double > ticks[QwtScaleDiv::NTickTypes]) const
Calculate ticks for an interval.
void setInterval(double minValue, double maxValue, BorderFlags=IncludeBorders)
bool contains(const QwtInterval &, double value) const
virtual ~QwtLinearScaleEngine()
Destructor.
basic_reference< false > reference
QwtInterval buildInterval(double value) const
Build an interval around a value.
virtual void autoScale(int maxNumSteps, double &x1, double &x2, double &stepSize) const QWT_OVERRIDE
double width() const
Return the width of an interval.
Number of valid tick types.
QList< double > strip(const QList< double > &, const QwtInterval &) const
Build a scale which is symmetric to the reference() value.
static double floorEps(double value, double intervalSize)
void buildMinorTicks(const QList< double > &majorTicks, int maxMinorSteps, double stepSize, QList< double > &minorTicks, QList< double > &mediumTicks) const
Calculate minor/medium ticks for major ticks.
virtual ~QwtScaleEngine()
Destructor.
static double qwtStepSize(double intervalSize, int maxSteps, uint base)
Turn the scale upside down.
static QwtInterval qwtPowInterval(double base, const QwtInterval &interval)
void setReference(double)
Specify a reference point.
long double widthL() const
Return the width of an interval as long double.
static double ceilEps(double value, double intervalSize)
A scale engine for linear scales.
void buildTicks(const QwtInterval &, double stepSize, int maxMinorSteps, QList< double > ticks[QwtScaleDiv::NTickTypes]) const
Calculate ticks for an interval.
std::unordered_map< PlotAttribute, QVariant > Attributes
Build a scale which includes the reference() value.
QwtScaleEngine::Attributes attributes
QwtInterval limited(double lowerBound, double upperBound) const
QList< double > buildMajorTicks(const QwtInterval &interval, double stepSize) const
Calculate major ticks for an interval.
QwtLogScaleEngine(uint base=10)
void setAttributes(Attributes)
QwtInterval normalized() const
Normalize the limits of the interval.
void setAttribute(Attribute, bool on=true)
virtual QwtScaleDiv divideScale(double x1, double x2, int maxMajorSteps, int maxMinorSteps, double stepSize=0.0) const QWT_OVERRIDE
Calculate a scale division for an interval.
QwtTransform * transformation() const
Base class for scale engines.
QList< double > buildMajorTicks(const QwtInterval &interval, double stepSize) const
Calculate major ticks for an interval.