NRE_Unit.hpp File Reference

Implementation of Math's API's unit system. More...

#include <iostream>
#include <ratio>
#include <Utility/String/NRE_String.hpp>
#include <Utility/Interfaces/Stringable/NRE_Stringable.hpp>
#include "NRE_Math.hpp"

Go to the source code of this file.

Classes

class  NRE::Math::Unit< M, L, T, A >
 Used to define clear physical unit. More...
 

Namespaces

 NRE
 The NearlyRealEngine's global namespace.
 
 Math
 Math's API.
 

Macros

#define TYPEDEF_UNIT(M, L, T, A, name)   typedef Unit<std::ratio<M>, std::ratio<L>, std::ratio<T>, std::ratio<A>> name
 

Functions

template<class M , class L , class T , class A >
std::ostream & NRE::Math::operator<< (std::ostream &stream, Unit< M, L, T, A > const &o)
 
template<class M , class L , class T , class A , class M2 , class L2 , class T2 , class A2 >
constexpr Unit< std::ratio_subtract< M, M2 >, std::ratio_subtract< L, L2 >, std::ratio_subtract< T, T2 >, std::ratio_subtract< A, A2 > > NRE::Math::operator/ (Unit< M, L, T, A > const &u1, Unit< M2, L2, T2, A2 > const &u2)
 
template<class M , class L , class T , class A >
constexpr Unit< std::ratio_subtract< std::ratio< 0 >, M >, std::ratio_subtract< std::ratio< 0 >, L >, std::ratio_subtract< std::ratio< 0 >, T >, std::ratio_subtract< std::ratio< 0 >, A > > NRE::Math::operator/ (long double x, Unit< M, L, T, A > const &u)
 
template<class M , class L , class T , class A >
constexpr Unit< M, L, T, A > NRE::Math::operator/ (Unit< M, L, T, A > const &u, long double x)
 
template<class M , class L , class T , class A , class M2 , class L2 , class T2 , class A2 >
constexpr Unit< std::ratio_add< M, M2 >, std::ratio_add< L, L2 >, std::ratio_add< T, T2 >, std::ratio_add< A, A2 > > NRE::Math::operator* (Unit< M, L, T, A > const &u1, Unit< M2, L2, T2, A2 > const &u2)
 
template<class M , class L , class T , class A >
constexpr Unit< M, L, T, A > NRE::Math::operator* (long double x, Unit< M, L, T, A > const &u)
 
template<class M , class L , class T , class A >
constexpr Unit< M, L, T, A > NRE::Math::operator* (Unit< M, L, T, A > const &u, long double x)
 
 NRE::Math::TYPEDEF_UNIT (1, 0, 0, 0, UMass)
 
 NRE::Math::TYPEDEF_UNIT (0, 1, 0, 0, ULength)
 
 NRE::Math::TYPEDEF_UNIT (0, 2, 0, 0, UArea)
 
 NRE::Math::TYPEDEF_UNIT (0, 3, 0, 0, UVolume)
 
 NRE::Math::TYPEDEF_UNIT (0, 0, 1, 0, UTime)
 
 NRE::Math::TYPEDEF_UNIT (0, 1,-1, 0, USpeed)
 
 NRE::Math::TYPEDEF_UNIT (0, 1,-2, 0, UAcceleration)
 
 NRE::Math::TYPEDEF_UNIT (0, 0,-1, 0, UFrequency)
 
 NRE::Math::TYPEDEF_UNIT (1, 1,-2, 0, UForce)
 
 NRE::Math::TYPEDEF_UNIT (1,-1,-2, 0, UPressure)
 
 NRE::Math::TYPEDEF_UNIT (0, 0, 0, 1, Angle)
 
constexpr UMass NRE::Math::kilogramme (1.0)
 
constexpr ULength NRE::Math::metre (1.0)
 
constexpr UTime NRE::Math::second (1.0)
 
constexpr UFrequency NRE::Math::Hz (1.0)
 
constexpr UForce NRE::Math::newton (1.0)
 
constexpr UPressure NRE::Math::pascal (1.0)
 
