Velocity renamed to Speed (resolves #103)

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

No files matched your search

+2
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
+5 -5
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;
```
+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
+1 -1
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
+7 -7
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
+3 -3
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());
}