This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/geo/Length.h
kazu b503fb9bdc pushing before transfering ownership
added new tests and new helper classes
speed improvements
minor fixes
2016-01-25 17:54:58 +01:00

61 lines
1.1 KiB
C++

#ifndef LENGTH_H
#define LENGTH_H
/**
* unit independent length measurement
*/
template <typename T, int mul> struct Length {
private:
const T val;
/** delete empty ctor */
Length() = delete;
/** hidden value ctor */
Length(const T val) : val(val) {;}
public:
/** construct from mm */
static Length mm(const T mm) {return Length(mm * mul / 1000);}
/** construct from cm */
static Length cm(const T cm) {return Length(cm * mul / 100);}
/** construct from m */
static Length m(const T m) {return Length(m * mul / 1);}
public:
/** get in mm */
T mm() const {return val * 1000 / mul;}
/** get in cm */
T cm() const {return val * 100 / mul;}
/** get in m */
T m() const {return val * 1 / mul;}
public:
/** add the given length */
Length operator + (const Length o) {return Length(m+o.m);}
/** subtract the given length */
Length operator - (const Length o) {return Length(m+o.m);}
};
/** float. internally stored in meters */
typedef Length<float, 1> LengthF;
/** int. internally stored in millimeters */
typedef Length<int, 1000> LengthI;
#endif // LENGTH_H