constexpr ULength NRE::Math::operator""_mm (long double x)
 
constexpr ULength NRE::Math::operator""_cm (long double x)
 
constexpr ULength NRE::Math::operator""_m (long double x)
 
constexpr ULength NRE::Math::operator""_km (long double x)
 
constexpr ULength NRE::Math::operator""_mm (unsigned long long int x)
 
constexpr ULength NRE::Math::operator""_cm (unsigned long long int x)
 
constexpr ULength NRE::Math::operator""_m (unsigned long long int x)
 
constexpr ULength NRE::Math::operator""_km (unsigned long long int x)
 
constexpr USpeed NRE::Math::operator""_kmph (long double x)
 
constexpr USpeed NRE::Math::operator""_kmph (unsigned long long int x)
 
constexpr UFrequency NRE::Math::operator""_Hz (long double x)
 
constexpr UFrequency NRE::Math::operator""_Hz (unsigned long long int x)
 
constexpr UTime NRE::Math::operator""_s (long double x)
 
constexpr UTime NRE::Math::operator""_min (long double x)
 
constexpr UTime NRE::Math::operator""_h (long double x)
 
constexpr UTime NRE::Math::operator""_day (long double x)
 
constexpr UTime NRE::Math::operator""_s (unsigned long long int x)
 
constexpr UTime NRE::Math::operator""_min (unsigned long long int x)
 
constexpr UTime NRE::Math::operator""_h (unsigned long long int x)
 
constexpr UTime NRE::Math::operator""_day (unsigned long long int x)
 
constexpr UMass NRE::Math::operator""_kg (long double x)
 
constexpr UMass NRE::Math::operator""_g (long double x)
 
constexpr UMass NRE::Math::operator""_t (long double x)
 
constexpr UMass NRE::Math::operator""_kg (unsigned long long int x)
 
constexpr UMass NRE::Math::operator""_g (unsigned long long int x)
 
constexpr UMass NRE::Math::operator""_t (unsigned long long int x)
 
constexpr UAcceleration NRE::Math::operator""_mps2 (long double x)
 
constexpr UAcceleration NRE::Math::operator""_mps2 (unsigned long long int x)
 
constexpr UAcceleration NRE::Math::operator""_G (long double x)
 
constexpr UAcceleration NRE::Math::operator""_G (unsigned long long int x)
 
constexpr UForce NRE::Math::operator""_N (long double x)
 
constexpr UForce NRE::Math::operator""_N (unsigned long long int x)
 
constexpr UPressure NRE::Math::operator""_Pa (long double x)
 
constexpr UPressure NRE::Math::operator""_Pa (unsigned long long int x)
 
constexpr long double NRE::Math::operator""_pi (long double x)
 
constexpr long double NRE::Math::operator""_pi (unsigned long long int x)
 
constexpr Angle NRE::Math::radian (1.0)
 
constexpr Angle NRE::Math::operator""_rad (long double x)
 
constexpr Angle NRE::Math::operator""_rad (unsigned long long int x)
 
constexpr Angle NRE::Math::operator""_deg (long double x)
 
constexpr Angle NRE::Math::operator""_deg (unsigned long long int x)
 
double NRE::Math::sin (Angle const &u)
 
double NRE::Math::cos (Angle const &u)
 
double NRE::Math::tan (Angle const &u)
 
double NRE::Math::asin (Angle const &u)
 
double NRE::Math::acos (Angle const &u)
 
double NRE::Math::atan (Angle const &u)
 
double NRE::Math::toRad (Angle const &u)
 
double NRE::Math::toDeg (Angle const &u)
 

Variables

constexpr UMass NRE::Math::gramme = 0.001 * kilogramme
 
constexpr UMass NRE::Math::tonne = 1000 * kilogramme
 
constexpr ULength NRE::Math::decimetre = metre / 10
 
constexpr ULength NRE::Math::centimetre = metre / 100
 
constexpr ULength NRE::Math::millimetre = metre / 1000
 
constexpr ULength NRE::Math::kilometre = 1000 * metre
 
