2018-01-20 23:51:39 +01:00
|
|
|
#ifndef LINEARUNITS_H
|
|
|
|
#define LINEARUNITS_H
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <QDebug>
|
2018-04-16 20:26:10 +02:00
|
|
|
#include "pointd.h"
|
2018-01-20 23:51:39 +01:00
|
|
|
|
|
|
|
class LinearUnits
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LinearUnits() : _f(NAN) {}
|
|
|
|
LinearUnits(int code);
|
|
|
|
|
2020-04-21 23:26:35 +02:00
|
|
|
bool operator==(const LinearUnits &other) const
|
|
|
|
{return (_f == other._f);}
|
|
|
|
|
2018-01-20 23:51:39 +01:00
|
|
|
bool isNull() const {return std::isnan(_f);}
|
|
|
|
bool isValid() const {return !std::isnan(_f);}
|
|
|
|
|
|
|
|
double toMeters(double val) const {return val * _f;}
|
2018-04-15 16:27:47 +02:00
|
|
|
PointD toMeters(const PointD &p) const
|
|
|
|
{return PointD(p.x() * _f, p.y() * _f);}
|
2018-01-20 23:51:39 +01:00
|
|
|
double fromMeters(double val) const {return val / _f;}
|
2018-04-15 16:27:47 +02:00
|
|
|
PointD fromMeters(const PointD &p) const
|
|
|
|
{return PointD(p.x() / _f, p.y() /_f);}
|
2018-01-20 23:51:39 +01:00
|
|
|
|
2018-02-13 23:03:18 +01:00
|
|
|
#ifndef QT_NO_DEBUG
|
2018-01-20 23:51:39 +01:00
|
|
|
friend QDebug operator<<(QDebug dbg, const LinearUnits &lu);
|
2018-02-13 23:03:18 +01:00
|
|
|
#endif // QT_NO_DEBUG
|
2018-01-20 23:51:39 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
double _f;
|
|
|
|
};
|
|
|
|
|
2018-02-13 23:03:18 +01:00
|
|
|
#ifndef QT_NO_DEBUG
|
2018-01-20 23:51:39 +01:00
|
|
|
QDebug operator<<(QDebug dbg, const LinearUnits &lu);
|
2018-02-13 23:03:18 +01:00
|
|
|
#endif // QT_NO_DEBUG
|
2018-01-20 23:51:39 +01:00
|
|
|
|
|
|
|
#endif // LINEARUNITS_H
|