38 #ifndef PLAYRHO_COMMON_UNITS_HPP
39 #define PLAYRHO_COMMON_UNITS_HPP
43 #include <type_traits>
47 #if defined(USE_BOOST_UNITS)
48 #include <boost/units/io.hpp>
49 #include <boost/units/limits.hpp>
50 #include <boost/units/cmath.hpp>
51 #include <boost/units/systems/si/length.hpp>
52 #include <boost/units/systems/si/time.hpp>
53 #include <boost/units/systems/si/velocity.hpp>
54 #include <boost/units/systems/si/acceleration.hpp>
55 #include <boost/units/systems/si/frequency.hpp>
56 #include <boost/units/systems/si/velocity.hpp>
57 #include <boost/units/systems/si/mass.hpp>
58 #include <boost/units/systems/si/momentum.hpp>
59 #include <boost/units/systems/si/inverse_mass.hpp>
60 #include <boost/units/systems/si/area.hpp>
61 #include <boost/units/systems/si/plane_angle.hpp>
62 #include <boost/units/systems/si/angular_momentum.hpp>
63 #include <boost/units/systems/si/angular_velocity.hpp>
64 #include <boost/units/systems/si/angular_acceleration.hpp>
65 #include <boost/units/systems/si/second_moment_of_area.hpp>
66 #include <boost/units/systems/si/surface_density.hpp>
67 #include <boost/units/systems/si/moment_of_inertia.hpp>
68 #include <boost/units/systems/si/inverse_moment_of_inertia.hpp>
69 #include <boost/units/systems/si/force.hpp>
70 #include <boost/units/systems/si/torque.hpp>
71 #include <boost/units/systems/angle/degrees.hpp>
72 #endif // defined(USE_BOOST_UNITS)
75 #if defined(USE_BOOST_UNITS)
76 #define PLAYRHO_QUANTITY(BoostDimension) boost::units::quantity<BoostDimension, Real>
77 #define PLAYRHO_UNIT(Quantity, BoostUnit) Quantity{BoostUnit * Real{1}}
78 #define PLAYRHO_DERIVED_UNIT(Quantity, BoostUnit, Ratio) Quantity{BoostUnit * Real{Ratio}}
79 #else // defined(USE_BOOST_UNITS)
80 #define PLAYRHO_QUANTITY(BoostDimension) Real
81 #define PLAYRHO_UNIT(Quantity, BoostUnit) Real{1}
82 #define PLAYRHO_DERIVED_UNIT(Quantity, BoostUnit, Ratio) Real{Ratio}}
83 #endif // defined(USE_BOOST_UNITS)
305 boost::units::si::meter_per_second);
310 boost::units::si::meter_per_second_squared);
328 boost::units::si::kilogram_per_square_meter);
349 boost::units::si::radian_per_second);
577 return static_cast<Real>(v) * 60 * 60 *
Second;
584 return static_cast<Real>(v) * 60 * 60 *
Second;
591 return static_cast<Real>(v) * 60 * 60 * 24 *
Second;
598 return static_cast<Real>(v) * 60 * 60 * 24 *
Second;
819 #if defined(USE_BOOST_UNITS)
834 hypot(
const boost::units::quantity<Unit,Real>& x,
const boost::units::quantity<Unit,Real>& y)
837 return boost::units::quantity<Unit,Real>::from_value(
hypot(x.value(), y.value()));
847 sqrt(
const boost::units::quantity<Unit,Real>& q)
850 using quantity_type =
typename boost::units::root_typeof_helper<
851 boost::units::quantity<Unit,Real>,
852 boost::units::static_rational<2>
854 using unit_type =
typename quantity_type::unit_type;
856 return boost::units::quantity<unit_type, Real>::from_value(
sqrt(q.value()));
861 inline auto AlmostZero(
const boost::units::quantity<Y, Real> v)
863 return abs(v) < std::numeric_limits<boost::units::quantity<Y, Real>>::min();
867 template<
class Unit,
class Y>
870 return source.value();
877 return GetInvalid<Real>() *
Radian;
884 return GetInvalid<Real>() *
Hertz;
898 return GetInvalid<Real>() *
Second;
905 return GetInvalid<Real>() *
Meter;
912 return GetInvalid<Real>() *
Kilogram;
919 return GetInvalid<Real>() /
Kilogram;
933 return GetInvalid<Real>() *
Newton;
972 #endif // defined(USE_BOOST_UNITS)
976 #if defined(USE_BOOST_UNITS)
997 template <
class Dimension,
typename X,
typename = std::enable_if_t<
1001 PLAYRHO_CONSTEXPR inline auto operator/ (quantity<Dimension, playrho::Real> lhs, X rhs)
1006 template <
class Dimension,
typename X,
typename = std::enable_if_t<
1010 PLAYRHO_CONSTEXPR inline auto operator/ (X lhs, quantity<Dimension, playrho::Real> rhs)
1023 template <
class Dimension,
typename X,
typename = std::enable_if_t<
1026 PLAYRHO_CONSTEXPR inline auto operator* (quantity<Dimension, playrho::Real> lhs, X rhs)
1039 template <
class Dimension,
typename X,
typename = std::enable_if_t<
1042 PLAYRHO_CONSTEXPR inline auto operator* (X lhs, quantity<Dimension, playrho::Real> rhs)
1049 #endif // defined(USE_BOOST_UNITS)
1051 #undef PLAYRHO_QUANTITY
1054 #endif // PLAYRHO_COMMON_UNITS_HPP