rock_widget_collection  0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
QCPRange Class Reference

Represents the range an axis is encompassing. More...

#include <qcustomplot.h>

Public Member Functions

 QCPRange ()
 
 QCPRange (double lower, double upper)
 
double size () const
 
double center () const
 
void normalize ()
 
QCPRange sanitizedForLogScale () const
 
QCPRange sanitizedForLinScale () const
 

Static Public Member Functions

static bool validRange (double lower, double upper)
 
static bool validRange (const QCPRange &range)
 

Public Attributes

double lower
 
double upper
 

Static Public Attributes

static const double minRange = 1e-280
 
static const double maxRange = 1e250
 

Detailed Description

Represents the range an axis is encompassing.

contains a lower and upper double value and provides convenience input, output and modification functions.

See also
QCPAxis::setRange

Definition at line 491 of file qcustomplot.h.

Constructor & Destructor Documentation

◆ QCPRange() [1/2]

QCPRange::QCPRange ( )

Constructs a range with lower and upper set to zero.

Definition at line 2331 of file qcustomplot.cc.

2331  :
2332  lower(0),
2333  upper(0)
2334 {
2335 }
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494

◆ QCPRange() [2/2]

QCPRange::QCPRange ( double  lower,
double  upper 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Constructs a range with the specified lower and upper values.

Definition at line 2340 of file qcustomplot.cc.

2341 {
2342  this->lower = lower;
2343  this->upper = upper;
2344 }
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494

Member Function Documentation

◆ center()

double QCPRange::center ( ) const

Returns the center of the range, i.e. (upper+lower)*0.5

Definition at line 2357 of file qcustomplot.cc.

2358 {
2359  return (upper+lower)*0.5;
2360 }
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494

◆ normalize()

void QCPRange::normalize ( )

Makes sure lower is numerically smaller than upper. If this is not the case, the values are swapped.

Definition at line 2366 of file qcustomplot.cc.

2367 {
2368  if (lower > upper)
2369  qSwap(lower, upper);
2370 }
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494

◆ sanitizedForLinScale()

QCPRange QCPRange::sanitizedForLinScale ( ) const

Returns a sanitized version of the range. Sanitized means for linear scales, that lower will always be numerically smaller (or equal) to upper.

Definition at line 2433 of file qcustomplot.cc.

2434 {
2435  QCPRange sanitizedRange(lower, upper);
2436  sanitizedRange.normalize();
2437  return sanitizedRange;
2438 }
double upper
Definition: qcustomplot.h:494
Represents the range an axis is encompassing.
Definition: qcustomplot.h:491
double lower
Definition: qcustomplot.h:494

◆ sanitizedForLogScale()

QCPRange QCPRange::sanitizedForLogScale ( ) const

Returns a sanitized version of the range. Sanitized means for logarithmic scales, that the range won't span the positive and negative sign domain, i.e. contain zero. Further lower will always be numerically smaller (or equal) to upper.

If the original range does span positive and negative sign domains or contains zero, the returned range will try to approximate the original range as good as possible. If the positive interval of the original range is wider than the negative interval, the returned range will only contain the positive interval, with lower bound set to rangeFac or rangeFac *upper, whichever is closer to zero. Same procedure is used if the negative interval is wider than the positive interval, this time by changing the upper bound.

Definition at line 2384 of file qcustomplot.cc.

2385 {
2386  double rangeFac = 1e-3;
2387  QCPRange sanitizedRange(lower, upper);
2388  sanitizedRange.normalize();
2389  // can't have range spanning negative and positive values in log plot, so change range to fix it
2390  //if (qFuzzyCompare(sanitizedRange.lower+1, 1) && !qFuzzyCompare(sanitizedRange.upper+1, 1))
2391  if (sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0)
2392  {
2393  // case lower is 0
2394  if (rangeFac < sanitizedRange.upper*rangeFac)
2395  sanitizedRange.lower = rangeFac;
2396  else
2397  sanitizedRange.lower = sanitizedRange.upper*rangeFac;
2398  } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1))
2399  else if (sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0)
2400  {
2401  // case upper is 0
2402  if (-rangeFac > sanitizedRange.lower*rangeFac)
2403  sanitizedRange.upper = -rangeFac;
2404  else
2405  sanitizedRange.upper = sanitizedRange.lower*rangeFac;
2406  } else if (sanitizedRange.lower < 0 && sanitizedRange.upper > 0)
2407  {
2408  // find out whether negative or positive interval is wider to decide which sign domain will be chosen
2409  if (-sanitizedRange.lower > sanitizedRange.upper)
2410  {
2411  // negative is wider, do same as in case upper is 0
2412  if (-rangeFac > sanitizedRange.lower*rangeFac)
2413  sanitizedRange.upper = -rangeFac;
2414  else
2415  sanitizedRange.upper = sanitizedRange.lower*rangeFac;
2416  } else
2417  {
2418  // positive is wider, do same as in case lower is 0
2419  if (rangeFac < sanitizedRange.upper*rangeFac)
2420  sanitizedRange.lower = rangeFac;
2421  else
2422  sanitizedRange.lower = sanitizedRange.upper*rangeFac;
2423  }
2424  }
2425  // due to normalization, case lower>0 && upper<0 should never occur, because that implies upper<lower
2426  return sanitizedRange;
2427 }
double upper
Definition: qcustomplot.h:494
Represents the range an axis is encompassing.
Definition: qcustomplot.h:491
double lower
Definition: qcustomplot.h:494

