Skip to content

Commit

Permalink
Merge pull request #460 from tobylorenz/master
Browse files Browse the repository at this point in the history
Add "inch of mercury" pressure unit as US Custom Unit
  • Loading branch information
mpusz authored May 25, 2023
2 parents fc30bb3 + 537aca2 commit 59a1269
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/reference/systems/isq/si/uscs/pressure.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Pressure
========

.. doxygenfile:: si/uscs/pressure.h
1 change: 1 addition & 0 deletions docs/reference/systems/isq/si_uscs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ U.S. Customary Units (based on SI)
:maxdepth: 2

si/uscs/length
si/uscs/pressure
3 changes: 2 additions & 1 deletion src/systems/si-uscs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
cmake_minimum_required(VERSION 3.19)

add_units_module(
si-uscs DEPENDENCIES mp-units::si HEADERS include/units/isq/si/uscs/length.h include/units/isq/si/uscs/uscs.h
si-uscs DEPENDENCIES mp-units::si HEADERS include/units/isq/si/uscs/length.h include/units/isq/si/uscs/pressure.h
include/units/isq/si/uscs/uscs.h
)
88 changes: 88 additions & 0 deletions src/systems/si-uscs/include/units/isq/si/uscs/pressure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
// Copyright (c) 2023 Tobias Lorenz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once

// IWYU pragma: begin_exports
#include <units/isq/dimensions/pressure.h>
#include <units/quantity.h>
#include <units/reference.h>
#include <units/symbol_text.h>
// IWYU pragma: end_exports

#include <units/isq/si/pressure.h>
#include <units/unit.h>

namespace units::isq::si::uscs {

// https://en.wikipedia.org/wiki/Inch_of_mercury
// https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors/nist-guide-si-appendix-b8
struct inch_of_mercury : named_scaled_unit<inch_of_mercury, "inHg", mag<ratio(3'386'389, 1'000)>(), si::pascal> {};

#ifndef UNITS_NO_LITERALS

inline namespace literals {

// inHg
constexpr auto operator"" _q_inHg(unsigned long long l)
{
gsl_ExpectsAudit(std::in_range<std::int64_t>(l));
return si::pressure<units::isq::si::uscs::inch_of_mercury, std::int64_t>(static_cast<std::int64_t>(l));
}
constexpr auto operator"" _q_inHg(long double l)
{
return si::pressure<units::isq::si::uscs::inch_of_mercury, long double>(l);
}

} // namespace literals

#endif // UNITS_NO_LITERALS

#ifndef UNITS_NO_REFERENCES

namespace pressure_references {

inline constexpr auto inHg = reference<si::dim_pressure, uscs::inch_of_mercury>{};

} // namespace pressure_references

namespace references {

using namespace pressure_references;

} // namespace references

#endif // UNITS_NO_REFERENCES

} // namespace units::isq::si::uscs

#ifndef UNITS_NO_ALIASES

namespace units::aliases::isq::si::uscs::inline pressure {

template<Representation Rep = double>
using inHg = units::isq::si::pressure<units::isq::si::uscs::inch_of_mercury, Rep>;

} // namespace units::aliases::isq::si::uscs::inline pressure

#endif // UNITS_NO_ALIASES
1 change: 1 addition & 0 deletions src/systems/si-uscs/include/units/isq/si/uscs/uscs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@

// IWYU pragma: begin_exports
#include <units/isq/si/uscs/length.h>
#include <units/isq/si/uscs/pressure.h>
// IWYU pragma: end_exports
11 changes: 11 additions & 0 deletions test/unit_test/static/us_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@
#include <units/isq/si/international/length.h>
#include <units/isq/si/international/speed.h>
#include <units/isq/si/length.h>
#include <units/isq/si/pressure.h>
#include <units/isq/si/time.h>
#include <units/isq/si/uscs/pressure.h>
#include <units/unit.h>

namespace {

using namespace units;
using namespace units::isq::si;
using namespace units::isq::si::international;
using namespace units::isq::si::uscs;

/* ************** BASE DIMENSIONS **************** */

Expand All @@ -52,4 +55,12 @@ static_assert(10.0_q_mi / 2_q_h == 5_q_mi_per_h);

static_assert(mile_per_hour::symbol == "mi/h");


/* ************** US CUSTOMARY UNITS **************** */

// pressure

// 29.9213 inHg = 1013.25 hPa
static_assert(1_q_inHg == 3386.389_q_Pa);

} // namespace

0 comments on commit 59a1269

Please sign in to comment.