signaldrawer.cpp \
jsonserializable.cpp \
libHPCS/libhpcs.c \
- gui/failedfilesdialog.cpp
+ gui/failedfilesdialog.cpp \
+ helpers.cpp
HEADERS += \
datafilesloader.h \
--- /dev/null
+/*
+ Copyright (c) 2013 Michal Malý <madcatxster@prifuk.cz>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+
+#include "helpers.h"
+
+const double Helpers::EPSILON = 2e-14;
+
+double Helpers::firstTick(const double from, const double step)
+{
+ const double mod = fabs(fmod(from, step));
+ double ret;
+
+ if (fabs(mod - 0.0) < EPSILON)
+ ret = from;
+ else
+ ret = from + (step - fmod(from, step));
+
+ return ret;
+}
+
+QString Helpers::getFileNameSuffix(const QString& name)
+{
+ int dotIdx = name.lastIndexOf('.');
+
+ if (dotIdx < 0)
+ return "";
+
+ return name.mid(dotIdx+1).toLower();
+}
#ifndef HELPERS_H
#define HELPERS_H
+#include "logger.h"
#include <QtCore/QString>
-
class Helpers {
public:
- template <typename T> static T average(T* vals, size_t len) {
+ static const double EPSILON;
+
+ static double firstTick(const double from, const double step);
+ static QString getFileNameSuffix(const QString& name);
+
+ template <typename T> static T average(T* vals, size_t len)
+ {
T sum = 0;
for (size_t i = 0; i < len; i++)
sum += vals[i];
return sum / len;
}
- template <typename T> static T clamp(T in, T min, T max) {
+ template <typename T> static T clamp(T in, T min, T max)
+ {
if (in < min)
return min;
if (in > max)
return max;
}
- static QString getFileNameSuffix(const QString& name)
- {
- int dotIdx = name.lastIndexOf('.');
-
- if (dotIdx < 0)
- return "";
-
- return name.mid(dotIdx+1).toLower();
- }
-
template <typename T> static T maxof(T n, ...)
{
T idx;
}
};
+
#endif // HELPERS_H
THE SOFTWARE.
*/
+#include "helpers.h"
#include "signalcontroller.h"
#include "logger.h"
#include <cfloat>
//qDebug() << __QFUNC__ << "Step" << step << "RelStep" << relStep << "relDiff" << diffRel << fromAbs;
/* Calculate position of the first major tick */
- if (from == 0.0) {
- firstTickAbs = fromAbs;
- firstTickRel = from;
- } else {
- firstTickAbs = fromAbs + (step - fmod(fromAbs, step));
- firstTickRel = from + (relStep - fmod(from, relStep));
- }
+ firstTickAbs = Helpers::firstTick(fromAbs, step);
+ firstTickRel = Helpers::firstTick(from, relStep);
//qDebug() << __QFUNC__ << "First tick Abs:" << firstTickAbs << "Rel:" << firstTickRel;
return RulerDrawData(firstTickAbs, firstTickRel, step, relStep);
THE SOFTWARE.
*/
+#include "helpers.h"
#include "logger.h"
#include "signaldrawer.h"
#include <QFontMetrics>
const double relMin)
{
const double subRelStep = subStep(rd.relStep);
- const double subRelRem = fmod(relMin, subRelStep);
- const double subRelMin = relMin + (subRelStep - subRelRem);
+ const double subRelMin = Helpers::firstTick(relMin, subRelStep);
const double subAbsMin = (rd.firstTickRel - subRelMin) * (subStep(rd.step)) / subRelStep;
drawScaleBySubticks(rd, drawFunc, subRelMin, subAbsMin, rd.firstTickRel);