mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-31 19:04:27 +02:00
Added the "named_deduced_unit" type and more units to the fps system
The named_deduced_unit type can be used as a named type for child for child deduced units
This commit is contained in:
@@ -38,7 +38,7 @@ using area = quantity<dim_area, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// fm2
|
||||
// ft2
|
||||
constexpr auto operator"" q_ft2(unsigned long long l) { return area<square_foot, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_ft2(long double l) { return area<square_foot, long double>(l); }
|
||||
|
||||
|
46
src/include/units/physical/fps/density.h
Normal file
46
src/include/units/physical/fps/density.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2018 Mateusz Pusz
|
||||
//
|
||||
// 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
|
||||
|
||||
#include <units/physical/dimensions.h>
|
||||
#include <units/physical/fps/mass.h>
|
||||
#include <units/physical/fps/length.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::physical::fps {
|
||||
|
||||
struct pound_per_foot_cub : unit<pound_per_foot_cub> {};
|
||||
|
||||
struct dim_density : physical::dim_density<dim_density, pound_per_foot_cub, dim_mass, dim_length> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using density = quantity<dim_density, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
constexpr auto operator"" q_lb_per_ft3(unsigned long long l) { return density<pound_per_foot_cub, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_lb_per_ft3(long double l) { return density<pound_per_foot_cub, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::physical::fps
|
@@ -32,14 +32,17 @@ namespace units::physical::fps {
|
||||
// https://en.wikipedia.org/wiki/Foot-poundal
|
||||
struct foot_poundal : unit<foot_poundal> {};
|
||||
|
||||
// https://en.wikipedia.org/wiki/Foot-pound_(energy)
|
||||
struct foot_pound_force : named_scaled_unit<foot_poundal, "lbf", no_prefix, ratio<32'174'049, 1'000'000>, foot_poundal> {};
|
||||
|
||||
struct dim_energy : physical::dim_energy<dim_energy, foot_poundal, dim_force, dim_length> {};
|
||||
|
||||
// https://en.wikipedia.org/wiki/Foot-pound_(energy)
|
||||
struct foot_pound_force : named_deduced_unit<foot_pound_force, dim_energy, pound_force, foot> {};
|
||||
|
||||
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using energy = quantity<dim_energy, U, Rep>;
|
||||
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
constexpr auto operator"" q_ft_pdl(unsigned long long l) { return energy<foot_poundal, std::int64_t>(l); }
|
||||
|
@@ -34,7 +34,7 @@ namespace units::physical::fps {
|
||||
struct poundal : named_unit<poundal, "pdl", no_prefix> {};
|
||||
|
||||
// https://en.wikipedia.org/wiki/Pound_(force)
|
||||
struct pound_force : named_scaled_unit<pound_force, "ftlbf", no_prefix, ratio<32'174'049, 1'000'000>, poundal> {};
|
||||
struct pound_force : named_scaled_unit<pound_force, "lbf", no_prefix, ratio<32'174'049, 1'000'000>, poundal> {};
|
||||
|
||||
|
||||
|
||||
|
@@ -31,11 +31,10 @@ namespace units::physical::fps {
|
||||
|
||||
struct foot_poundal_per_second : unit<foot_poundal_per_second> {};
|
||||
|
||||
struct foot_pound_force_per_second : scaled_unit<ratio<32'174'049, 1'000'000>, foot_poundal_per_second> {};
|
||||
|
||||
|
||||
struct dim_power : physical::dim_power<dim_power, foot_poundal_per_second, dim_energy, dim_time> {};
|
||||
|
||||
struct foot_pound_force_per_second : deduced_unit<foot_pound_force_per_second, dim_power, foot_pound_force, second> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using power = quantity<dim_power, U, Rep>;
|
||||
|
||||
|
51
src/include/units/physical/fps/volume.h
Normal file
51
src/include/units/physical/fps/volume.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2018 Mateusz Pusz
|
||||
//
|
||||
// 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
|
||||
|
||||
#include <units/physical/dimensions.h>
|
||||
#include <units/physical/fps/length.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::physical::fps {
|
||||
|
||||
struct cubic_foot : unit<cubic_foot> {};
|
||||
struct dim_volume : physical::dim_volume<dim_volume, cubic_foot, dim_length> {};
|
||||
|
||||
struct cubic_yard : deduced_unit<cubic_yard, dim_volume, yard> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using volume = quantity<dim_volume, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// ft3
|
||||
constexpr auto operator"" q_ft3(unsigned long long l) { return volume<cubic_foot, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_ft3(long double l) { return volume<cubic_foot, long double>(l); }
|
||||
|
||||
// yard3
|
||||
constexpr auto operator"" q_yd3(unsigned long long l) { return volume<cubic_yard, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_yd3(long double l) { return volume<cubic_yard, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::physical::fps
|
@@ -165,6 +165,29 @@ struct deduced_unit : downcast_child<Child, detail::deduced_unit<Dim, U, URest..
|
||||
using prefix_family = no_prefix;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief A unit with a deduced ratio and symbol that can be used as a named unit for children
|
||||
*
|
||||
* Defines a new unit with a deduced ratio and symbol based on the recipe from the provided
|
||||
* derived dimension. The number and order of provided units should match the recipe of the
|
||||
* derived dimension. All of the units provided should also be a named ones so it is possible
|
||||
* to create a deduced symbol text.
|
||||
*
|
||||
* @tparam Child inherited class type used by the downcasting facility (CRTP Idiom)
|
||||
* @tparam Dim a derived dimension recipe to use for deduction
|
||||
* @tparam U the unit of the first composite dimension from provided derived dimension's recipe
|
||||
* @tparam URest the units for the rest of dimensions from the recipe
|
||||
*/
|
||||
template<typename Child, DerivedDimension Dim, Unit U, Unit... URest>
|
||||
requires detail::same_scaled_units<typename Dim::recipe, U, URest...> &&
|
||||
(U::is_named && (URest::is_named && ... && true))
|
||||
struct named_deduced_unit : downcast_child<Child, detail::deduced_unit<Dim, U, URest...>> {
|
||||
static constexpr bool is_named = true;
|
||||
static constexpr auto symbol = detail::deduced_symbol_text<Dim, U, URest...>();
|
||||
using prefix_family = no_prefix;
|
||||
};
|
||||
|
||||
// template<typename Child, Dimension Dim, basic_fixed_string Symbol, PrefixFamily PF, Unit U, Unit... Us>
|
||||
// struct named_deduced_derived_unit : downcast_child<Child, detail::deduced_derived_unit<Dim, U, Us...>> {
|
||||
// static constexpr bool is_named = true;
|
||||
|
Reference in New Issue
Block a user