QGIS API Documentation 4.3.0-Master (90cb4ecf9ef)
Loading...
Searching...
No Matches
QgsMathUtils Class Reference

Contains utility functions for mathematical operations. More...

#include <qgsmathutils.h>

Static Public Member Functions

static Q_INVOKABLE void doubleToRational (double value, qlonglong &numerator, qlonglong &denominator, double tolerance=1.0e-9, int maxIterations=100)
 Converts a double value to a rational fraction.
static QgsDoubleRange roundedRange (const QgsDoubleRange &range)
 Expands a range outward to round values, e.g.
static double roundingInterval (double span, int divisions=10)
 Returns a round interval, a power of ten, which splits the given span into at least divisions parts.

Detailed Description

Contains utility functions for mathematical operations.

Since
QGIS 4.0

Definition at line 30 of file qgsmathutils.h.

Member Function Documentation

◆ doubleToRational()

void QgsMathUtils::doubleToRational ( double value,
qlonglong & numerator,
qlonglong & denominator,
double tolerance = 1.0e-9,
int maxIterations = 100 )
static

Converts a double value to a rational fraction.

Parameters
valuevalue to convert
numeratorcalculated numerator
denominatorcalculated denominator
tolerancedesired precision. The returned fraction will be at within this tolerance of the original value.
maxIterationsmaximum number of iterations. Higher values result in better approximations, but at the cost of additional computation.

Definition at line 25 of file qgsmathutils.cpp.

◆ roundedRange()

QgsDoubleRange QgsMathUtils::roundedRange ( const QgsDoubleRange & range)
static

Expands a range outward to round values, e.g.

a range of 1234.5 - 3456.7 is expanded to 1200 - 3500.

The bounds are rounded to a tenth of the order of magnitude of the range's size, so that the returned range stays close to the original one.

Infinite and empty ranges are returned unchanged.

Since
QGIS 4.4

Definition at line 100 of file qgsmathutils.cpp.

◆ roundingInterval()

double QgsMathUtils::roundingInterval ( double span,
int divisions = 10 )
static

Returns a round interval, a power of ten, which splits the given span into at least divisions parts.

E.g. a span of 2222 returns 100 for 10 divisions and 10 for 100 divisions.

Returns 0 if span is not finite or is not greater than 0, or if divisions is lower than 1.

Since
QGIS 4.4

Definition at line 92 of file qgsmathutils.cpp.


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