◆ size()

double QCPRange::size ( ) const

Returns the size of the range, i.e. upper-lower

Definition at line 2349 of file qcustomplot.cc.

2350 {
2351  return upper-lower;
2352 }
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494

◆ validRange() [1/2]

bool QCPRange::validRange ( double  lower,
double  upper 
)
static

Checks, whether the specified range is within valid bounds, which are defined as QCPRange::maxRange and QCPRange::minRange. A valid range means:

  • range bounds within -maxRange and maxRange
  • range size above minRange
  • range size below maxRange

Definition at line 2448 of file qcustomplot.cc.

2449 {
2450  /*
2451  return (lower > -maxRange &&
2452  upper < maxRange &&
2453  fabs(lower-upper) > minRange &&
2454  (lower < -minRange || lower > minRange) &&
2455  (upper < -minRange || upper > minRange));
2456  */
2457  return (lower > -maxRange &&
2458  upper < maxRange &&
2459  fabs(lower-upper) > minRange &&
2460  fabs(lower-upper) < maxRange);
2461 }
static const double maxRange
Definition: qcustomplot.h:509
static const double minRange
Definition: qcustomplot.h:508
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494

◆ validRange() [2/2]

bool QCPRange::validRange ( const QCPRange range)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Checks, whether the specified range is within valid bounds, which are defined as QCPRange::maxRange and QCPRange::minRange. A valid range means:

  • range bounds within -maxRange and maxRange
  • range size above minRange
  • range size below maxRange

Definition at line 2472 of file qcustomplot.cc.

2473 {
2474  /*
2475  return (range.lower > -maxRange &&
2476  range.upper < maxRange &&
2477  fabs(range.lower-range.upper) > minRange &&
2478  fabs(range.lower-range.upper) < maxRange &&
2479  (range.lower < -minRange || range.lower > minRange) &&
2480  (range.upper < -minRange || range.upper > minRange));
2481  */
2482  return (range.lower > -maxRange &&
2483  range.upper < maxRange &&
2484  fabs(range.lower-range.upper) > minRange &&
2485  fabs(range.lower-range.upper) < maxRange);
2486 }
static const double maxRange
Definition: qcustomplot.h:509
static const double minRange
Definition: qcustomplot.h:508
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494

Member Data Documentation

◆ lower

double QCPRange::lower

Definition at line 494 of file qcustomplot.h.

◆ maxRange

const double QCPRange::maxRange = 1e250
static

Maximum values (negative and positive) the range will accept in range-changing functions. Larger absolute values would cause errors due to the 11-bit exponent of double precision numbers, corresponding to a maximum magnitude of roughly 1e308. Since the number of planck-volumes in the entire visible universe is only ~1e183, this should be enough.

See also
validRange, minRange

Definition at line 509 of file qcustomplot.h.

◆ minRange

const double QCPRange::minRange = 1e-280
static

Minimum range size (upper - lower) the range changing functions will accept. Smaller intervals would cause errors due to the 11-bit exponent of double precision numbers, corresponding to a minimum magnitude of roughly 1e-308.

See also
validRange, maxRange

Definition at line 508 of file qcustomplot.h.

◆ upper

double QCPRange::upper

Definition at line 494 of file qcustomplot.h.


The documentation for this class was generated from the following files: