forked from mpusz/mp-units
Velocity renamed to Speed (resolves #103)
This commit is contained in:
+10
-10
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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.));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user