fix: 💥 dim_torque now properly divides by an angle (instead of multiply) + default unit name change

Resolves #220
This commit is contained in:
Mateusz Pusz
2021-02-15 15:01:56 +01:00
parent efeacca9ee
commit 4d965d7f47
5 changed files with 15 additions and 9 deletions

View File

@@ -14,6 +14,7 @@
- perf: temporary string creation removed from `quantity::op<<()` - perf: temporary string creation removed from `quantity::op<<()`
- perf: limited the C++ Standard Library headers usage - perf: limited the C++ Standard Library headers usage
- (!) fix: `exp()` has sense only for dimensionless quantities - (!) fix: `exp()` has sense only for dimensionless quantities
- (!) fix: `dim_torque` now properly divides by an angle (instead of multiply) + default unit name change
- fix: `quantity_cast()` fixed to work correctly with representation types not convertible from `std::intmax_t` - fix: `quantity_cast()` fixed to work correctly with representation types not convertible from `std::intmax_t`
- fix: ambiguous case for empty type list resolved - fix: ambiguous case for empty type list resolved
- (!) build: The library should now be linked as `mp::units` in the CMake's `target_link_libraries()` - (!) build: The library should now be linked as `mp::units` in the CMake's `target_link_libraries()`

View File

@@ -33,10 +33,10 @@ using namespace units::physical::si::literals;
int main() int main()
{ {
auto torque = 20.0_q_Nm; auto torque = 20.0_q_Nm_per_rad;
auto energy = 20.0_q_J; auto energy = 20.0_q_J;
Angle auto angle = torque / energy; Angle auto angle = energy / torque;
std::cout << angle << '\n'; std::cout << angle << '\n';
} }

View File

@@ -28,8 +28,8 @@
namespace units::physical { namespace units::physical {
template<typename Child, Unit U, DimensionOfT<dim_energy> E, DimensionOfT<dim_angle> A> template<typename Child, Unit U, DimensionOfT<dim_force> F, DimensionOfT<dim_length> L, DimensionOfT<dim_angle> A>
struct dim_torque : derived_dimension<Child, U, exponent<E, 1>, exponent<A, 1>> {}; struct dim_torque : derived_dimension<Child, U, exponent<F, 1>, exponent<L, 1>, exponent<A, -1>> {};
template<typename T> template<typename T>
concept Torque = QuantityOfT<T, dim_torque>; concept Torque = QuantityOfT<T, dim_torque>;

View File

@@ -30,9 +30,9 @@
namespace units::physical::si { namespace units::physical::si {
struct newton_metre : named_unit<newton_metre, "Nm", prefix> {}; struct newton_metre_per_radian : unit<newton_metre_per_radian> {};
struct dim_torque : physical::dim_torque<dim_torque, newton_metre, dim_energy, dim_angle<>> {}; struct dim_torque : physical::dim_torque<dim_torque, newton_metre_per_radian, dim_force, dim_length, dim_angle<>> {};
template<UnitOf<dim_torque> U, QuantityValue Rep = double> template<UnitOf<dim_torque> U, QuantityValue Rep = double>
using torque = quantity<dim_torque, U, Rep>; using torque = quantity<dim_torque, U, Rep>;
@@ -40,14 +40,14 @@ using torque = quantity<dim_torque, U, Rep>;
inline namespace literals { inline namespace literals {
// Nm // Nm
constexpr auto operator"" _q_Nm(unsigned long long l) { return torque<newton_metre, std::int64_t>(l); } constexpr auto operator"" _q_Nm_per_rad(unsigned long long l) { return torque<newton_metre_per_radian, std::int64_t>(l); }
constexpr auto operator"" _q_Nm(long double l) { return torque<newton_metre, long double>(l); } constexpr auto operator"" _q_Nm_per_rad(long double l) { return torque<newton_metre_per_radian, long double>(l); }
} // namespace literals } // namespace literals
namespace unit_constants { namespace unit_constants {
inline constexpr auto Nm = torque<newton_metre, one_rep>{}; inline constexpr auto Nm_per_rad = torque<newton_metre_per_radian, one_rep>{};
} // namespace unit_constants } // namespace unit_constants

View File

@@ -305,6 +305,11 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
CHECK(fmt::format("{}", 1_q_J_per_mol) == "1 J/mol"); CHECK(fmt::format("{}", 1_q_J_per_mol) == "1 J/mol");
} }
SECTION("torque")
{
CHECK(fmt::format("{}", 1_q_Nm_per_rad) == "1 N ⋅ m/rad");
}
SECTION("incoherent units with powers") SECTION("incoherent units with powers")
{ {
CHECK(fmt::format("{}", 1_q_mi * 1_q_mi * 1_q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³"); CHECK(fmt::format("{}", 1_q_mi * 1_q_mi * 1_q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³");