xo-unit: add imperial distance units inch/foot/yard/mile

This commit is contained in:
Roland Conybeare 2024-05-07 10:31:51 -04:00
commit 166276c710
3 changed files with 32 additions and 0 deletions

View file

@ -91,6 +91,15 @@ namespace xo {
constexpr basis_unit megameter = megametre;
constexpr basis_unit gigameter = gigametre;
/** @brief basis-unit representing 1 inch; defined as exactly 1/12 feet **/
constexpr basis_unit inch = basis_unit(dim::distance, scalefactor_ratio_type( 3048, 120000));
/** @brief basis-unit representing 1 foot; defined as exactly 0.3048 meters **/
constexpr basis_unit foot = basis_unit(dim::distance, scalefactor_ratio_type( 3048, 10000));
/** @brief basis-unit representing 1 yard; defined as exactly 3 feet **/
constexpr basis_unit yard = basis_unit(dim::distance, scalefactor_ratio_type( 3*3048, 10000));
/** @brief basis-unit representing 1 mile; defined as exactly 1760 yards = 5280 feet **/
constexpr basis_unit mile = basis_unit(dim::distance, scalefactor_ratio_type( 5280*3048, 10000));
// ----- time -----
constexpr basis_unit picosecond = basis_unit(dim::time, scalefactor_ratio_type( 1, 1000000000000));

View file

@ -369,6 +369,8 @@ namespace xo {
namespace nu {
constexpr auto dimensionless = natural_unit<std::int64_t>();
// ----- mass -----
constexpr auto picogram = natural_unit<std::int64_t>::from_bu(bu::picogram);
constexpr auto nanogram = natural_unit<std::int64_t>::from_bu(bu::nanogram);
constexpr auto microgram = natural_unit<std::int64_t>::from_bu(bu::microgram);
@ -380,6 +382,8 @@ namespace xo {
constexpr auto megatonne = natural_unit<std::int64_t>::from_bu(bu::megatonne);
constexpr auto gigatonne = natural_unit<std::int64_t>::from_bu(bu::gigatonne);
// ----- distance -----
constexpr auto picometer = natural_unit<std::int64_t>::from_bu(bu::picometer);
constexpr auto nanometer = natural_unit<std::int64_t>::from_bu(bu::nanometer);
constexpr auto micrometer = natural_unit<std::int64_t>::from_bu(bu::micrometer);
@ -391,6 +395,13 @@ namespace xo {
constexpr auto lightsecond = natural_unit<std::int64_t>::from_bu(bu::lightsecond);
constexpr auto astronomicalunit = natural_unit<std::int64_t>::from_bu(bu::astronomicalunit);
constexpr auto inch = natural_unit<std::int64_t>::from_bu(bu::inch);
constexpr auto foot = natural_unit<std::int64_t>::from_bu(bu::foot);
constexpr auto yard = natural_unit<std::int64_t>::from_bu(bu::yard);
constexpr auto mile = natural_unit<std::int64_t>::from_bu(bu::mile);
// ----- time -----
constexpr auto picosecond = natural_unit<std::int64_t>::from_bu(bu::picosecond);
constexpr auto nanosecond = natural_unit<std::int64_t>::from_bu(bu::nanosecond);
constexpr auto microsecond = natural_unit<std::int64_t>::from_bu(bu::microsecond);

View file

@ -425,6 +425,18 @@ namespace xo {
template <typename Repr>
inline constexpr auto astronomicalunits(Repr x) { return quantity<nu::astronomicalunit, Repr>(x); }
/** @brief create quantity representing @p x inches of distance, with compile-time unit representation **/
template <typename Repr>
inline constexpr auto inches(Repr x) { return quantity<nu::inch, Repr>(x); }
/** @brief create quantity representing @p x feet of distance, with compile-time unit representation **/
template <typename Repr>
inline constexpr auto feet(Repr x) { return quantity<nu::foot, Repr>(x); }
/** @brief create quantity representing @p x yards of distance, with compile-time unit representation **/
template <typename Repr>
inline constexpr auto yards(Repr x) { return quantity<nu::yard, Repr>(x); }
/** @brief create quantity representing @p x statute miles of distance, with compile-time unit representation **/
template <typename Repr>
inline constexpr auto miles(Repr x) { return quantity<nu::mile, Repr>(x); }
static constexpr auto meter = meters(1);
// ----- time -----