pushing before transfering ownership
added new tests and new helper classes speed improvements minor fixes
This commit is contained in:
60
geo/Length.h
Normal file
60
geo/Length.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user