constexpr UArea NRE::Math::metre2 = metre * metre
 
constexpr UArea NRE::Math::decimetre2 = decimetre * decimetre
 
constexpr UArea NRE::Math::centimetre2 = centimetre * centimetre
 
constexpr UArea NRE::Math::millimetre2 = millimetre * millimetre
 
constexpr UArea NRE::Math::kilometre2 = kilometre * kilometre
 
constexpr UVolume NRE::Math::metre3 = metre2 * metre
 
constexpr UVolume NRE::Math::decimetre3 = decimetre2 * decimetre
 
constexpr UVolume NRE::Math::centimetre3 = centimetre2 * centimetre
 
constexpr UVolume NRE::Math::millimetre3 = millimetre2 * millimetre
 
constexpr UVolume NRE::Math::kilometre3 = kilometre2 * kilometre
 
constexpr UVolume NRE::Math::litre = decimetre3
 
constexpr UTime NRE::Math::minute = 60 * second
 
constexpr UTime NRE::Math::hour = 60 * minute
 
constexpr UTime NRE::Math::day = 24 * hour
 
constexpr UAcceleration NRE::Math::G = 9.80665 * metre / (second * second)
 
constexpr Angle NRE::Math::degree = (PI / 180.0f) * radian
 

Detailed Description

Implementation of Math's API's unit system.

Author
Louis ABEL
Date
08/09/2018

Macro Definition Documentation

#define TYPEDEF_UNIT (   M,
  L,
  T,
  A,
  name 
)    typedef Unit<std::ratio<M>, std::ratio<L>, std::ratio<T>, std::ratio<A>> name

Mass unit

Function Documentation

double NRE::Math::acos ( Angle const &  u)
inline

Compute the arc cos of a unit in typed manners

Parameters
uthe unit
Returns
the resulting tan
double NRE::Math::asin ( Angle const &  u)
inline

Compute the arc sin of a unit in typed manners

Parameters
uthe unit
Returns
the resulting tan
double NRE::Math::atan ( Angle const &  u)
inline

Compute the arc tan of a unit in typed manners

Parameters
uthe unit
Returns
the resulting tan
double NRE::Math::cos ( Angle const &  u)
inline

Compute the cos of a unit in typed manners

Parameters
uthe unit
Returns
the resulting cos
constexpr UFrequency NRE::Math::Hz ( 1.  0)

Standard SI unit

constexpr UMass NRE::Math::kilogramme ( 1.  0)

Standard SI unit

constexpr ULength NRE::Math::metre ( 1.  0)

Standard SI unit

constexpr UForce NRE::Math::newton ( 1.  0)

Standard SI unit

constexpr ULength NRE::Math::operator""_cm ( long double  x)

Litteral operator for centimetre

Parameters
xthe value to convert
Returns
the corresponding length
constexpr ULength NRE::Math::operator""_cm ( unsigned long long int  x)

Litteral operator for centimetre

Parameters
xthe value to convert
Returns
the corresponding length
constexpr UTime NRE::Math::operator""_day ( long double  x)

Litteral operator for day

Parameters
xthe value to convert
Returns
the corresponding time
constexpr UTime NRE::Math::operator""_day ( unsigned long long int  x)

Litteral operator for day

Parameters
xthe value to convert
Returns
the corresponding time
constexpr Angle NRE::Math::operator""_deg ( long double  x)

Litteral operator for degree

Parameters
xthe value to convert
Returns
the corresponding angle
constexpr Angle NRE::Math::operator""_deg ( unsigned long long int  x)

Litteral operator for degree

Parameters
xthe value to convert
Returns
the corresponding angle
constexpr UMass NRE::Math::operator""_g ( long double  x)

Litteral operator for gramme

Parameters
xthe value to convert
Returns
the corresponding mass
constexpr UMass NRE::Math::operator""_g ( unsigned long long int  x)

Litteral operator for gramme

Parameters
xthe value to convert
Returns
the corresponding mass
constexpr UAcceleration NRE::Math::operator""_G ( long double  x)

Litteral operator for gravity

