diff options
Diffstat (limited to 'src/bm/bmmisc.cpp')
-rw-r--r-- | src/bm/bmmisc.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/bm/bmmisc.cpp b/src/bm/bmmisc.cpp index 5ab7404..90d4062 100644 --- a/src/bm/bmmisc.cpp +++ b/src/bm/bmmisc.cpp @@ -162,6 +162,25 @@ bool BMMisc::getMultiOption( return true; } +// ### 2 B DOCUMENTED! +bool BMMisc::getMultiOption2( + const QStringList &args, const QString &option, QList<QStringList> *values, int n, + QString *error) +{ + for (int i = 0; ; ++i) { + QStringList values_; + if (getOption(args, option, &values_, n, i, error)) { + Q_ASSERT(values_.size() == n); + values->append(values_); + } else { + if (!error->isEmpty()) + return false; + break; + } + } + return true; +} + bool BMMisc::hasOption(const QStringList &args, const QString &option) { QStringList dummyValues; @@ -177,6 +196,18 @@ qreal BMMisc::median(const QList<qreal> &values) return sortedValues.at(sortedValues.size() / 2); } +// Computes the (zero-based) position of the median value of the numbers in \a values. +// If the median value occurs multiple times, the position of either the last or first +// duplicate is returned depending on whether \a lastDuplicate is true or false respectively. +int BMMisc::medianPos(const QList<qreal> &values, bool lastDuplicate) +{ + Q_ASSERT(!values.isEmpty()); + QList<qreal> sortedValues = values; + qSort(sortedValues); + const qreal medianValue = sortedValues.at(sortedValues.size() / 2); + return lastDuplicate ? values.lastIndexOf(medianValue) : values.indexOf(medianValue); +} + qreal BMMisc::v2y( const qreal v, const qreal ymax, const qreal vmin, const qreal yfact, const qreal ydefault) { |