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
+2 -2
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);
}
+4 -4
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
+9 -9
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::
+2 -2
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
+1 -1
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