Velocity renamed to Speed (resolves #103)

This commit is contained in:
Mateusz Pusz
2020-05-10 17:31:47 +02:00
parent f70d6d0be1
commit ce301748dd
42 changed files with 151 additions and 150 deletions

View File

@@ -50,13 +50,13 @@ and dimensional analysis can be performed without sacrificing on accuracy. Pleas
the below example for a quick preview of basic library features:
```cpp
#include <units/physical/si/velocity.h>
#include <units/physical/international/velocity.h>
#include <units/physical/si/speed.h>
#include <units/physical/international/speed.h>
#include <iostream>
using namespace units::physical;
constexpr Velocity auto avg_speed(Length auto d, Time auto t)
constexpr Speed auto avg_speed(Length auto d, Time auto t)
{
return d / t;
}
@@ -64,10 +64,10 @@ constexpr Velocity auto avg_speed(Length auto d, Time auto t)
int main()
{
using namespace units::physical::si::literals;
Velocity auto v1 = avg_speed(220q_km, 2q_h);
Velocity auto v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
Velocity auto v3 = quantity_cast<si::metre_per_second>(v2);
Velocity auto v4 = quantity_cast<int>(v3);
Speed auto v1 = avg_speed(220q_km, 2q_h);
Speed auto v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
Speed auto v3 = quantity_cast<si::metre_per_second>(v2);
Speed auto v4 = quantity_cast<int>(v3);
std::cout << v1 << '\n'; // 110 km/h
std::cout << v2 << '\n'; // 70 mi/h

View File

@@ -25,6 +25,8 @@
- Added a lot of prefixes to named units and introduced `alias_unit` (thanks [@yasamoka](https://github.com/yasamoka))
- Linking with Conan targets only when they exists ([#98](https://github.com/mpusz/units/issues/98))
- All physical dimensions and units put into `physical` namespace
- CMake improvements
- Velocity renamed to speed
- ...
Many thanks to GitHub users [@oschonrock](https://github.com/oschonrock) and

View File

@@ -164,7 +164,7 @@ struct kilometre : prefixed_unit<kilometre, kilo, metre> {};
struct second : named_unit<second, "s", prefix> {};
struct hour : named_scaled_unit<hour, "h", no_prefix, ratio<3600>, second> {};
// velocity
// speed
struct metre_per_second : unit<metre_per_second> {};
struct kilometre_per_hour : deduced_unit<kilometre_per_hour, dim_velocity, kilometre, hour> {};
@@ -176,7 +176,7 @@ namespace units::physical::us {
struct yard : named_scaled_unit<yard, "yd", no_prefix, ratio<9'144, 10'000>, si::metre> {};
struct mile : named_scaled_unit<mile, "mi", no_prefix, ratio<1'760>, yard> {};
// velocity
// speed
struct mile_per_hour : deduced_unit<mile_per_hour, si::dim_velocity, mile, si::hour> {};
}
@@ -285,7 +285,7 @@ struct derived_dimension_base;
}
```
A derived dimension can be formed from multiple exponents (i.e. velocity is represented as
A derived dimension can be formed from multiple exponents (i.e. speed is represented as
`exp<L, 1>, exp<T, -1>`). It is also possible to form a derived dimension with only one exponent
(i.e. frequency is represented as just `exp<T, -1>`).
@@ -734,11 +734,11 @@ temporary results of calculations:
```cpp
units::Length auto d1 = 123q_m;
units::Time auto t1 = 10q_s;
units::Velocity auto v1 = avg_speed(d1, t1);
units::Speed auto v1 = avg_speed(d1, t1);
auto temp1 = v1 * 50q_m; // intermediate unknown dimension
units::Velocity auto v2 = temp1 / 100q_m; // back to known dimensions again
units::Speed auto v2 = temp1 / 100q_m; // back to known dimensions again
units::Length auto d2 = v2 * 60q_s;
```

View File

@@ -19,7 +19,7 @@ For example the speed of light constant in :term:`SI` is defined as::
namespace si::si2019 {
template<Scalar Rep = double>
inline constexpr auto speed_of_light = velocity<metre_per_second, Rep>(299792458);
inline constexpr auto speed_of_light = speed<metre_per_second, Rep>(299792458);
}
@@ -28,6 +28,6 @@ The same constant defined for natural units may be provided as::
namespace natural {
template<Scalar Rep = double>
inline constexpr auto speed_of_light = velocity<unitless, Rep>(1);
inline constexpr auto speed_of_light = speed<unitless, Rep>(1);
}

View File

@@ -5,7 +5,7 @@ Dimensions
In the previous chapter we briefly introduced the notion of a physical
:term:`dimension`. Now it is time to learn much more about this subject.
Length, time, velocity, area, energy are only a few examples of physical
Length, time, speed, area, energy are only a few examples of physical
dimensions.
Operations
@@ -45,7 +45,7 @@ probably will always end up in a quantity of a yet another dimension:
Length auto dist2 = 3q_m;
Time auto dur1 = 2q_s;
Area auto res1 = dist1 * dist2; // 6 m²
Velocity auto res2 = dist1 / dur1; // 1 m/s
Speed auto res2 = dist1 / dur1; // 1 m/s
Frequency auto res3 = 10 / dur1; // 5 Hz
However, please note that there is an exception from the above rule.
@@ -96,12 +96,12 @@ The quantities of derived dimensions are called
quantities. This means that they are created by multiplying or dividing
quantities of other dimensions.
Looking at the previous code snippets the area, velocity, or frequency are
Looking at the previous code snippets the area, speed, or frequency are
the examples of such quantities. Each derived quantity can be represented
as a unique list of exponents of base quantities. For example:
- an area is a length base quantity raised to the exponent ``2``
- a velocity is formed from the length base quantity with exponent ``1``
- a speed is formed from the length base quantity with exponent ``1``
and time base quantity with exponent ``-1``.
The above dimensions can be defined in the library with the

View File

@@ -82,14 +82,14 @@ quantities. The usage of such a function can look as follows::
using namespace units::physical::si::literals;
using namespace units::physical::international::literals;
constexpr Velocity auto v1 = avg_speed(220q_km, 2q_h);
constexpr Velocity auto v2 = avg_speed(140q_mi, 2q_h);
constexpr Speed auto v1 = avg_speed(220q_km, 2q_h);
constexpr Speed auto v2 = avg_speed(140q_mi, 2q_h);
In this and all other physical units libraries such a function can be
implemented as::
constexpr si::velocity<si::metre_per_second> avg_speed(si::length<si::metre> d,
si::time<si::second> t)
constexpr si::speed<si::metre_per_second> avg_speed(si::length<si::metre> d,
si::time<si::second> t)
{
return d / t;
}
@@ -114,7 +114,7 @@ are returning a physical quantity of a correct dimension. For this
dimension-specific concepts come handy again and with usage of C++20 generic
functions our function can look as simple as::
constexpr Velocity auto avg_speed(Length auto d, Time auto t)
constexpr Speed auto avg_speed(Length auto d, Time auto t)
{
return d / t;
}
@@ -141,7 +141,7 @@ but often we would like to know a specific type too. We have two options here:
- query the actual dimension, unit, and representation types::
constexpr Velocity auto v = avg_speed(220q_km, 2q_h);
constexpr Speed auto v = avg_speed(220q_km, 2q_h);
using quantity_type = decltype(v);
using dimension_type = quantity_type::dimension;
using unit_type = quantity_type::unit;
@@ -149,9 +149,9 @@ but often we would like to know a specific type too. We have two options here:
- convert or cast to a desired quantity type::
constexpr Velocity auto v1 = avg_speed(220.q_km, 2q_h);
constexpr si::velocity<si::metre_per_second> v2 = v1;
constexpr Velocity auto v3 = quantity_cast<si::velocity<si::metre_per_second>(v1);
constexpr Speed auto v1 = avg_speed(220.q_km, 2q_h);
constexpr si::speed<si::metre_per_second> v2 = v1;
constexpr Speed auto v3 = quantity_cast<si::speed<si::metre_per_second>(v1);
.. seealso::

View File

@@ -14,8 +14,8 @@ stream::
using namespace units::physical::si::literals;
using namespace units::physical::international::literals;
constexpr Velocity auto v1 = avg_speed(220.q_km, 2q_h);
constexpr Velocity auto v2 = avg_speed(140.q_mi, 2q_h);
constexpr Speed auto v1 = avg_speed(220.q_km, 2q_h);
constexpr Speed auto v2 = avg_speed(140.q_mi, 2q_h);
std::cout << v1 << '\n'; // 110 km/h
std::cout << v2 << '\n'; // 70 mi/h

View File

@@ -137,7 +137,7 @@ where ``kilogram_metre_per_second`` is defined as::
struct kilogram_metre_per_second : unit<kilogram_metre_per_second> {};
However, the easiest way to define momentum is just to use the
`si::velocity` derived dimension in the recipe:
`si::speed` derived dimension in the recipe:
.. code-block::
:emphasize-lines: 3

View File

@@ -136,7 +136,7 @@ ISO 80000 [1]_ definitions
- A power of a `base unit` is the `base unit` raised to an exponent.
- Coherence can be determined only with respect to a particular `system of quantities`
and a given set of `base units <base unit>`. That is, if the metre and the second are
base units, the metre per second is the coherent derived unit of velocity.
base units, the metre per second is the coherent derived unit of speed.
system of units
- Set of `base units <base unit>` and `derived units <derived unit>`, together with

View File

@@ -28,13 +28,13 @@ but still easy to use interface where all unit conversions and dimensional analy
performed without sacrificing on accuracy. Please see the below example for a quick preview
of basic library features::
#include <units/physical/si/velocity.h>
#include <units/physical/international/velocity.h>
#include <units/physical/si/speed.h>
#include <units/physical/international/speed.h>
#include <iostream>
using namespace units::physical;
constexpr Velocity auto avg_speed(Length auto d, Time auto t)
constexpr Speed auto avg_speed(Length auto d, Time auto t)
{
return d / t;
}
@@ -42,10 +42,10 @@ of basic library features::
int main()
{
using namespace units::physical::si::literals;
Velocity auto v1 = avg_speed(220q_km, 2q_h);
Velocity auto v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
Velocity auto v3 = quantity_cast<si::metre_per_second>(v2);
Velocity auto v4 = quantity_cast<int>(v3);
Speed auto v1 = avg_speed(220q_km, 2q_h);
Speed auto v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
Speed auto v3 = quantity_cast<si::metre_per_second>(v2);
Speed auto v4 = quantity_cast<int>(v3);
std::cout << v1 << '\n'; // 110 km/h
std::cout << v2 << '\n'; // 70 mi/h

View File

@@ -19,18 +19,18 @@ pass it to the library's output:
.. code-block::
#include "legacy.h"
#include <units/physical/si/velocity.h>
#include <units/physical/si/speed.h>
using namespace units::physical;
constexpr Velocity auto avg_speed(Length auto d, Time auto t)
constexpr Speed auto avg_speed(Length auto d, Time auto t)
{
return d / t;
}
void print_eta(Length auto d, Time auto t)
{
Velocity auto v = avg_speed(d, t);
Speed auto v = avg_speed(d, t);
legacy::print_eta(quantity_cast<si::metre_per_second>(v).count());
}

View File

@@ -20,23 +20,23 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/physical/cgs/velocity.h>
#include <units/physical/si/velocity.h>
#include <units/physical/international/velocity.h>
#include <units/physical/cgs/speed.h>
#include <units/physical/si/speed.h>
#include <units/physical/international/speed.h>
#include <iostream>
namespace {
using namespace units::physical;
constexpr si::velocity<si::metre_per_second, int>
constexpr si::speed<si::metre_per_second, int>
fixed_int_si_avg_speed(si::length<si::metre, int> d,
si::time<si::second, int> t)
{
return d / t;
}
constexpr si::velocity<si::metre_per_second>
constexpr si::speed<si::metre_per_second>
fixed_double_si_avg_speed(si::length<si::metre> d,
si::time<si::second> t)
{
@@ -44,21 +44,21 @@ fixed_double_si_avg_speed(si::length<si::metre> d,
}
template<typename U1, typename R1, typename U2, typename R2>
constexpr Velocity AUTO si_avg_speed(si::length<U1, R1> d,
constexpr Speed AUTO si_avg_speed(si::length<U1, R1> d,
si::time<U2, R2> t)
{
return d / t;
}
constexpr Velocity AUTO avg_speed(Length AUTO d, Time AUTO t)
constexpr Speed AUTO avg_speed(Length AUTO d, Time AUTO t)
{
return d / t;
}
template<Length D, Time T, Velocity V>
void print_result(D distance, T duration, V velocity)
template<Length D, Time T, Speed V>
void print_result(D distance, T duration, V speed)
{
const auto result_in_kmph = units::quantity_cast<si::velocity<si::kilometre_per_hour>>(velocity);
const auto result_in_kmph = units::quantity_cast<si::speed<si::kilometre_per_hour>>(speed);
std::cout << "Average speed of a car that makes " << distance << " in "
<< duration << " is " << result_in_kmph << ".\n";
}

View File

@@ -20,14 +20,14 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/physical/si/velocity.h>
#include <units/physical/international/velocity.h>
#include <units/physical/si/speed.h>
#include <units/physical/international/speed.h>
#include <units/format.h>
#include <iostream>
using namespace units::physical;
constexpr Velocity AUTO avg_speed(Length AUTO d, Time AUTO t)
constexpr Speed AUTO avg_speed(Length AUTO d, Time AUTO t)
{
return d / t;
}
@@ -35,10 +35,10 @@ constexpr Velocity AUTO avg_speed(Length AUTO d, Time AUTO t)
int main()
{
using namespace units::physical::si::literals;
Velocity AUTO v1 = avg_speed(220q_km, 2q_h);
Velocity AUTO v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
Velocity AUTO v3 = quantity_cast<si::metre_per_second>(v2);
Velocity AUTO v4 = quantity_cast<int>(v3);
Speed AUTO v1 = avg_speed(220q_km, 2q_h);
Speed AUTO v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
Speed AUTO v3 = quantity_cast<si::metre_per_second>(v2);
Speed AUTO v4 = quantity_cast<int>(v3);
std::cout << v1 << '\n'; // 110 km/h
std::cout << fmt::format("{}", v2) << '\n'; // 70 mi/h

View File

@@ -1,7 +1,7 @@
#include <units/format.h>
#include <units/physical/si/length.h>
#include <units/physical/si/time.h>
#include <units/physical/si/velocity.h>
#include <units/physical/si/speed.h>
#include <iostream>
#include <array>
@@ -12,25 +12,24 @@
namespace {
using namespace units;
template<Quantity Q>
template<units::Quantity Q>
struct state_variable {
Q estimated_current_state;
Q predicted_next_state;
};
using namespace units::physical::si;
using namespace units::physical;
using namespace units::physical::si::literals;
constexpr auto radar_transmit_interval = 5.0q_s;
constexpr double kalman_range_gain = 0.2;
constexpr double kalman_speed_gain = 0.1;
struct state {
state_variable<length<metre>> range;
state_variable<velocity<metre_per_second>> speed;
state_variable<si::length<si::metre>> range;
state_variable<si::speed<si::metre_per_second>> speed;
constexpr void estimate(const state& previous_state, const length<metre>& measurement)
constexpr void estimate(const state& previous_state, const si::length<si::metre>& measurement)
{
auto const innovation = measurement - previous_state.range.predicted_next_state;
range.estimated_current_state = previous_state.range.predicted_next_state + kalman_range_gain * innovation;

View File

@@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/physical/si/velocity.h>
#include <units/physical/si/speed.h>
#include <units/physical/si/force.h>
#include <units/physical/si/energy.h>
#include <units/format.h>

View File

@@ -162,7 +162,7 @@ void example()
const auto a = si::acceleration<si::metre_per_second_sq, measurement<double>>(measurement(9.8, 0.1));
const auto t = si::time<si::second, measurement<double>>(measurement(1.2, 0.1));
const Velocity AUTO v1 = a * t;
const Speed AUTO v1 = a * t;
std::cout << a << " * " << t << " = " << v1 << " = " << quantity_cast<si::kilometre_per_hour>(v1) << '\n';
si::length<si::metre, measurement<double>> length(measurement(123., 1.));

View File

@@ -23,7 +23,7 @@
#include <units/physical/natural/constants.h>
#include <units/physical/si/energy.h>
#include <units/physical/si/momentum.h>
#include <units/physical/si/velocity.h>
#include <units/physical/si/speed.h>
#include <units/physical/si/constants.h>
#include <units/math.h>
#include <iostream>
@@ -32,7 +32,7 @@ namespace {
using namespace units::physical;
Energy AUTO total_energy(Momentum AUTO p, Mass AUTO m, Velocity AUTO c)
Energy AUTO total_energy(Momentum AUTO p, Mass AUTO m, Speed AUTO c)
{
return sqrt(pow<2>(p * c) + pow<2>(m * pow<2>(c)));
}
@@ -42,7 +42,7 @@ void si_example()
using namespace units::physical::si;
using GeV = gigaelectronvolt;
constexpr Velocity AUTO c = si2019::speed_of_light<>;
constexpr Speed AUTO c = si2019::speed_of_light<>;
std::cout << "\n*** SI units (c = " << c << ") ***\n";
@@ -73,7 +73,7 @@ void natural_example()
using namespace units::physical::natural;
using GeV = gigaelectronvolt;
constexpr Velocity AUTO c = speed_of_light<>;
constexpr Speed AUTO c = speed_of_light<>;
const momentum<GeV> p(4);
const mass<GeV> m(3);
const Energy AUTO E = total_energy(p, m, c);

View File

@@ -20,13 +20,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/physical/si/velocity.h>
#include <units/physical/si/speed.h>
#include <iostream>
namespace {
template<units::physical::Length D, units::physical::Time T>
constexpr units::physical::Velocity AUTO avg_speed(D d, T t)
constexpr units::physical::Speed AUTO avg_speed(D d, T t)
{
return d / t;
}
@@ -38,10 +38,10 @@ void example()
Length AUTO d1 = 123q_m;
Time AUTO t1 = 10q_s;
Velocity AUTO v1 = avg_speed(d1, t1);
Speed AUTO v1 = avg_speed(d1, t1);
auto temp1 = v1 * 50q_m; // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit'
Velocity AUTO v2 = temp1 / 100q_m; // back to known dimensions again
Speed AUTO v2 = temp1 / 100q_m; // back to known dimensions again
Length AUTO d2 = v2 * 60q_s;
std::cout << "d1 = " << d1 << '\n';

View File

@@ -50,7 +50,7 @@ add_library(units INTERFACE)
# include/units/si/frequency.h
# include/units/si/length.h
# include/units/si/time.h
# include/units/si/velocity.h
# include/units/si/speed.h
#)
target_compile_features(units INTERFACE cxx_std_20)
target_link_libraries(units

View File

@@ -35,7 +35,7 @@ namespace units::detail {
* quantities as a product of powers of factors corresponding to the base quantities, omitting any numerical factors.
* A power of a factor is the factor raised to an exponent.
*
* A derived dimension can be formed from multiple exponents (i.e. velocity is represented as "exp<L, 1>, exp<T, -1>").
* A derived dimension can be formed from multiple exponents (i.e. speed is represented as "exp<L, 1>, exp<T, -1>").
* It is also possible to form a derived dimension with only one exponent (i.e. frequency is represented as just
* "exp<T, -1>").
*

View File

@@ -23,7 +23,7 @@
#pragma once
#include <units/physical/dimensions.h>
#include <units/physical/cgs/velocity.h>
#include <units/physical/cgs/speed.h>
#include <units/quantity.h>
namespace units::physical::cgs {

View File

@@ -33,13 +33,13 @@ struct centimetre_per_second : unit<centimetre_per_second> {};
struct dim_velocity : physical::dim_velocity<dim_velocity, centimetre_per_second, dim_length, dim_time> {};
template<Unit U, Scalar Rep = double>
using velocity = quantity<dim_velocity, U, Rep>;
using speed = quantity<dim_velocity, U, Rep>;
inline namespace literals {
// cmps
constexpr auto operator"" q_cm_per_s(unsigned long long l) { return velocity<centimetre_per_second, std::int64_t>(l); }
constexpr auto operator"" q_cm_per_s(long double l) { return velocity<centimetre_per_second, long double>(l); }
constexpr auto operator"" q_cm_per_s(unsigned long long l) { return speed<centimetre_per_second, std::int64_t>(l); }
constexpr auto operator"" q_cm_per_s(long double l) { return speed<centimetre_per_second, long double>(l); }
} // namespace literals

View File

@@ -207,7 +207,7 @@ template<typename T>
concept Volume = QuantityOf<T, dim_volume>;
template<typename T>
concept Velocity = QuantityOf<T, dim_velocity>;
concept Speed = QuantityOf<T, dim_velocity>;
template<typename T>
concept Acceleration = QuantityOf<T, dim_acceleration>;

View File

@@ -22,7 +22,7 @@
#pragma once
#include <units/physical/si/velocity.h>
#include <units/physical/si/speed.h>
#include <units/physical/international/length.h>
namespace units::physical::international {
@@ -32,8 +32,8 @@ struct mile_per_hour : deduced_unit<mile_per_hour, si::dim_velocity, internation
inline namespace literals {
// mph
constexpr auto operator"" q_mi_per_h(unsigned long long l) { return si::velocity<mile_per_hour, std::int64_t>(l); }
constexpr auto operator"" q_mi_per_h(long double l) { return si::velocity<mile_per_hour, long double>(l); }
constexpr auto operator"" q_mi_per_h(unsigned long long l) { return si::speed<mile_per_hour, std::int64_t>(l); }
constexpr auto operator"" q_mi_per_h(long double l) { return si::speed<mile_per_hour, long double>(l); }
} // namespace literals

View File

@@ -27,6 +27,6 @@
namespace units::physical::natural {
template<Scalar Rep = double>
inline constexpr auto speed_of_light = velocity<unitless, Rep>(1);
inline constexpr auto speed_of_light = speed<unitless, Rep>(1);
} // namespace units::physical::natural

View File

@@ -42,7 +42,7 @@ using mass = quantity<dim_mass, U, Rep>;
struct dim_velocity : physical::dim_velocity<dim_velocity, unitless, dim_length, dim_time> {};
template<Unit U, Scalar Rep = double>
using velocity = quantity<dim_velocity, U, Rep>;
using speed = quantity<dim_velocity, U, Rep>;
struct dim_acceleration : physical::dim_acceleration<dim_acceleration, gigaelectronvolt, dim_length, dim_time> {};
template<Unit U, Scalar Rep = double>

View File

@@ -49,6 +49,6 @@
#include "si/resistance.h"
#include "si/surface_tension.h"
#include "si/thermal_conductivity.h"
#include "si/velocity.h"
#include "si/speed.h"
#include "si/voltage.h"
#include "si/volume.h"

View File

@@ -23,7 +23,7 @@
#pragma once
#include <units/physical/dimensions.h>
#include <units/physical/si/velocity.h>
#include <units/physical/si/speed.h>
#include <units/quantity.h>
namespace units::physical::si {

View File

@@ -28,7 +28,7 @@
#include <units/physical/si/power.h>
#include <units/physical/si/substance.h>
#include <units/physical/si/temperature.h>
#include <units/physical/si/velocity.h>
#include <units/physical/si/speed.h>
namespace units::physical::si::si2019 {
@@ -48,7 +48,7 @@ template<Scalar Rep = double>
inline constexpr auto avogadro_constant = Rep(6.02214076e23) / substance<mole, Rep>(1);
template<Scalar Rep = double>
inline constexpr auto speed_of_light = velocity<metre_per_second, Rep>(299'792'458);
inline constexpr auto speed_of_light = speed<metre_per_second, Rep>(299'792'458);
template<Scalar Rep = double>
inline constexpr auto hyperfine_structure_transition_frequency = frequency<hertz, Rep>(9'192'631'770);

View File

@@ -24,7 +24,7 @@
#include <units/physical/dimensions.h>
#include <units/physical/si/mass.h>
#include <units/physical/si/velocity.h>
#include <units/physical/si/speed.h>
#include <units/quantity.h>
namespace units::physical::si {

View File

@@ -35,17 +35,17 @@ struct dim_velocity : physical::dim_velocity<dim_velocity, metre_per_second, dim
struct kilometre_per_hour : deduced_unit<kilometre_per_hour, dim_velocity, kilometre, hour> {};
template<Unit U, Scalar Rep = double>
using velocity = quantity<dim_velocity, U, Rep>;
using speed = quantity<dim_velocity, U, Rep>;
inline namespace literals {
// mps
constexpr auto operator"" q_m_per_s(unsigned long long l) { return velocity<metre_per_second, std::int64_t>(l); }
constexpr auto operator"" q_m_per_s(long double l) { return velocity<metre_per_second, long double>(l); }
constexpr auto operator"" q_m_per_s(unsigned long long l) { return speed<metre_per_second, std::int64_t>(l); }
constexpr auto operator"" q_m_per_s(long double l) { return speed<metre_per_second, long double>(l); }
// kmph
constexpr auto operator"" q_km_per_h(unsigned long long l) { return velocity<kilometre_per_hour, std::int64_t>(l); }
constexpr auto operator"" q_km_per_h(long double l) { return velocity<kilometre_per_hour, long double>(l); }
constexpr auto operator"" q_km_per_h(unsigned long long l) { return speed<kilometre_per_hour, std::int64_t>(l); }
constexpr auto operator"" q_km_per_h(long double l) { return speed<kilometre_per_hour, long double>(l); }
} // namespace literals

View File

@@ -26,7 +26,7 @@
#include "units/physical/si/frequency.h"
#include "units/physical/si/power.h"
#include "units/physical/si/pressure.h"
#include "units/physical/si/velocity.h"
#include "units/physical/si/speed.h"
#include "units/physical/si/volume.h"
#include "units/physical/si/surface_tension.h"
#include "units/physical/si/resistance.h"
@@ -268,7 +268,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]")
SECTION("deduced derived unit")
{
SECTION("velocity")
SECTION("speed")
{
const auto q = 20q_km / 2q_h;
os << q;

View File

@@ -26,7 +26,7 @@
#include "units/physical/international/length.h"
#include "units/physical/international/area.h"
#include "units/physical/international/volume.h"
#include "units/physical/international/velocity.h"
#include "units/physical/international/speed.h"
#include "units/physical/iau/length.h"
#include "units/physical/typographic/length.h"
#include "units/format.h"
@@ -152,7 +152,7 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
CHECK(fmt::format("{}", 1q_THz) == "1 THz");
}
SECTION("velocity")
SECTION("speed")
{
CHECK(fmt::format("{}", 1q_m_per_s) == "1 m/s");
CHECK(fmt::format("{}", 1q_km_per_h) == "1 km/h");

View File

@@ -29,7 +29,7 @@
#include <units/physical/cgs/power.h>
#include <units/physical/cgs/pressure.h>
#include <units/physical/cgs/time.h>
#include <units/physical/cgs/velocity.h>
#include <units/physical/cgs/speed.h>
namespace {
@@ -48,7 +48,7 @@ static_assert(centimetre::symbol == "cm");
/* ************** DERIVED DIMENSIONS IN TERMS OF BASE UNITS **************** */
// velocity
// speed
static_assert(10q_cm / 5q_s == 2q_cm_per_s);
static_assert(10q_cm / 2q_cm_per_s == 5q_s);

View File

@@ -23,7 +23,7 @@
#include "units/math.h"
#include "units/physical/si/area.h"
#include "units/physical/si/frequency.h"
#include "units/physical/si/velocity.h"
#include "units/physical/si/speed.h"
#include <chrono>
#include <utility>
@@ -249,30 +249,30 @@ static_assert(length<kilometre, expl_impl<int>>(quantity_cast<kilometre>(length<
// static_assert(length<kilometre, expl_expl<int>>(length<metre, expl_expl<int>>(expl_expl<int>(2000))).count() == expl_expl<int>(2)); // should not compile (truncating conversion)
static_assert(length<kilometre, expl_expl<int>>(quantity_cast<kilometre>(length<metre, expl_expl<int>>(expl_expl<int>(2000)))).count() == expl_expl<int>(2));
// static_assert(velocity<metre_per_second, impl<int>>(velocity<kilometre_per_hour, impl<int>>(72)).count() == impl<int>(20)); // should not compile (truncating conversion)
static_assert(velocity<metre_per_second, impl<int>>(quantity_cast<metre_per_second>(velocity<kilometre_per_hour, impl<int>>(72))).count() == impl<int>(20));
// static_assert(velocity<metre_per_second, expl<int>>(velocity<kilometre_per_hour, expl<int>>(expl(72))).count() == expl<int>(20)); // should not compile (truncating conversion)
static_assert(velocity<metre_per_second, expl<int>>(quantity_cast<metre_per_second>(velocity<kilometre_per_hour, expl<int>>(expl<int>(72)))).count() == expl<int>(20));
// static_assert(velocity<metre_per_second, impl_impl<int>>(velocity<kilometre_per_hour, impl_impl<int>>(72)).count() == impl_impl<int>(20)); // should not compile (truncating conversion)
static_assert(velocity<metre_per_second, impl_impl<int>>(quantity_cast<metre_per_second>(velocity<kilometre_per_hour, impl_impl<int>>(72))).count() == impl_impl<int>(20));
// static_assert(velocity<metre_per_second, impl_expl<int>>(velocity<kilometre_per_hour, impl_expl<int>>(72)).count() == impl_expl<int>(20)); // should not compile (truncating conversion)
static_assert(velocity<metre_per_second, impl_expl<int>>(quantity_cast<metre_per_second>(velocity<kilometre_per_hour, impl_expl<int>>(72))).count() == impl_expl<int>(20));
// static_assert(velocity<metre_per_second, expl_impl<int>>(velocity<kilometre_per_hour, expl_impl<int>>(expl_impl(72))).count() == expl_impl<int>(20)); // should not compile (truncating conversion)
static_assert(velocity<metre_per_second, expl_impl<int>>(quantity_cast<metre_per_second>(velocity<kilometre_per_hour, expl_impl<int>>(expl_impl<int>(72)))).count() == expl_impl<int>(20));
// static_assert(velocity<metre_per_second, expl_expl<int>>(velocity<kilometre_per_hour, expl_expl<int>>(expl_expl(72))).count() == expl_expl<int>(20)); // should not compile (truncating conversion)
static_assert(velocity<metre_per_second, expl_expl<int>>(quantity_cast<metre_per_second>(velocity<kilometre_per_hour, expl_expl<int>>(expl_expl<int>(72)))).count() == expl_expl<int>(20));
// static_assert(speed<metre_per_second, impl<int>>(speed<kilometre_per_hour, impl<int>>(72)).count() == impl<int>(20)); // should not compile (truncating conversion)
static_assert(speed<metre_per_second, impl<int>>(quantity_cast<metre_per_second>(speed<kilometre_per_hour, impl<int>>(72))).count() == impl<int>(20));
// static_assert(speed<metre_per_second, expl<int>>(speed<kilometre_per_hour, expl<int>>(expl(72))).count() == expl<int>(20)); // should not compile (truncating conversion)
static_assert(speed<metre_per_second, expl<int>>(quantity_cast<metre_per_second>(speed<kilometre_per_hour, expl<int>>(expl<int>(72)))).count() == expl<int>(20));
// static_assert(speed<metre_per_second, impl_impl<int>>(speed<kilometre_per_hour, impl_impl<int>>(72)).count() == impl_impl<int>(20)); // should not compile (truncating conversion)
static_assert(speed<metre_per_second, impl_impl<int>>(quantity_cast<metre_per_second>(speed<kilometre_per_hour, impl_impl<int>>(72))).count() == impl_impl<int>(20));
// static_assert(speed<metre_per_second, impl_expl<int>>(speed<kilometre_per_hour, impl_expl<int>>(72)).count() == impl_expl<int>(20)); // should not compile (truncating conversion)
static_assert(speed<metre_per_second, impl_expl<int>>(quantity_cast<metre_per_second>(speed<kilometre_per_hour, impl_expl<int>>(72))).count() == impl_expl<int>(20));
// static_assert(speed<metre_per_second, expl_impl<int>>(speed<kilometre_per_hour, expl_impl<int>>(expl_impl(72))).count() == expl_impl<int>(20)); // should not compile (truncating conversion)
static_assert(speed<metre_per_second, expl_impl<int>>(quantity_cast<metre_per_second>(speed<kilometre_per_hour, expl_impl<int>>(expl_impl<int>(72)))).count() == expl_impl<int>(20));
// static_assert(speed<metre_per_second, expl_expl<int>>(speed<kilometre_per_hour, expl_expl<int>>(expl_expl(72))).count() == expl_expl<int>(20)); // should not compile (truncating conversion)
static_assert(speed<metre_per_second, expl_expl<int>>(quantity_cast<metre_per_second>(speed<kilometre_per_hour, expl_expl<int>>(expl_expl<int>(72)))).count() == expl_expl<int>(20));
// static_assert(velocity<kilometre_per_hour, impl<int>>(velocity<metre_per_second, impl<int>>(20)).count() == impl<int>(72)); // should not compile (truncating conversion)
static_assert(velocity<kilometre_per_hour, impl<int>>(quantity_cast<kilometre_per_hour>(velocity<metre_per_second, impl<int>>(20))).count() == impl<int>(72));
// static_assert(velocity<kilometre_per_hour, expl<int>>(velocity<metre_per_second, expl<int>>(expl<int>(20))).count() == expl<int>(72)); // should not compile (truncating conversion)
static_assert(velocity<kilometre_per_hour, expl<int>>(quantity_cast<kilometre_per_hour>(velocity<metre_per_second, expl<int>>(expl<int>(20)))).count() == expl<int>(72));
// static_assert(velocity<kilometre_per_hour, impl_impl<int>>(velocity<metre_per_second, impl_impl<int>>(20)).count() == impl_impl<int>(72)); // should not compile (truncating conversion)
static_assert(velocity<kilometre_per_hour, impl_impl<int>>(quantity_cast<kilometre_per_hour>(velocity<metre_per_second, impl_impl<int>>(20))).count() == impl_impl<int>(72));
// static_assert(velocity<kilometre_per_hour, impl_expl<int>>(velocity<metre_per_second, impl_expl<int>>(20)).count() == impl_expl<int>(72)); // should not compile (truncating conversion)
static_assert(velocity<kilometre_per_hour, impl_expl<int>>(quantity_cast<kilometre_per_hour>(velocity<metre_per_second, impl_expl<int>>(20))).count() == impl_expl<int>(72));
// static_assert(velocity<kilometre_per_hour, expl_impl<int>>(velocity<metre_per_second, expl_impl<int>>(expl_impl<int>(20))).count() == expl_impl<int>(72)); // should not compile (truncating conversion)
static_assert(velocity<kilometre_per_hour, expl_impl<int>>(quantity_cast<kilometre_per_hour>(velocity<metre_per_second, expl_impl<int>>(expl_impl<int>(20)))).count() == expl_impl<int>(72));
// static_assert(velocity<kilometre_per_hour, expl_expl<int>>(velocity<metre_per_second, expl_expl<int>>(expl_expl<int>(20))).count() == expl_expl<int>(72)); // should not compile (truncating conversion)
static_assert(velocity<kilometre_per_hour, expl_expl<int>>(quantity_cast<kilometre_per_hour>(velocity<metre_per_second, expl_expl<int>>(expl_expl<int>(20)))).count() == expl_expl<int>(72));
// static_assert(speed<kilometre_per_hour, impl<int>>(speed<metre_per_second, impl<int>>(20)).count() == impl<int>(72)); // should not compile (truncating conversion)
static_assert(speed<kilometre_per_hour, impl<int>>(quantity_cast<kilometre_per_hour>(speed<metre_per_second, impl<int>>(20))).count() == impl<int>(72));
// static_assert(speed<kilometre_per_hour, expl<int>>(speed<metre_per_second, expl<int>>(expl<int>(20))).count() == expl<int>(72)); // should not compile (truncating conversion)
static_assert(speed<kilometre_per_hour, expl<int>>(quantity_cast<kilometre_per_hour>(speed<metre_per_second, expl<int>>(expl<int>(20)))).count() == expl<int>(72));
// static_assert(speed<kilometre_per_hour, impl_impl<int>>(speed<metre_per_second, impl_impl<int>>(20)).count() == impl_impl<int>(72)); // should not compile (truncating conversion)
static_assert(speed<kilometre_per_hour, impl_impl<int>>(quantity_cast<kilometre_per_hour>(speed<metre_per_second, impl_impl<int>>(20))).count() == impl_impl<int>(72));
// static_assert(speed<kilometre_per_hour, impl_expl<int>>(speed<metre_per_second, impl_expl<int>>(20)).count() == impl_expl<int>(72)); // should not compile (truncating conversion)
static_assert(speed<kilometre_per_hour, impl_expl<int>>(quantity_cast<kilometre_per_hour>(speed<metre_per_second, impl_expl<int>>(20))).count() == impl_expl<int>(72));
// static_assert(speed<kilometre_per_hour, expl_impl<int>>(speed<metre_per_second, expl_impl<int>>(expl_impl<int>(20))).count() == expl_impl<int>(72)); // should not compile (truncating conversion)
static_assert(speed<kilometre_per_hour, expl_impl<int>>(quantity_cast<kilometre_per_hour>(speed<metre_per_second, expl_impl<int>>(expl_impl<int>(20)))).count() == expl_impl<int>(72));
// static_assert(speed<kilometre_per_hour, expl_expl<int>>(speed<metre_per_second, expl_expl<int>>(expl_expl<int>(20))).count() == expl_expl<int>(72)); // should not compile (truncating conversion)
static_assert(speed<kilometre_per_hour, expl_expl<int>>(quantity_cast<kilometre_per_hour>(speed<metre_per_second, expl_expl<int>>(expl_expl<int>(20)))).count() == expl_expl<int>(72));
} // namespace

View File

@@ -57,8 +57,8 @@ static_assert(!Area<si::time<si::second>>);
static_assert(Volume<si::volume<si::cubic_metre>>);
static_assert(!Volume<si::time<si::second>>);
static_assert(Velocity<si::velocity<si::metre_per_second>>);
static_assert(!Velocity<si::time<si::second>>);
static_assert(Speed<si::speed<si::metre_per_second>>);
static_assert(!Speed<si::time<si::second>>);
static_assert(Acceleration<si::acceleration<si::metre_per_second_sq>>);
static_assert(!Acceleration<si::time<si::second>>);

View File

@@ -21,7 +21,7 @@
// SOFTWARE.
#include "units/physical/si/area.h"
#include "units/physical/si/velocity.h"
#include "units/physical/si/speed.h"
#include "units/physical/international/area.h"
#include "units/math.h"

View File

@@ -23,7 +23,7 @@
#include "units/math.h"
#include "units/physical/si/area.h"
#include "units/physical/si/frequency.h"
#include "units/physical/si/velocity.h"
#include "units/physical/si/speed.h"
#include "units/physical/si/volume.h"
#include <chrono>
#include <utility>
@@ -135,9 +135,9 @@ static_assert(
static_assert(std::is_same_v<decltype(length<metre, int>() * 1.0), length<metre, double>>);
static_assert(std::is_same_v<decltype(1.0 * length<metre, int>()), length<metre, double>>);
static_assert(
std::is_same_v<decltype(velocity<metre_per_second, int>() * physical::si::time<second, int>()), length<metre, int>>);
std::is_same_v<decltype(speed<metre_per_second, int>() * physical::si::time<second, int>()), length<metre, int>>);
static_assert(
std::is_same_v<decltype(velocity<metre_per_second, int>() * physical::si::time<hour, int>()), length<scaled_unit<ratio<36, 1, 2>, metre>, int>>);
std::is_same_v<decltype(speed<metre_per_second, int>() * physical::si::time<hour, int>()), length<scaled_unit<ratio<36, 1, 2>, metre>, int>>);
static_assert(std::is_same_v<decltype(length<metre>() * physical::si::time<minute>()),
quantity<unknown_dimension<units::exp<dim_length, 1>, units::exp<dim_time, 1>>, scaled_unit<ratio<6, 1, 1>, unknown_coherent_unit>>>);
static_assert(std::is_same_v<decltype(1 / physical::si::time<second, int>()), frequency<hertz, int>>);
@@ -149,9 +149,9 @@ static_assert(std::is_same_v<decltype(length<metre, int>() / 1.0), length<metre,
static_assert(std::is_same_v<decltype(length<metre, int>() / length<metre, double>()), double>);
static_assert(std::is_same_v<decltype(length<kilometre, int>() / length<metre, double>()), double>);
static_assert(
std::is_same_v<decltype(length<metre, int>() / physical::si::time<second, int>()), velocity<metre_per_second, int>>);
std::is_same_v<decltype(length<metre, int>() / physical::si::time<second, int>()), speed<metre_per_second, int>>);
static_assert(
std::is_same_v<decltype(length<metre>() / physical::si::time<minute>()), velocity<scaled_unit<ratio<1, 6, -1>, metre_per_second>>>);
std::is_same_v<decltype(length<metre>() / physical::si::time<minute>()), speed<scaled_unit<ratio<1, 6, -1>, metre_per_second>>>);
static_assert(std::is_same_v<decltype(physical::si::time<minute>() / length<metre>()),
quantity<unknown_dimension<units::exp<dim_length, -1>, units::exp<dim_time, 1>>, scaled_unit<ratio<6 ,1 , 1>, unknown_coherent_unit>>>);
static_assert(std::is_same_v<decltype(length<metre, int>() % short(1)), length<metre, int>>);
@@ -245,7 +245,7 @@ static_assert(1q_km + 1q_m == 1001q_m);
static_assert(10q_km / 5q_km == 2);
static_assert(10q_km / 2 == 5q_km);
// velocity
// speed
static_assert(10q_m / 5q_s == 2q_m_per_s);
static_assert(10 / 5q_s * 1q_m == 2q_m_per_s);

View File

@@ -30,7 +30,7 @@
#include <units/physical/cgs/power.h>
#include <units/physical/cgs/pressure.h>
#include <units/physical/cgs/time.h>
#include <units/physical/cgs/velocity.h>
#include <units/physical/cgs/speed.h>
#include <units/physical/si/acceleration.h>
#include <units/physical/si/area.h>
#include <units/physical/si/energy.h>
@@ -40,7 +40,7 @@
#include <units/physical/si/power.h>
#include <units/physical/si/pressure.h>
#include <units/physical/si/time.h>
#include <units/physical/si/velocity.h>
#include <units/physical/si/speed.h>
namespace {
@@ -49,7 +49,7 @@ using namespace units::physical;
static_assert(cgs::length<cgs::centimetre>(100) == si::length<si::metre>(1));
static_assert(cgs::mass<cgs::gram>(1'000) == si::mass<si::kilogram>(1));
static_assert(cgs::time<cgs::second>(1) == si::time<si::second>(1));
static_assert(cgs::velocity<cgs::centimetre_per_second>(100) == si::velocity<si::metre_per_second>(1));
static_assert(cgs::speed<cgs::centimetre_per_second>(100) == si::speed<si::metre_per_second>(1));
static_assert(cgs::area<cgs::square_centimetre>(10000) == si::area<si::square_metre>(1));
static_assert(cgs::acceleration<cgs::gal>(100) == si::acceleration<si::metre_per_second_sq>(1));
static_assert(cgs::force<cgs::dyne>(100'000) == si::force<si::newton>(1));
@@ -64,7 +64,7 @@ using namespace units::physical::si::literals;
static_assert(cgs::length<cgs::centimetre>(100) == 1q_m);
static_assert(cgs::mass<cgs::gram>(1'000) == 1q_kg);
static_assert(cgs::time<cgs::second>(1) == 1q_s);
static_assert(cgs::velocity<cgs::centimetre_per_second>(100) == 1q_m_per_s);
static_assert(cgs::speed<cgs::centimetre_per_second>(100) == 1q_m_per_s);
static_assert(cgs::acceleration<cgs::gal>(100) == 1q_m_per_s2);
static_assert(cgs::force<cgs::dyne>(100'000) == 1q_N);
static_assert(cgs::energy<cgs::erg>(10'000'000) == 1q_J);
@@ -80,7 +80,7 @@ using namespace units::physical::cgs::literals;
static_assert(100q_cm == si::length<si::metre>(1));
static_assert(1'000q_g == si::mass<si::kilogram>(1));
static_assert(1q_s == si::time<si::second>(1));
static_assert(100q_cm_per_s == si::velocity<si::metre_per_second>(1));
static_assert(100q_cm_per_s == si::speed<si::metre_per_second>(1));
static_assert(100q_Gal == si::acceleration<si::metre_per_second_sq>(1));
static_assert(100'000q_dyn == si::force<si::newton>(1));
static_assert(10'000'000q_erg == si::energy<si::joule>(1));

View File

@@ -235,9 +235,9 @@ static_assert(kilogray::symbol == "kGy");
/* ************** DERIVED DIMENSIONS IN TERMS OF BASE UNITS **************** */
// velocity
// speed
static_assert(std::is_same_v<decltype(1q_km / 1q_s), velocity<scaled_unit<ratio<1, 1, 3>, metre_per_second>, std::int64_t>>);
static_assert(std::is_same_v<decltype(1q_km / 1q_s), speed<scaled_unit<ratio<1, 1, 3>, metre_per_second>, std::int64_t>>);
static_assert(10q_m / 5q_s == 2q_m_per_s);
static_assert(10 / 5q_s * 1q_m == 2q_m_per_s);

View File

@@ -23,11 +23,11 @@
#include <units/physical/si/area.h>
#include <units/physical/si/length.h>
#include <units/physical/international/length.h>
#include <units/physical/si/velocity.h>
#include <units/physical/si/speed.h>
#include <units/physical/si/volume.h>
#include <units/physical/international/area.h>
#include <units/physical/us/length.h>
#include <units/physical/international/velocity.h>
#include <units/physical/international/speed.h>
#include <units/physical/international/volume.h>
#include <utility>
@@ -52,7 +52,7 @@ static_assert(5q_in + 8q_cm == 207q_mm);
/* ************** DERIVED DIMENSIONS IN TERMS OF BASE UNITS **************** */
// velocity
// speed
static_assert(10.0q_mi / 2q_h == 5q_mi_per_h);

View File

@@ -20,10 +20,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/physical/si/velocity.h>
#include <units/physical/si/speed.h>
#include <iostream>
constexpr units::Velocity AUTO avg_speed(units::Length AUTO d, units::Time AUTO t)
constexpr units::Speed AUTO avg_speed(units::Length AUTO d, units::Time AUTO t)
{
return d / t;
}