Parameters
xthe value to convert
Returns
the corresponding acceleration
constexpr UAcceleration NRE::Math::operator""_G ( unsigned long long int  x)

Litteral operator for gravity

Parameters
xthe value to convert
Returns
the corresponding acceleration
constexpr UTime NRE::Math::operator""_h ( long double  x)

Litteral operator for hour

Parameters
xthe value to convert
Returns
the corresponding time
constexpr UTime NRE::Math::operator""_h ( unsigned long long int  x)

Litteral operator for hour

Parameters
xthe value to convert
Returns
the corresponding time
constexpr UFrequency NRE::Math::operator""_Hz ( long double  x)

Litteral operator for hertz

Parameters
xthe value to convert
Returns
the corresponding frequency
constexpr UFrequency NRE::Math::operator""_Hz ( unsigned long long int  x)

Litteral operator for hertz

Parameters
xthe value to convert
Returns
the corresponding frequency
constexpr UMass NRE::Math::operator""_kg ( long double  x)

Litteral operator for kilogramme

Parameters
xthe value to convert
Returns
the corresponding mass
constexpr UMass NRE::Math::operator""_kg ( unsigned long long int  x)

Litteral operator for kilogramme

Parameters
xthe value to convert
Returns
the corresponding mass
constexpr ULength NRE::Math::operator""_km ( long double  x)

Litteral operator for kilometre

Parameters
xthe value to convert
Returns
the corresponding length
constexpr ULength NRE::Math::operator""_km ( unsigned long long int  x)

Litteral operator for kilometre

Parameters
xthe value to convert
Returns
the corresponding length
constexpr USpeed NRE::Math::operator""_kmph ( long double  x)

Litteral operator for kilometre per hour

Parameters
xthe value to convert
Returns
the corresponding speed
constexpr USpeed NRE::Math::operator""_kmph ( unsigned long long int  x)

Litteral operator for kilometre per hour

Parameters
xthe value to convert
Returns
the corresponding speed
constexpr ULength NRE::Math::operator""_m ( long double  x)

Litteral operator for metre

Parameters
xthe value to convert
Returns
the corresponding length
constexpr ULength NRE::Math::operator""_m ( unsigned long long int  x)

Litteral operator for metre

Parameters
xthe value to convert
Returns
the corresponding length
constexpr UTime NRE::Math::operator""_min ( long double  x)

Litteral operator for minute

Parameters
xthe value to convert
Returns
the corresponding time
constexpr UTime NRE::Math::operator""_min ( unsigned long long int  x)

Litteral operator for minute

Parameters
xthe value to convert
Returns
the corresponding time
constexpr ULength NRE::Math::operator""_mm ( long double  x)

Litteral operator for millimetre

Parameters
xthe value to convert
Returns
the corresponding length
constexpr ULength NRE::Math::operator""_mm ( unsigned long long int  x)

Litteral operator for millimetre

Parameters
xthe value to convert
Returns
the corresponding length
constexpr UAcceleration NRE::Math::operator""_mps2 ( long double  x)

Litteral operator for metre per second square

Parameters
xthe value to convert
Returns
the corresponding acceleration
constexpr UAcceleration NRE::Math::operator""_mps2 ( unsigned long long int  x)

Litteral operator for metre per second square

Parameters
xthe value to convert
Returns
the corresponding acceleration
constexpr UForce NRE::Math::operator""_N ( long double  x)

Litteral operator for newton

Parameters
xthe value to convert
Returns
the corresponding force
constexpr UForce NRE::Math::operator""_N ( unsigned long long int  x)

Litteral operator for newton

Parameters
xthe value to convert
Returns
the corresponding force
constexpr UPressure NRE::Math::operator""_Pa ( long double  x)

Litteral operator for pascal

Parameters
xthe value to convert
Returns
the corresponding pressure
constexpr UPressure NRE::Math::operator""_Pa ( unsigned long long int  x)

Litteral operator for pascal

Parameters
xthe value to convert
Returns
the corresponding pressure
constexpr long double NRE::Math::operator""_pi ( long double  x)

Litteral operator for pi

