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);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
friend bool operator==(const LinearUnits &lu1, const LinearUnits &lu2);
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator==(const LinearUnits &lu1, const LinearUnits &lu2)
|
|
|
|
{return (lu1._f == lu2._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
|