Parameters
xthe value to convert
Returns
the corresponding value
constexpr long double NRE::Math::operator""_pi ( unsigned long long int  x)

Litteral operator for pi

Parameters
xthe value to convert
Returns
the corresponding value
constexpr Angle NRE::Math::operator""_rad ( long double  x)

Litteral operator for radian

Parameters
xthe value to convert
Returns
the corresponding angle
constexpr Angle NRE::Math::operator""_rad ( unsigned long long int  x)

Litteral operator for radian

Parameters
xthe value to convert
Returns
the corresponding angle
constexpr UTime NRE::Math::operator""_s ( long double  x)

Litteral operator for second

Parameters
xthe value to convert
Returns
the corresponding time
constexpr UTime NRE::Math::operator""_s ( unsigned long long int  x)

Litteral operator for second

Parameters
xthe value to convert
Returns
the corresponding time
constexpr UMass NRE::Math::operator""_t ( long double  x)

Litteral operator for tonne

Parameters
xthe value to convert
Returns
the corresponding mass
constexpr UMass NRE::Math::operator""_t ( unsigned long long int  x)

Litteral operator for tonne

Parameters
xthe value to convert
Returns
the corresponding mass
template<class M , class L , class T , class A , class M2 , class L2 , class T2 , class A2 >
constexpr Unit<std::ratio_add<M, M2>, std::ratio_add<L, L2>, std::ratio_add<T, T2>, std::ratio_add<A, A2> > NRE::Math::operator* ( Unit< M, L, T, A > const &  u1,
Unit< M2, L2, T2, A2 > const &  u2 
)

Compute the unit resulting in the multiplication of u1 by u2

Parameters
u1the first unit
u2the second unit
Returns
the computed unit
template<class M , class L , class T , class A >
constexpr Unit<M, L, T, A> NRE::Math::operator* ( long double  x,
Unit< M, L, T, A > const &  u 
)

Compute the unit resulting in the multiplication of x by u

Parameters
xthe value to multiply with u
uthe unit
Returns
the computed unit
template<class M , class L , class T , class A >
constexpr Unit<M, L, T, A> NRE::Math::operator* ( Unit< M, L, T, A > const &  u,
long double  x 
)

Compute the unit resulting in the multiplication of u by x

Parameters
uthe unit
xthe value to multiply with u
Returns
the computed unitUsed to create a new standard unit
template<class M , class L , class T , class A , class M2 , class L2 , class T2 , class A2 >
constexpr Unit<std::ratio_subtract<M, M2>, std::ratio_subtract<L, L2>, std::ratio_subtract<T, T2>, std::ratio_subtract<A, A2> > NRE::Math::operator/ ( Unit< M, L, T, A > const &  u1,
Unit< M2, L2, T2, A2 > const &  u2 
)

Compute the unit resulting in the division of u1 by u2

Parameters
u1the first unit
u2the second unit
Returns
the computed unit
template<class M , class L , class T , class A >
constexpr Unit<std::ratio_subtract<std::ratio<0>, M>, std::ratio_subtract<std::ratio<0>, L>, std::ratio_subtract<std::ratio<0>, T>, std::ratio_subtract<std::ratio<0>, A> > NRE::Math::operator/ ( long double  x,
Unit< M, L, T, A > const &  u 
)

Compute the unit resulting in the division of x by u

Parameters
xthe value to divide with u
uthe unit
Returns
the computed unit
template<class M , class L , class T , class A >
constexpr Unit<M, L, T, A> NRE::Math::operator/ ( Unit< M, L, T, A > const &  u,
long double  x 
)

Compute the unit resulting in the division of u by x

Parameters
uthe unit to be divided
xthe value
Returns
the computed unit
template<class M , class L , class T , class A >
std::ostream& NRE::Math::operator<< ( std::ostream &  stream,
Unit< M, L, T, A > const &  o 
)

Output stream operator for the object

Parameters
streamthe stream to add the object's string representation
othe object to add in the stream
Returns
the modified stream
constexpr UPressure NRE::Math::pascal ( 1.  0)

Standard SI unit

constexpr Angle NRE::Math::radian ( 1.  0)

Standard SI unit

constexpr UTime NRE::Math::second ( 1.  0)

Standard SI unit

double NRE::Math::sin ( Angle const &  u)
inline

Compute the sin of a unit in typed manners

Parameters
uthe unit
Returns
the resulting sin
double NRE::Math::tan ( Angle const &  u)
inline

Compute the tan of a unit in typed manners

Parameters
uthe unit
Returns
the resulting tan
double NRE::Math::toDeg ( Angle const &  u)
inline

Return the angle value in degree

Parameters
uthe unit
Returns
the resulting angle
double NRE::Math::toRad ( Angle const &  u)
inline

Return the angle value in radian

Parameters
uthe unit
Returns
the resulting angle
NRE::Math::TYPEDEF_UNIT ( ,
,
,
,
UMass   
)

Length unit

NRE::Math::TYPEDEF_UNIT ( ,
,
,
,
ULength   
)

Area unit

NRE::Math::TYPEDEF_UNIT ( ,
,
,
,
UArea   
)

Volume unit

NRE::Math::TYPEDEF_UNIT ( ,
,
,
,
UVolume   
)

Time unit

NRE::Math::TYPEDEF_UNIT ( ,
,
,
,
UTime   
)

Speed unit

NRE::Math::TYPEDEF_UNIT ( ,
,
1,
,
USpeed   
)

Acceleration unit

NRE::Math::TYPEDEF_UNIT ( ,
,
2,
,
UAcceleration   
)

Frequency unit

NRE::Math::TYPEDEF_UNIT ( ,
,
1,
,
UFrequency   
)

Force unit

NRE::Math::TYPEDEF_UNIT ( ,
,
2,
,
UForce   
)

Pressure unit

NRE::Math::TYPEDEF_UNIT ( ,
1,
2,
,
UPressure   
)

Angle unit

Variable Documentation

constexpr ULength NRE::Math::centimetre = metre / 100

A hundredth of metre

constexpr UArea NRE::Math::centimetre2 = centimetre * centimetre

One by One centimetre square

constexpr UVolume NRE::Math::centimetre3 = centimetre2 * centimetre

One by One by One centimetre cube

constexpr UTime NRE::Math::day = 24 * hour

Twenty four hours

constexpr ULength NRE::Math::decimetre = metre / 10

A tenth of metre

constexpr UArea NRE::Math::decimetre2 = decimetre * decimetre

One by One decimetre square

constexpr UVolume NRE::Math::decimetre3 = decimetre2 * decimetre

One by One by One decimetre cube

constexpr Angle NRE::Math::degree = (PI / 180.0f) * radian

Scale degree with radian

constexpr UAcceleration NRE::Math::G = 9.80665 * metre / (second * second)

Standard Gravity value

constexpr UMass NRE::Math::gramme = 0.001 * kilogramme

A thousandth of kilogramme

constexpr UTime NRE::Math::hour = 60 * minute

Sixty minutes

constexpr ULength NRE::Math::kilometre = 1000 * metre

One thousand of metre

constexpr UArea NRE::Math::kilometre2 = kilometre * kilometre

One by One kilometre square

constexpr UVolume NRE::Math::kilometre3 = kilometre2 * kilometre

One by One by One kilometre cube

constexpr UVolume NRE::Math::litre = decimetre3

One by One by One decimetre cube

constexpr UArea NRE::Math::metre2 = metre * metre

One by One metre square

constexpr UVolume NRE::Math::metre3 = metre2 * metre

One by One by One metre cube

constexpr ULength NRE::Math::millimetre = metre / 1000

A thousandth of metre

constexpr UArea NRE::Math::millimetre2 = millimetre * millimetre

One by One millimetre square

constexpr UVolume NRE::Math::millimetre3 = millimetre2 * millimetre

One by One by One millimetre cube

constexpr UTime NRE::Math::minute = 60 * second

Sixty seconds

constexpr UMass NRE::Math::tonne = 1000 * kilogramme

One thousand of kilogramme