forked from mpusz/mp-units
style: clang-format applied to the remaining files
This commit is contained in:
@@ -21,12 +21,12 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/si/cgs/length.h>
|
||||
#include <units/isq/si/cgs/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/cgs/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/international/length.h>
|
||||
#include <units/isq/si/international/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/length.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/international/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/length.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@@ -35,38 +35,31 @@ namespace {
|
||||
|
||||
using namespace units::isq;
|
||||
|
||||
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)
|
||||
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::speed<si::metre_per_second>
|
||||
fixed_double_si_avg_speed(si::length<si::metre> d,
|
||||
si::time<si::second> t)
|
||||
constexpr si::speed<si::metre_per_second> fixed_double_si_avg_speed(si::length<si::metre> d, si::time<si::second> t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
|
||||
template<typename U1, typename R1, typename U2, typename R2>
|
||||
constexpr Speed auto si_avg_speed(si::length<U1, R1> d,
|
||||
si::time<U2, R2> t)
|
||||
constexpr Speed auto si_avg_speed(si::length<U1, R1> d, si::time<U2, R2> t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
|
||||
constexpr Speed auto avg_speed(Length auto d, Time auto t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
constexpr Speed auto avg_speed(Length auto d, Time auto t) { return d / t; }
|
||||
|
||||
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::speed<si::kilometre_per_hour>>(speed);
|
||||
std::cout << "Average speed of a car that makes " << distance << " in "
|
||||
<< duration << " is " << result_in_kmph << ".\n";
|
||||
std::cout << "Average speed of a car that makes " << distance << " in " << duration << " is " << result_in_kmph
|
||||
<< ".\n";
|
||||
}
|
||||
|
||||
void example()
|
||||
@@ -94,7 +87,8 @@ void example()
|
||||
std::cout << "\nSI units with 'double' as representation\n";
|
||||
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<int>(distance), quantity_cast<int>(duration)));
|
||||
print_result(distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<int>(distance), quantity_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, si_avg_speed(distance, duration));
|
||||
@@ -130,7 +124,9 @@ void example()
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
// also it is not possible to make a lossless conversion of miles to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
print_result(
|
||||
distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, si_avg_speed(distance, duration));
|
||||
@@ -169,7 +165,9 @@ void example()
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
// it is not possible to make a lossless conversion of centimeters to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
print_result(
|
||||
distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
|
||||
@@ -178,20 +176,17 @@ void example()
|
||||
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
example();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unhandled unknown exception caught\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <units/isq/si/force.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/mass.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/volume.h>
|
||||
#include <cassert>
|
||||
@@ -40,7 +40,7 @@ namespace {
|
||||
|
||||
using namespace units::aliases::isq::si;
|
||||
|
||||
inline constexpr auto g = units::isq::si::si2019::standard_gravity<>;
|
||||
inline constexpr auto g = units::isq::si::si2019::standard_gravity<>; // NOLINT(readability-identifier-length)
|
||||
inline constexpr auto air_density = kg_per_m3<>(1.225);
|
||||
|
||||
class Box {
|
||||
@@ -48,7 +48,10 @@ class Box {
|
||||
length::m<> height_;
|
||||
density::kg_per_m3<> density_ = air_density;
|
||||
public:
|
||||
constexpr Box(const length::m<>& length, const length::m<>& width, length::m<> height): base_(length * width), height_(std::move(height)) {}
|
||||
constexpr Box(const length::m<>& length, const length::m<>& width, length::m<> height) :
|
||||
base_(length * width), height_(std::move(height))
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr force::N<> filled_weight() const
|
||||
{
|
||||
@@ -86,13 +89,13 @@ int main()
|
||||
auto box = Box(mm<>(1000.0), mm<>(500.0), height);
|
||||
box.set_contents_density(kg_per_m3<>(1000.0));
|
||||
|
||||
const auto fill_time = s<>(200.0); // time since starting fill
|
||||
const auto measured_mass = kg<>(20.0); // measured mass at fill_time
|
||||
const auto fill_time = s<>(200.0); // time since starting fill
|
||||
const auto measured_mass = kg<>(20.0); // measured mass at fill_time
|
||||
|
||||
const Length auto fill_level = box.fill_level(measured_mass);
|
||||
const Dimensionless auto fill_percent = quantity_cast<percent>(fill_level / height);
|
||||
const Volume auto spare_capacity = box.spare_capacity(measured_mass);
|
||||
const auto input_flow_rate = measured_mass / fill_time; // unknown dimension
|
||||
const auto input_flow_rate = measured_mass / fill_time; // unknown dimension
|
||||
const Speed auto float_rise_rate = fill_level / fill_time;
|
||||
const Time auto fill_time_left = (height / fill_level - 1) * fill_time;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <units/isq/si/resistance.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/voltage.h>
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/quantity_io.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ struct Ship {
|
||||
};
|
||||
|
||||
// Print 'a' in its current units and print its value cast to the units in each of Args
|
||||
template<class ...Args, units::Quantity Q>
|
||||
template<class... Args, units::Quantity Q>
|
||||
auto fmt_line(const Q a)
|
||||
{
|
||||
return STD_FMT::format("{:22}", a) + (STD_FMT::format(",{:20}", units::quantity_cast<Args>(a)) + ...);
|
||||
@@ -63,16 +63,21 @@ void print_details(std::string_view description, const Ship& ship)
|
||||
{
|
||||
const auto waterDensity = si::fps::density::lb_per_ft3<>(62.4);
|
||||
std::cout << STD_FMT::format("{}\n", description);
|
||||
std::cout << STD_FMT::format("{:20} : {}\n", "length", fmt_line<si::fps::length::yd<>, si::length::m<>>(ship.length))
|
||||
<< STD_FMT::format("{:20} : {}\n", "draft", fmt_line<si::fps::length::yd<>, si::length::m<>>(ship.draft))
|
||||
<< STD_FMT::format("{:20} : {}\n", "beam", fmt_line<si::fps::length::yd<>, si::length::m<>>(ship.beam))
|
||||
<< STD_FMT::format("{:20} : {}\n", "mass", fmt_line<si::fps::mass::lton<>, si::mass::t<>>(ship.mass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "speed", fmt_line<si::fps::speed::knot<>, si::speed::km_per_h<>>(ship.speed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "power", fmt_line<si::fps::power::hp<>, si::power::kW<>>(ship.power))
|
||||
<< STD_FMT::format("{:20} : {}\n", "main guns", fmt_line<si::fps::length::in<>, si::length::mm<>>(ship.mainGuns))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells weighing",fmt_line<si::fps::mass::lton<>, si::mass::kg<>>(ship.shellMass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells at",fmt_line<si::fps::speed::mph<>, si::speed::km_per_h<>>(ship.shellSpeed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "volume underwater", fmt_line<si::volume::m3<>, si::volume::l<>>(ship.mass / waterDensity));
|
||||
std::cout << STD_FMT::format("{:20} : {}\n", "length", fmt_line<si::fps::length::yd<>, si::length::m<>>(ship.length))
|
||||
<< STD_FMT::format("{:20} : {}\n", "draft", fmt_line<si::fps::length::yd<>, si::length::m<>>(ship.draft))
|
||||
<< STD_FMT::format("{:20} : {}\n", "beam", fmt_line<si::fps::length::yd<>, si::length::m<>>(ship.beam))
|
||||
<< STD_FMT::format("{:20} : {}\n", "mass", fmt_line<si::fps::mass::lton<>, si::mass::t<>>(ship.mass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "speed",
|
||||
fmt_line<si::fps::speed::knot<>, si::speed::km_per_h<>>(ship.speed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "power", fmt_line<si::fps::power::hp<>, si::power::kW<>>(ship.power))
|
||||
<< STD_FMT::format("{:20} : {}\n", "main guns",
|
||||
fmt_line<si::fps::length::in<>, si::length::mm<>>(ship.mainGuns))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells weighing",
|
||||
fmt_line<si::fps::mass::lton<>, si::mass::kg<>>(ship.shellMass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells at",
|
||||
fmt_line<si::fps::speed::mph<>, si::speed::km_per_h<>>(ship.shellSpeed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "volume underwater",
|
||||
fmt_line<si::volume::m3<>, si::volume::l<>>(ship.mass / waterDensity));
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -82,13 +87,37 @@ int main()
|
||||
using units::aliases::isq::si::fps::length::ft; // to disambiguate from si::femptotonne
|
||||
|
||||
// KMS Bismark, using the units the Germans would use, taken from Wiki
|
||||
auto bismark = Ship{.length{m<>(251.)}, .draft{m<>(9.3)}, .beam{m<>(36)}, .speed{km_per_h<>(56)}, .mass{t<>(50'300)}, .mainGuns{mm<>(380)}, .shellMass{kg<>(800)}, .shellSpeed{m_per_s<>(820.)}, .power{kW<>(110.45)}};
|
||||
auto bismark = Ship{.length{m<>(251.)},
|
||||
.draft{m<>(9.3)},
|
||||
.beam{m<>(36)},
|
||||
.speed{km_per_h<>(56)},
|
||||
.mass{t<>(50'300)},
|
||||
.mainGuns{mm<>(380)},
|
||||
.shellMass{kg<>(800)},
|
||||
.shellSpeed{m_per_s<>(820.)},
|
||||
.power{kW<>(110.45)}};
|
||||
|
||||
// USS Iowa, using units from the foot-pound-second system
|
||||
auto iowa = Ship{.length{ft<>(860.)}, .draft{ft<>(37.) + in<>(2.)}, .beam{ft<>(108.) + in<>(2.)}, .speed{knot<>(33)}, .mass{lton<>(57'540)}, .mainGuns{in<>(16)}, .shellMass{lb<>(2700)}, .shellSpeed{ft_per_s<>(2690.)}, .power{hp<>(212'000)}};
|
||||
auto iowa = Ship{.length{ft<>(860.)},
|
||||
.draft{ft<>(37.) + in<>(2.)},
|
||||
.beam{ft<>(108.) + in<>(2.)},
|
||||
.speed{knot<>(33)},
|
||||
.mass{lton<>(57'540)},
|
||||
.mainGuns{in<>(16)},
|
||||
.shellMass{lb<>(2700)},
|
||||
.shellSpeed{ft_per_s<>(2690.)},
|
||||
.power{hp<>(212'000)}};
|
||||
|
||||
// HMS King George V, using units from the foot-pound-second system
|
||||
auto kgv = Ship{.length{ft<>(745.1)}, .draft{ft<>(33.) + in<>(7.5)}, .beam{ft<>(103.2) + in<>(2.5)}, .speed{knot<>(28.3)}, .mass{lton<>(42'245)}, .mainGuns{in<>(14)}, .shellMass{lb<>(1'590)}, .shellSpeed{ft_per_s<>(2483)}, .power{hp<>(110'000)}};
|
||||
auto kgv = Ship{.length{ft<>(745.1)},
|
||||
.draft{ft<>(33.) + in<>(7.5)},
|
||||
.beam{ft<>(103.2) + in<>(2.5)},
|
||||
.speed{knot<>(28.3)},
|
||||
.mass{lton<>(42'245)},
|
||||
.mainGuns{in<>(14)},
|
||||
.shellMass{lb<>(1'590)},
|
||||
.shellSpeed{ft_per_s<>(2483)},
|
||||
.power{hp<>(110'000)}};
|
||||
|
||||
print_details("KMS Bismark, defined in appropriate units from the SI system", bismark);
|
||||
std::cout << "\n\n";
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <units/chrono.h>
|
||||
#include <units/generic/dimensionless.h>
|
||||
#include <units/isq/si/international/length.h>
|
||||
|
||||
#include <array>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@@ -43,14 +42,14 @@ using namespace units::isq;
|
||||
auto get_gliders()
|
||||
{
|
||||
using namespace units::aliases::isq::si;
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||
static const std::array gliders = {
|
||||
glider{"SZD-30 Pirat", {velocity(km_per_h<>(83)), rate_of_climb(m_per_s<>(-0.7389))}},
|
||||
glider{"SZD-51 Junior", {velocity(km_per_h<>(80)), rate_of_climb(m_per_s<>(-0.6349))}},
|
||||
glider{"SZD-48 Jantar Std 3", {velocity(km_per_h<>(110)), rate_of_climb(m_per_s<>(-0.77355))}},
|
||||
glider{"SZD-56 Diana", {velocity(km_per_h<>(110)), rate_of_climb(m_per_s<>(-0.63657))}}};
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
glider{"SZD-30 Pirat", {velocity(km_per_h<>(83)), rate_of_climb(m_per_s<>(-0.7389))}},
|
||||
glider{"SZD-51 Junior", {velocity(km_per_h<>(80)), rate_of_climb(m_per_s<>(-0.6349))}},
|
||||
glider{"SZD-48 Jantar Std 3", {velocity(km_per_h<>(110)), rate_of_climb(m_per_s<>(-0.77355))}},
|
||||
glider{"SZD-56 Diana", {velocity(km_per_h<>(110)), rate_of_climb(m_per_s<>(-0.63657))}}};
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
return gliders;
|
||||
}
|
||||
|
||||
@@ -58,9 +57,9 @@ auto get_weather_conditions()
|
||||
{
|
||||
using namespace units::aliases::isq::si;
|
||||
static const std::array weather_conditions = {
|
||||
std::pair("Good", weather{height(m<>(1900)), rate_of_climb(m_per_s<>(4.3))}),
|
||||
std::pair("Medium", weather{height(m<>(1550)), rate_of_climb(m_per_s<>(2.8))}),
|
||||
std::pair("Bad", weather{height(m<>(850)), rate_of_climb(m_per_s<>(1.8))})};
|
||||
std::pair("Good", weather{height(m<>(1900)), rate_of_climb(m_per_s<>(4.3))}),
|
||||
std::pair("Medium", weather{height(m<>(1550)), rate_of_climb(m_per_s<>(2.8))}),
|
||||
std::pair("Bad", weather{height(m<>(850)), rate_of_climb(m_per_s<>(1.8))})};
|
||||
return weather_conditions;
|
||||
}
|
||||
|
||||
@@ -69,14 +68,14 @@ auto get_waypoints()
|
||||
using namespace geographic::literals;
|
||||
using namespace units::aliases::isq::si::international;
|
||||
static const std::array waypoints = {
|
||||
waypoint{"EPPR", {54.24772_N, 18.6745_E}, altitude(ft<>(16))}, // N54°14'51.8" E18°40'28.2"
|
||||
waypoint{"EPGI", {53.52442_N, 18.84947_E}, altitude(ft<>(115))} // N53°31'27.9" E18°50'58.1"
|
||||
waypoint{"EPPR", {54.24772_N, 18.6745_E}, altitude(ft<>(16))}, // N54°14'51.8" E18°40'28.2"
|
||||
waypoint{"EPGI", {53.52442_N, 18.84947_E}, altitude(ft<>(115))} // N53°31'27.9" E18°50'58.1"
|
||||
};
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, glider>
|
||||
requires(std::same_as<std::ranges::range_value_t<R>, glider>)
|
||||
void print(const R& gliders)
|
||||
{
|
||||
std::cout << "Gliders:\n";
|
||||
@@ -85,13 +84,14 @@ void print(const R& gliders)
|
||||
std::cout << "- Name: " << g.name << "\n";
|
||||
std::cout << "- Polar:\n";
|
||||
for (const auto& p : g.polar)
|
||||
std::cout << STD_FMT::format(" * {:%.4Q %q} @ {:%.1Q %q} -> {:%.1Q %q}\n", p.climb, p.v, units::quantity_cast<units::one>(glide_ratio(g.polar[0])));
|
||||
std::cout << STD_FMT::format(" * {:%.4Q %q} @ {:%.1Q %q} -> {:%.1Q %q}\n", p.climb, p.v,
|
||||
units::quantity_cast<units::one>(glide_ratio(g.polar[0])));
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, std::pair<const char*, weather>>
|
||||
requires(std::same_as<std::ranges::range_value_t<R>, std::pair<const char*, weather>>)
|
||||
void print(const R& conditions)
|
||||
{
|
||||
std::cout << "Weather:\n";
|
||||
@@ -106,7 +106,7 @@ void print(const R& conditions)
|
||||
}
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, waypoint>
|
||||
requires(std::same_as<std::ranges::range_value_t<R>, waypoint>)
|
||||
void print(const R& waypoints)
|
||||
{
|
||||
std::cout << "Waypoints:\n";
|
||||
@@ -125,7 +125,8 @@ void print(const task& t)
|
||||
std::cout << "- Finish: " << t.get_finish().name << "\n";
|
||||
std::cout << "- Length: " << STD_FMT::format("{:%.1Q %q}", t.get_length()) << "\n";
|
||||
|
||||
std::cout << "- Legs: " << "\n";
|
||||
std::cout << "- Legs: "
|
||||
<< "\n";
|
||||
for (const auto& l : t.get_legs())
|
||||
std::cout << STD_FMT::format(" * {} -> {} ({:%.1Q %q})\n", l.begin().name, l.end().name, l.get_length());
|
||||
std::cout << "\n";
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/si/energy.h> // IWYU pragma: keep
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/energy.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/force.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/quantity_io.h>
|
||||
#include <linear_algebra.hpp>
|
||||
#include <iostream>
|
||||
#include <linear_algebra.hpp>
|
||||
|
||||
namespace STD_LA {
|
||||
|
||||
@@ -72,9 +72,9 @@ void vector_of_quantity_add()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_add:\n";
|
||||
|
||||
vector<length::m<>> v = { m<>(1), m<>(2), m<>(3) };
|
||||
vector<length::m<>> u = { m<>(3), m<>(2), m<>(1) };
|
||||
vector<length::km<>> t = { km<>(3), km<>(2), km<>(1) };
|
||||
vector<length::m<>> v = {m<>(1), m<>(2), m<>(3)};
|
||||
vector<length::m<>> u = {m<>(3), m<>(2), m<>(1)};
|
||||
vector<length::km<>> t = {km<>(3), km<>(2), km<>(1)};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -89,8 +89,8 @@ void vector_of_quantity_multiply_same()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_multiply_same:\n";
|
||||
|
||||
vector<length::m<>> v = { m<>(1), m<>(2), m<>(3) };
|
||||
vector<length::m<>> u = { m<>(3), m<>(2), m<>(1) };
|
||||
vector<length::m<>> v = {m<>(1), m<>(2), m<>(3)};
|
||||
vector<length::m<>> u = {m<>(3), m<>(2), m<>(1)};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -103,8 +103,8 @@ void vector_of_quantity_multiply_different()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_multiply_different:\n";
|
||||
|
||||
vector<force::N<>> v = { N<>(1), N<>(2), N<>(3) };
|
||||
vector<length::m<>> u = { m<>(3), m<>(2), m<>(1) };
|
||||
vector<force::N<>> v = {N<>(1), N<>(2), N<>(3)};
|
||||
vector<length::m<>> u = {m<>(3), m<>(2), m<>(1)};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -118,7 +118,7 @@ void vector_of_quantity_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_divide_by_scalar:\n";
|
||||
|
||||
vector<length::m<>> v = { m<>(4), m<>(8), m<>(12) };
|
||||
vector<length::m<>> v = {m<>(4), m<>(8), m<>(12)};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
|
||||
@@ -139,9 +139,9 @@ void matrix_of_quantity_add()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_add:\n";
|
||||
|
||||
matrix<length::m<>> v = {{ m<>(1), m<>(2), m<>(3) }, { m<>(4), m<>(5), m<>(6) }, { m<>(7), m<>(8), m<>(9) }};
|
||||
matrix<length::m<>> u = {{ m<>(3), m<>(2), m<>(1) }, { m<>(3), m<>(2), m<>(1) }, { m<>(3), m<>(2), m<>(1) }};
|
||||
matrix<length::mm<>> t = {{ mm<>(3), mm<>(2), mm<>(1) }, { mm<>(3), mm<>(2), mm<>(1) }, { mm<>(3), mm<>(2), mm<>(1) }};
|
||||
matrix<length::m<>> v = {{m<>(1), m<>(2), m<>(3)}, {m<>(4), m<>(5), m<>(6)}, {m<>(7), m<>(8), m<>(9)}};
|
||||
matrix<length::m<>> u = {{m<>(3), m<>(2), m<>(1)}, {m<>(3), m<>(2), m<>(1)}, {m<>(3), m<>(2), m<>(1)}};
|
||||
matrix<length::mm<>> t = {{mm<>(3), mm<>(2), mm<>(1)}, {mm<>(3), mm<>(2), mm<>(1)}, {mm<>(3), mm<>(2), mm<>(1)}};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -158,8 +158,8 @@ void matrix_of_quantity_multiply_same()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_multiply_same:\n";
|
||||
|
||||
matrix<length::m<>> v = {{ m<>(1), m<>(2), m<>(3) }, { m<>(4), m<>(5), m<>(6) }, { m<>(7), m<>(8), m<>(9) }};
|
||||
vector<length::m<>> u = { m<>(3), m<>(2), m<>(1) };
|
||||
matrix<length::m<>> v = {{m<>(1), m<>(2), m<>(3)}, {m<>(4), m<>(5), m<>(6)}, {m<>(7), m<>(8), m<>(9)}};
|
||||
vector<length::m<>> u = {m<>(3), m<>(2), m<>(1)};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -172,8 +172,8 @@ void matrix_of_quantity_multiply_different()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_multiply_different:\n";
|
||||
|
||||
vector<force::N<>> v = { N<>(1), N<>(2), N<>(3) };
|
||||
matrix<length::m<>> u = {{ m<>(1), m<>(2), m<>(3) }, { m<>(4), m<>(5), m<>(6) }, { m<>(7), m<>(8), m<>(9) }};
|
||||
vector<force::N<>> v = {N<>(1), N<>(2), N<>(3)};
|
||||
matrix<length::m<>> u = {{m<>(1), m<>(2), m<>(3)}, {m<>(4), m<>(5), m<>(6)}, {m<>(7), m<>(8), m<>(9)}};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -187,7 +187,7 @@ void matrix_of_quantity_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_divide_by_scalar:\n";
|
||||
|
||||
matrix<length::m<>> v = {{ m<>(2), m<>(4), m<>(6) }, { m<>(4), m<>(6), m<>(8) }, { m<>(8), m<>(4), m<>(2) }};
|
||||
matrix<length::m<>> v = {{m<>(2), m<>(4), m<>(6)}, {m<>(4), m<>(6), m<>(8)}, {m<>(8), m<>(4), m<>(2)}};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
|
||||
@@ -216,9 +216,9 @@ void quantity_of_vector_add()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_add:\n";
|
||||
|
||||
length_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
length_v<si::kilometre> t(vector<>{ 3, 2, 1 });
|
||||
length_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
length_v<si::kilometre> t(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -233,8 +233,8 @@ void quantity_of_vector_multiply_same()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_multiply_same:\n";
|
||||
|
||||
length_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
length_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -247,8 +247,8 @@ void quantity_of_vector_multiply_different()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_multiply_different:\n";
|
||||
|
||||
force_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
force_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -262,7 +262,7 @@ void quantity_of_vector_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_divide_by_scalar:\n";
|
||||
|
||||
length_v<> v(vector<>{ 4, 8, 12 });
|
||||
length_v<> v(vector<>{4, 8, 12});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
|
||||
@@ -286,9 +286,9 @@ void quantity_of_matrix_add()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_add:\n";
|
||||
|
||||
length_m<> v(matrix<>{{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }});
|
||||
length_m<> u(matrix<>{{ 3, 2, 1 }, { 3, 2, 1 }, { 3, 2, 1 }});
|
||||
length_m<si::kilometre> t(matrix<>{{ 3, 2, 1 }, { 3, 2, 1 }, { 3, 2, 1 }});
|
||||
length_m<> v(matrix<>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
|
||||
length_m<> u(matrix<>{{3, 2, 1}, {3, 2, 1}, {3, 2, 1}});
|
||||
length_m<si::kilometre> t(matrix<>{{3, 2, 1}, {3, 2, 1}, {3, 2, 1}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -305,8 +305,8 @@ void quantity_of_matrix_multiply_same()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_multiply_same:\n";
|
||||
|
||||
length_m<> v(matrix<>{{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }});
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
length_m<> v(matrix<>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -319,8 +319,8 @@ void quantity_of_matrix_multiply_different()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_multiply_different:\n";
|
||||
|
||||
force_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_m<> u(matrix<>{{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }});
|
||||
force_v<> v(vector<>{1, 2, 3});
|
||||
length_m<> u(matrix<>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -334,7 +334,7 @@ void quantity_of_matrix_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_divide_by_scalar:\n";
|
||||
|
||||
length_m<> v(matrix<>{{ 2, 4, 6 }, { 4, 6, 8 }, { 8, 4, 2 }});
|
||||
length_m<> v(matrix<>{{2, 4, 6}, {4, 6, 8}, {8, 4, 2}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
|
||||
|
||||
@@ -38,8 +38,7 @@ public:
|
||||
|
||||
measurement() = default;
|
||||
|
||||
constexpr explicit measurement(const value_type& val, const value_type& err = {}) :
|
||||
value_(val)
|
||||
constexpr explicit measurement(const value_type& val, const value_type& err = {}) : value_(val)
|
||||
{
|
||||
// it sucks that using declaration cannot be provided for a constructor initializer list
|
||||
using namespace std;
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/natural/natural.h>
|
||||
#include <units/isq/si/constants.h>
|
||||
#include <units/isq/si/energy.h>
|
||||
#include <units/isq/si/mass.h>
|
||||
#include <units/isq/si/momentum.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/constants.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/math.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <exception>
|
||||
@@ -85,18 +85,16 @@ void natural_example()
|
||||
<< "E = " << E << "\n";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
si_example();
|
||||
natural_example();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unhandled unknown exception caught\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <exception>
|
||||
@@ -44,8 +44,9 @@ void example()
|
||||
Time auto t1 = s<>(10);
|
||||
Speed auto v1 = avg_speed(d1, t1);
|
||||
|
||||
auto temp1 = v1 * m<>(50); // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit'
|
||||
Speed auto v2 = temp1 / m<>(100); // back to known dimensions again
|
||||
auto temp1 =
|
||||
v1 * m<>(50); // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit'
|
||||
Speed auto v2 = temp1 / m<>(100); // back to known dimensions again
|
||||
Length auto d2 = v2 * s<>(60);
|
||||
|
||||
std::cout << "d1 = " << d1 << '\n';
|
||||
@@ -56,17 +57,15 @@ void example()
|
||||
std::cout << "d2 = " << d2 << '\n';
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
example();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unhandled unknown exception caught\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ int main()
|
||||
|
||||
std::cout << STD_FMT::format("therefore ratio lengthA / lengthB == {}\n\n", lengthA / lengthB);
|
||||
|
||||
std::cout << STD_FMT::format("conversion factor from lengthA::unit of {:%q} to lengthB::unit of {:%q}:\n\n", lengthA, lengthB)
|
||||
std::cout << STD_FMT::format("conversion factor from lengthA::unit of {:%q} to lengthB::unit of {:%q}:\n\n", lengthA,
|
||||
lengthB)
|
||||
<< STD_FMT::format("lengthB.number( {} ) == lengthA.number( {} ) * conversion_factor( {} )\n",
|
||||
lengthB.number(), lengthA.number(), conversion_factor(lengthB, lengthA));
|
||||
lengthB.number(), lengthA.number(), conversion_factor(lengthB, lengthA));
|
||||
}
|
||||
|
||||
@@ -66,10 +66,7 @@ using length = quantity<dim_length, U, Rep>;
|
||||
} // namespace si
|
||||
|
||||
template<typename Q, typename U>
|
||||
concept castable_to = Quantity<Q> && Unit<U> &&
|
||||
requires (Q q) {
|
||||
quantity_cast<U>(q);
|
||||
};
|
||||
concept castable_to = Quantity<Q> && Unit<U> && requires(Q q) { quantity_cast<U>(q); };
|
||||
|
||||
void conversions()
|
||||
{
|
||||
|
||||
@@ -49,7 +49,8 @@ distance spherical_distance(position from, position to)
|
||||
if constexpr (sizeof(rep) >= 8) {
|
||||
// spherical law of cosines
|
||||
const auto central_angle = acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1));
|
||||
// const auto central_angle = 2 * asin(sqrt(0.5 - cos(lat2 - lat1) / 2 + cos(lat1) * cos(lat2) * (1 - cos(lon2 - lon1)) / 2));
|
||||
// const auto central_angle = 2 * asin(sqrt(0.5 - cos(lat2 - lat1) / 2 + cos(lat1) * cos(lat2) * (1 - cos(lon2 -
|
||||
// lon1)) / 2));
|
||||
return distance(earth_radius * central_angle);
|
||||
} else {
|
||||
// the haversine formula
|
||||
|
||||
@@ -34,7 +34,8 @@ task::legs task::make_legs(const waypoints& wpts)
|
||||
task::legs res;
|
||||
res.reserve(wpts.size() - 1);
|
||||
auto to_leg = [](const waypoint& w1, const waypoint& w2) { return task::leg(w1, w2); };
|
||||
std::ranges::transform(wpts.cbegin(), prev(wpts.cend()), next(wpts.cbegin()), wpts.cend(), std::back_inserter(res), to_leg);
|
||||
std::ranges::transform(wpts.cbegin(), prev(wpts.cend()), next(wpts.cbegin()), wpts.cend(), std::back_inserter(res),
|
||||
to_leg);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -64,24 +65,23 @@ distance glide_distance(const flight_point& pos, const glider& g, const task& t,
|
||||
((ground_alt - t.get_finish().alt) / dist_to_finish - 1 / glide_ratio(g.polar[0])));
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace glide_computer
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace glide_computer;
|
||||
|
||||
void print(std::string_view phase_name, timestamp start_ts, const glide_computer::flight_point& point, const glide_computer::flight_point& new_point)
|
||||
void print(std::string_view phase_name, timestamp start_ts, const glide_computer::flight_point& point,
|
||||
const glide_computer::flight_point& new_point)
|
||||
{
|
||||
std::cout << STD_FMT::format(
|
||||
"| {:<12} | {:>9%.1Q %q} (Total: {:>9%.1Q %q}) | {:>8%.1Q %q} (Total: {:>8%.1Q %q}) | {:>7%.0Q %q} ({:>6%.0Q %q}) |\n",
|
||||
phase_name, quantity_cast<si::minute>(new_point.ts - point.ts), quantity_cast<si::minute>(new_point.ts - start_ts),
|
||||
new_point.dist - point.dist, new_point.dist, new_point.alt - point.alt, new_point.alt);
|
||||
"| {:<12} | {:>9%.1Q %q} (Total: {:>9%.1Q %q}) | {:>8%.1Q %q} (Total: {:>8%.1Q %q}) | {:>7%.0Q %q} ({:>6%.0Q %q}) "
|
||||
"|\n",
|
||||
phase_name, quantity_cast<si::minute>(new_point.ts - point.ts), quantity_cast<si::minute>(new_point.ts - start_ts),
|
||||
new_point.dist - point.dist, new_point.dist, new_point.alt - point.alt, new_point.alt);
|
||||
}
|
||||
|
||||
flight_point takeoff(timestamp start_ts, const task& t)
|
||||
{
|
||||
return {start_ts, t.get_start().alt};
|
||||
}
|
||||
flight_point takeoff(timestamp start_ts, const task& t) { return {start_ts, t.get_start().alt}; }
|
||||
|
||||
flight_point tow(timestamp start_ts, const flight_point& pos, const aircraft_tow& at)
|
||||
{
|
||||
@@ -92,7 +92,8 @@ flight_point tow(timestamp start_ts, const flight_point& pos, const aircraft_tow
|
||||
return new_pos;
|
||||
}
|
||||
|
||||
flight_point circle(timestamp start_ts, const flight_point& pos, const glider& g, const weather& w, const task& t, height& height_to_gain)
|
||||
flight_point circle(timestamp start_ts, const flight_point& pos, const glider& g, const weather& w, const task& t,
|
||||
height& height_to_gain)
|
||||
{
|
||||
const height h_agl = agl(pos.alt, terrain_level_alt(t, pos));
|
||||
const height circling_height = std::min(w.cloud_base - h_agl, height_to_gain);
|
||||
@@ -114,7 +115,8 @@ flight_point glide(timestamp start_ts, const flight_point& pos, const glider& g,
|
||||
const auto alt = ground_alt + s.min_agl_height;
|
||||
const auto l3d = length_3d(dist, pos.alt - alt);
|
||||
const duration d = l3d / g.polar[0].v.common();
|
||||
const flight_point new_pos{pos.ts + d, terrain_level_alt(t, pos) + s.min_agl_height, t.get_leg_index(new_distance), new_distance};
|
||||
const flight_point new_pos{pos.ts + d, terrain_level_alt(t, pos) + s.min_agl_height, t.get_leg_index(new_distance),
|
||||
new_distance};
|
||||
|
||||
print("Glide", start_ts, pos, new_pos);
|
||||
return new_pos;
|
||||
@@ -135,9 +137,11 @@ flight_point final_glide(timestamp start_ts, const flight_point& pos, const glid
|
||||
|
||||
namespace glide_computer {
|
||||
|
||||
void estimate(timestamp start_ts, const glider& g, const weather& w, const task& t, const safety& s, const aircraft_tow& at)
|
||||
void estimate(timestamp start_ts, const glider& g, const weather& w, const task& t, const safety& s,
|
||||
const aircraft_tow& at)
|
||||
{
|
||||
std::cout << STD_FMT::format("| {:<12} | {:^28} | {:^26} | {:^21} |\n", "Flight phase", "Duration", "Distance", "Height");
|
||||
std::cout << STD_FMT::format("| {:<12} | {:^28} | {:^26} | {:^21} |\n", "Flight phase", "Duration", "Distance",
|
||||
"Height");
|
||||
std::cout << STD_FMT::format("|{0:-^14}|{0:-^30}|{0:-^28}|{0:-^23}|\n", "");
|
||||
|
||||
// ready to takeoff
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <units/bits/fmt_hacks.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/quantity_kind.h>
|
||||
|
||||
#include <limits>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
@@ -32,14 +32,14 @@
|
||||
|
||||
#include <units/chrono.h>
|
||||
#include <units/format.h>
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <ostream>
|
||||
#include <ranges>
|
||||
#include <string> // IWYU pragma: keep
|
||||
#include <string> // IWYU pragma: keep
|
||||
#include <vector>
|
||||
|
||||
// An example of a really simplified tactical glide computer
|
||||
@@ -69,7 +69,7 @@ namespace glide_computer {
|
||||
|
||||
template<units::QuantityKind QK1, units::QuantityKind QK2>
|
||||
constexpr units::Dimensionless auto operator/(const QK1& lhs, const QK2& rhs)
|
||||
requires(!units::QuantityKindRelatedTo<QK1, QK2>) && requires { lhs.common() / rhs.common();}
|
||||
requires(!units::QuantityKindRelatedTo<QK1, QK2>) && requires { lhs.common() / rhs.common(); }
|
||||
{
|
||||
return lhs.common() / rhs.common();
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public:
|
||||
const waypoint* end_;
|
||||
distance length_ = geographic::spherical_distance(begin().pos, end().pos);
|
||||
public:
|
||||
leg(const waypoint& b, const waypoint& e) noexcept: begin_(&b), end_(&e) {}
|
||||
leg(const waypoint& b, const waypoint& e) noexcept : begin_(&b), end_(&e) {}
|
||||
constexpr const waypoint& begin() const { return *begin_; };
|
||||
constexpr const waypoint& end() const { return *end_; }
|
||||
constexpr const distance get_length() const { return length_; }
|
||||
@@ -157,8 +157,11 @@ public:
|
||||
using legs = std::vector<leg>;
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, waypoint>
|
||||
explicit task(const R& r) : waypoints_(std::ranges::begin(r), std::ranges::end(r)) {}
|
||||
requires std::same_as<std::ranges::range_value_t<R>,
|
||||
waypoint> explicit task(const R& r) :
|
||||
waypoints_(std::ranges::begin(r), std::ranges::end(r))
|
||||
{
|
||||
}
|
||||
|
||||
task(std::initializer_list<waypoint> wpts) : waypoints_(wpts) {}
|
||||
|
||||
@@ -170,10 +173,14 @@ public:
|
||||
|
||||
distance get_length() const { return length_; }
|
||||
|
||||
distance get_leg_dist_offset(std::size_t leg_index) const { return leg_index == 0 ? distance{} : leg_total_distances_[leg_index - 1]; }
|
||||
distance get_leg_dist_offset(std::size_t leg_index) const
|
||||
{
|
||||
return leg_index == 0 ? distance{} : leg_total_distances_[leg_index - 1];
|
||||
}
|
||||
std::size_t get_leg_index(distance dist) const
|
||||
{
|
||||
return static_cast<std::size_t>(std::ranges::distance(leg_total_distances_.cbegin(), std::ranges::lower_bound(leg_total_distances_, dist)));
|
||||
return static_cast<std::size_t>(
|
||||
std::ranges::distance(leg_total_distances_.cbegin(), std::ranges::lower_bound(leg_total_distances_, dist)));
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -214,6 +221,7 @@ inline units::isq::si::length<units::isq::si::kilometre> length_3d(distance dist
|
||||
|
||||
distance glide_distance(const flight_point& pos, const glider& g, const task& t, const safety& s, altitude ground_alt);
|
||||
|
||||
void estimate(timestamp start_ts, const glider& g, const weather& w, const task& t, const safety& s, const aircraft_tow& at);
|
||||
void estimate(timestamp start_ts, const glider& g, const weather& w, const task& t, const safety& s,
|
||||
const aircraft_tow& at);
|
||||
|
||||
} // namespace glide_computer
|
||||
|
||||
+10
-13
@@ -22,19 +22,16 @@
|
||||
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/international/length.h>
|
||||
#include <units/isq/si/international/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/international/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace units::isq;
|
||||
|
||||
constexpr Speed auto avg_speed(Length auto d, Time auto t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
constexpr Speed auto avg_speed(Length auto d, Time auto t) { return d / t; }
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -55,11 +52,11 @@ int main()
|
||||
#endif
|
||||
constexpr Speed auto v7 = quantity_cast<int>(v6);
|
||||
|
||||
std::cout << v1 << '\n'; // 110 km/h
|
||||
std::cout << v2 << '\n'; // 70 mi/h
|
||||
std::cout << STD_FMT::format("{}", v3) << '\n'; // 110 km/h
|
||||
std::cout << STD_FMT::format("{:*^14}", v4) << '\n'; // ***70 mi/h****
|
||||
std::cout << STD_FMT::format("{:%Q in %q}", v5) << '\n'; // 30.5556 in m/s
|
||||
std::cout << STD_FMT::format("{0:%Q} in {0:%q}", v6) << '\n'; // 31.2928 in m/s
|
||||
std::cout << STD_FMT::format("{:%Q}", v7) << '\n'; // 31
|
||||
std::cout << v1 << '\n'; // 110 km/h
|
||||
std::cout << v2 << '\n'; // 70 mi/h
|
||||
std::cout << STD_FMT::format("{}", v3) << '\n'; // 110 km/h
|
||||
std::cout << STD_FMT::format("{:*^14}", v4) << '\n'; // ***70 mi/h****
|
||||
std::cout << STD_FMT::format("{:%Q in %q}", v5) << '\n'; // 30.5556 in m/s
|
||||
std::cout << STD_FMT::format("{0:%Q} in {0:%q}", v6) << '\n'; // 31.2928 in m/s
|
||||
std::cout << STD_FMT::format("{:%Q}", v7) << '\n'; // 31
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@
|
||||
namespace kalman {
|
||||
|
||||
template<typename T>
|
||||
concept QuantityOrQuantityPoint = units::Quantity<T> || units::QuantityPoint<T>; // TODO Should it also account for `kinds`?
|
||||
concept QuantityOrQuantityPoint =
|
||||
units::Quantity<T> || units::QuantityPoint<T>; // TODO Should it also account for `kinds`?
|
||||
|
||||
template<typename... Qs>
|
||||
inline constexpr bool are_derivatives = false;
|
||||
@@ -44,34 +45,42 @@ inline constexpr bool are_derivatives<Q> = true;
|
||||
|
||||
template<typename Q1, typename Q2, typename... Qs>
|
||||
inline constexpr bool are_derivatives<Q1, Q2, Qs...> =
|
||||
units::DimensionOfT<typename decltype(Q1::reference / Q2::reference)::dimension, units::isq::dim_time> && // TODO Think on how to simplify this
|
||||
units::DimensionOfT<typename decltype(Q1::reference / Q2::reference)::dimension,
|
||||
units::isq::dim_time> && // TODO Think on how to simplify this
|
||||
are_derivatives<Q2, Qs...>;
|
||||
|
||||
// state
|
||||
template<QuantityOrQuantityPoint... QQPs>
|
||||
requires (sizeof...(QQPs) > 0) && (sizeof...(QQPs) <= 3) && are_derivatives<QQPs...>
|
||||
requires(sizeof...(QQPs) > 0) && (sizeof...(QQPs) <= 3) && are_derivatives<QQPs...>
|
||||
struct state {
|
||||
std::tuple<QQPs...> variables_;
|
||||
constexpr state(QQPs... qqps): variables_(std::move(qqps)...) {}
|
||||
constexpr state(QQPs... qqps) : variables_(std::move(qqps)...) {}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
concept State = units::is_specialization_of<T, state>;
|
||||
|
||||
template<std::size_t Idx, typename... Qs>
|
||||
constexpr auto& get(state<Qs...>& s) { return get<Idx>(s.variables_); }
|
||||
constexpr auto& get(state<Qs...>& s)
|
||||
{
|
||||
return get<Idx>(s.variables_);
|
||||
}
|
||||
|
||||
template<std::size_t Idx, typename... Qs>
|
||||
constexpr const auto& get(const state<Qs...>& s) { return get<Idx>(s.variables_); }
|
||||
constexpr const auto& get(const state<Qs...>& s)
|
||||
{
|
||||
return get<Idx>(s.variables_);
|
||||
}
|
||||
|
||||
// estimation
|
||||
template<QuantityOrQuantityPoint QQP, QuantityOrQuantityPoint... QQPs>
|
||||
struct estimation {
|
||||
private:
|
||||
using uncertainty_ref = decltype(QQP::reference * QQP::reference);
|
||||
using uncertainty_type = units::quantity<typename uncertainty_ref::dimension, typename uncertainty_ref::unit, typename QQP::rep>;
|
||||
using uncertainty_type =
|
||||
units::quantity<typename uncertainty_ref::dimension, typename uncertainty_ref::unit, typename QQP::rep>;
|
||||
public:
|
||||
kalman::state<QQP, QQPs...> state; // TODO extend kalman functions to work with this variadic patermater list
|
||||
kalman::state<QQP, QQPs...> state; // TODO extend kalman functions to work with this variadic patermater list
|
||||
uncertainty_type uncertainty;
|
||||
};
|
||||
|
||||
@@ -94,7 +103,7 @@ template<typename Q, QuantityOrQuantityPoint QM, units::Dimensionless K>
|
||||
requires units::equivalent<typename Q::dimension, typename QM::dimension>
|
||||
constexpr state<Q> state_update(const state<Q>& predicted, QM measured, K gain)
|
||||
{
|
||||
return { get<0>(predicted) + gain * (measured - get<0>(predicted)) };
|
||||
return {get<0>(predicted) + gain * (measured - get<0>(predicted))};
|
||||
}
|
||||
|
||||
template<typename Q1, typename Q2, QuantityOrQuantityPoint QM, units::Dimensionless K, units::isq::Time T>
|
||||
@@ -103,17 +112,18 @@ constexpr state<Q1, Q2> state_update(const state<Q1, Q2>& predicted, QM measured
|
||||
{
|
||||
const auto q1 = get<0>(predicted) + get<0>(gain) * (measured - get<0>(predicted));
|
||||
const auto q2 = get<1>(predicted) + get<1>(gain) * (measured - get<0>(predicted)) / interval;
|
||||
return { q1, q2 };
|
||||
return {q1, q2};
|
||||
}
|
||||
|
||||
template<typename Q1, typename Q2, typename Q3, QuantityOrQuantityPoint QM, units::Dimensionless K, units::isq::Time T>
|
||||
requires units::equivalent<typename Q1::dimension, typename QM::dimension>
|
||||
constexpr state<Q1, Q2, Q3> state_update(const state<Q1, Q2, Q3>& predicted, QM measured, std::array<K, 3> gain, T interval)
|
||||
constexpr state<Q1, Q2, Q3> state_update(const state<Q1, Q2, Q3>& predicted, QM measured, std::array<K, 3> gain,
|
||||
T interval)
|
||||
{
|
||||
const auto q1 = get<0>(predicted) + get<0>(gain) * (measured - get<0>(predicted));
|
||||
const auto q2 = get<1>(predicted) + get<1>(gain) * (measured - get<0>(predicted)) / interval;
|
||||
const auto q3 = get<2>(predicted) + get<2>(gain) * (measured - get<0>(predicted)) / (interval * interval / 2);
|
||||
return { q1, q2, q3 };
|
||||
return {q1, q2, q3};
|
||||
}
|
||||
|
||||
// covariance update
|
||||
@@ -129,7 +139,7 @@ constexpr state<Q1, Q2> state_extrapolation(const state<Q1, Q2>& estimated, T in
|
||||
{
|
||||
const auto q1 = get<0>(estimated) + get<1>(estimated) * interval;
|
||||
const auto q2 = get<1>(estimated);
|
||||
return { q1, q2 };
|
||||
return {q1, q2};
|
||||
}
|
||||
|
||||
template<typename Q1, typename Q2, typename Q3, units::isq::Time T>
|
||||
@@ -138,7 +148,7 @@ constexpr state<Q1, Q2, Q3> state_extrapolation(const state<Q1, Q2, Q3>& estimat
|
||||
const auto q1 = get<0>(estimated) + get<1>(estimated) * interval + get<2>(estimated) * pow<2>(interval) / 2;
|
||||
const auto q2 = get<1>(estimated) + get<2>(estimated) * interval;
|
||||
const auto q3 = get<2>(estimated);
|
||||
return { q1, q2, q3 };
|
||||
return {q1, q2, q3};
|
||||
}
|
||||
|
||||
// covariance extrapolation
|
||||
@@ -164,24 +174,26 @@ struct STD_FMT::formatter<kalman::state<Qs...>> {
|
||||
std::string value_buffer;
|
||||
auto to_value_buffer = std::back_inserter(value_buffer);
|
||||
if (specs.precision != -1) {
|
||||
if constexpr(sizeof...(Qs) == 1)
|
||||
if constexpr (sizeof...(Qs) == 1)
|
||||
STD_FMT::format_to(to_value_buffer, "{1:%.{0}Q %q}", specs.precision, kalman::get<0>(s));
|
||||
else if constexpr(sizeof...(Qs) == 2)
|
||||
STD_FMT::format_to(to_value_buffer, "{{ {1:%.{0}Q %q}, {2:%.{0}Q %q} }}", specs.precision, kalman::get<0>(s), kalman::get<1>(s));
|
||||
else if constexpr (sizeof...(Qs) == 2)
|
||||
STD_FMT::format_to(to_value_buffer, "{{ {1:%.{0}Q %q}, {2:%.{0}Q %q} }}", specs.precision, kalman::get<0>(s),
|
||||
kalman::get<1>(s));
|
||||
else
|
||||
STD_FMT::format_to(to_value_buffer, "{{ {1:%.{0}Q %q}, {2:%.{0}Q %q}, {3:%.{0}Q %q} }}", specs.precision, kalman::get<0>(s), kalman::get<1>(s), kalman::get<2>(s));
|
||||
}
|
||||
else {
|
||||
if constexpr(sizeof...(Qs) == 1)
|
||||
STD_FMT::format_to(to_value_buffer, "{{ {1:%.{0}Q %q}, {2:%.{0}Q %q}, {3:%.{0}Q %q} }}", specs.precision,
|
||||
kalman::get<0>(s), kalman::get<1>(s), kalman::get<2>(s));
|
||||
} else {
|
||||
if constexpr (sizeof...(Qs) == 1)
|
||||
STD_FMT::format_to(to_value_buffer, "{}", kalman::get<0>(s));
|
||||
else if constexpr(sizeof...(Qs) == 2)
|
||||
else if constexpr (sizeof...(Qs) == 2)
|
||||
STD_FMT::format_to(to_value_buffer, "{{ {}, {} }}", kalman::get<0>(s), kalman::get<1>(s));
|
||||
else
|
||||
STD_FMT::format_to(to_value_buffer, "{{ {}, {}, {} }}", kalman::get<0>(s), kalman::get<1>(s), kalman::get<2>(s));
|
||||
STD_FMT::format_to(to_value_buffer, "{{ {}, {}, {} }}", kalman::get<0>(s), kalman::get<1>(s),
|
||||
kalman::get<2>(s));
|
||||
}
|
||||
|
||||
std::string global_format_buffer;
|
||||
units::detail::quantity_global_format_specs<char> global_specs = { specs.fill, specs.align, specs.width };
|
||||
units::detail::quantity_global_format_specs<char> global_specs = {specs.fill, specs.align, specs.width};
|
||||
units::detail::format_global_buffer(std::back_inserter(global_format_buffer), global_specs);
|
||||
|
||||
return STD_FMT::vformat_to(ctx.out(), global_format_buffer, STD_FMT::make_format_args(value_buffer));
|
||||
@@ -202,7 +214,7 @@ struct STD_FMT::formatter<kalman::estimation<Q>> {
|
||||
auto format(kalman::estimation<Q> e, FormatContext& ctx)
|
||||
{
|
||||
units::Quantity auto q = [](const Q& t) {
|
||||
if constexpr(units::Quantity<Q>)
|
||||
if constexpr (units::Quantity<Q>)
|
||||
return t;
|
||||
else
|
||||
return t.relative();
|
||||
@@ -212,13 +224,12 @@ struct STD_FMT::formatter<kalman::estimation<Q>> {
|
||||
auto to_value_buffer = std::back_inserter(value_buffer);
|
||||
if (specs.precision != -1) {
|
||||
STD_FMT::format_to(to_value_buffer, "{0:%.{2}Q} ± {1:%.{2}Q} {0:%q}", q, sqrt(e.uncertainty), specs.precision);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
STD_FMT::format_to(to_value_buffer, "{0:%Q} ± {1:%Q} {0:%q}", q, sqrt(e.uncertainty));
|
||||
}
|
||||
|
||||
std::string global_format_buffer;
|
||||
units::detail::quantity_global_format_specs<char> global_specs = { specs.fill, specs.align, specs.width };
|
||||
units::detail::quantity_global_format_specs<char> global_specs = {specs.fill, specs.align, specs.width};
|
||||
units::detail::format_global_buffer(std::back_inserter(global_format_buffer), global_specs);
|
||||
|
||||
return STD_FMT::vformat_to(ctx.out(), global_format_buffer, STD_FMT::make_format_args(value_buffer));
|
||||
|
||||
@@ -21,9 +21,9 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/isq/si/mass.h>
|
||||
#include <units/format.h>
|
||||
#include <units/generic/dimensionless.h>
|
||||
#include <units/isq/si/mass.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
@@ -34,10 +34,12 @@ using namespace units;
|
||||
void print_header(const kalman::State auto& initial)
|
||||
{
|
||||
std::cout << STD_FMT::format("Initial: {}\n", initial);
|
||||
std::cout << STD_FMT::format("{:>2} | {:>9} | {:>8} | {:>14} | {:>14}\n", "N", "Gain", "Measured", "Curr. Estimate", "Next Estimate");
|
||||
std::cout << STD_FMT::format("{:>2} | {:>9} | {:>8} | {:>14} | {:>14}\n", "N", "Gain", "Measured", "Curr. Estimate",
|
||||
"Next Estimate");
|
||||
}
|
||||
|
||||
void print(auto iteration, Dimensionless auto gain, Quantity auto measured, const kalman::State auto& current, const kalman::State auto& next)
|
||||
void print(auto iteration, Dimensionless auto gain, Quantity auto measured, const kalman::State auto& current,
|
||||
const kalman::State auto& next)
|
||||
{
|
||||
std::cout << STD_FMT::format("{:2} | {:9} | {:8} | {:14} | {:14}\n", iteration, gain, measured, current, next);
|
||||
}
|
||||
@@ -48,13 +50,13 @@ int main()
|
||||
using namespace units::isq::si::references;
|
||||
using state = kalman::state<si::mass<si::gram>>;
|
||||
|
||||
const state initial = { 1 * kg };
|
||||
const std::array measurements = { 1030 * g, 989 * g, 1017 * g, 1009 * g, 1013 * g,
|
||||
979 * g, 1008 * g, 1042 * g, 1012 * g, 1011 * g };
|
||||
const state initial = {1 * kg};
|
||||
const std::array measurements = {1030 * g, 989 * g, 1017 * g, 1009 * g, 1013 * g,
|
||||
979 * g, 1008 * g, 1042 * g, 1012 * g, 1011 * g};
|
||||
|
||||
print_header(initial);
|
||||
state next = initial;
|
||||
for(int index = 1; const auto& m : measurements) {
|
||||
for (int index = 1; const auto& m : measurements) {
|
||||
const auto& previous = next;
|
||||
const dimensionless<one> gain = 1. / index;
|
||||
const auto current = state_update(previous, m, gain);
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/format.h>
|
||||
#include <units/generic/dimensionless.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/speed.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/format.h>
|
||||
#include <units/generic/dimensionless.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
@@ -51,14 +51,14 @@ int main()
|
||||
using state = kalman::state<si::length<si::metre>, si::speed<si::metre_per_second>>;
|
||||
|
||||
const auto interval = 5 * s;
|
||||
const state initial = { 30 * km, 40 * (m / s) };
|
||||
const std::array measurements = { 30110 * m, 30265 * m, 30740 * m, 30750 * m, 31135 * m,
|
||||
31015 * m, 31180 * m, 31610 * m, 31960 * m, 31865 * m };
|
||||
const state initial = {30 * km, 40 * (m / s)};
|
||||
const std::array measurements = {30110 * m, 30265 * m, 30740 * m, 30750 * m, 31135 * m,
|
||||
31015 * m, 31180 * m, 31610 * m, 31960 * m, 31865 * m};
|
||||
std::array gain = {dimensionless<one>(0.2), dimensionless<one>(0.1)};
|
||||
|
||||
print_header(initial);
|
||||
state next = state_extrapolation(initial, interval);
|
||||
for(int index = 1; const auto& measured : measurements) {
|
||||
for (int index = 1; const auto& measured : measurements) {
|
||||
const auto& previous = next;
|
||||
const auto current = state_update(previous, measured, gain, interval);
|
||||
next = state_extrapolation(current, interval);
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/format.h>
|
||||
#include <units/generic/dimensionless.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/speed.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/format.h>
|
||||
#include <units/generic/dimensionless.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
@@ -51,14 +51,14 @@ int main()
|
||||
using state = kalman::state<si::length<si::metre>, si::speed<si::metre_per_second>>;
|
||||
|
||||
const auto interval = 5 * s;
|
||||
const state initial = { 30 * km, 50 * (m / s) };
|
||||
const std::array measurements = { 30160 * m, 30365 * m, 30890 * m, 31050 * m, 31785 * m,
|
||||
32215 * m, 33130 * m, 34510 * m, 36010 * m, 37265 * m };
|
||||
const state initial = {30 * km, 50 * (m / s)};
|
||||
const std::array measurements = {30160 * m, 30365 * m, 30890 * m, 31050 * m, 31785 * m,
|
||||
32215 * m, 33130 * m, 34510 * m, 36010 * m, 37265 * m};
|
||||
std::array gain = {dimensionless<one>(0.2), dimensionless<one>(0.1)};
|
||||
|
||||
print_header(initial);
|
||||
state next = state_extrapolation(initial, interval);
|
||||
for(int index = 1; const auto& measured : measurements) {
|
||||
for (int index = 1; const auto& measured : measurements) {
|
||||
const auto& previous = next;
|
||||
const auto current = state_update(previous, measured, gain, interval);
|
||||
next = state_extrapolation(current, interval);
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/format.h>
|
||||
#include <units/generic/dimensionless.h>
|
||||
#include <units/isq/si/acceleration.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/speed.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/format.h>
|
||||
#include <units/generic/dimensionless.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
@@ -49,19 +49,20 @@ int main()
|
||||
{
|
||||
using namespace units::isq;
|
||||
using namespace units::isq::si::references;
|
||||
using state = kalman::state<si::length<si::metre>, si::speed<si::metre_per_second>, si::acceleration<si::metre_per_second_sq>>;
|
||||
using state =
|
||||
kalman::state<si::length<si::metre>, si::speed<si::metre_per_second>, si::acceleration<si::metre_per_second_sq>>;
|
||||
constexpr auto mps = m / s;
|
||||
constexpr auto mps2 = mps / s;
|
||||
|
||||
const auto interval = 5. * s;
|
||||
const state initial = { 30 * km, 50 * mps, 0 * mps2 };
|
||||
const std::array measurements = { 30160 * m, 30365 * m, 30890 * m, 31050 * m, 31785 * m,
|
||||
32215 * m, 33130 * m, 34510 * m, 36010 * m, 37265 * m };
|
||||
const state initial = {30 * km, 50 * mps, 0 * mps2};
|
||||
const std::array measurements = {30160 * m, 30365 * m, 30890 * m, 31050 * m, 31785 * m,
|
||||
32215 * m, 33130 * m, 34510 * m, 36010 * m, 37265 * m};
|
||||
std::array gain = {dimensionless<one>(0.5), dimensionless<one>(0.4), dimensionless<one>(0.1)};
|
||||
|
||||
print_header(initial);
|
||||
state next = state_extrapolation(initial, interval);
|
||||
for(int index = 1; const auto& measured : measurements) {
|
||||
for (int index = 1; const auto& measured : measurements) {
|
||||
const auto& previous = next;
|
||||
const auto current = state_update(previous, measured, gain, interval);
|
||||
next = state_extrapolation(current, interval);
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/math.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
@@ -35,13 +35,15 @@ template<Quantity Q>
|
||||
void print_header(kalman::estimation<Q> initial)
|
||||
{
|
||||
std::cout << STD_FMT::format("Initial: {}\n", initial);
|
||||
std::cout << STD_FMT::format("{:>2} | {:>5} | {:>8} | {:>16} | {:>16}\n", "N", "Gain", "Measured", "Curr. Estimate", "Next Estimate");
|
||||
std::cout << STD_FMT::format("{:>2} | {:>5} | {:>8} | {:>16} | {:>16}\n", "N", "Gain", "Measured", "Curr. Estimate",
|
||||
"Next Estimate");
|
||||
}
|
||||
|
||||
template<Quantity Q, Dimensionless K>
|
||||
void print(auto iteration, K gain, Q measured, kalman::estimation<Q> current, kalman::estimation<Q> next)
|
||||
{
|
||||
std::cout << STD_FMT::format("{:2} | {:5%.2Q} | {:8} | {:>16.2} | {:>16.2}\n", iteration, gain, measured, current, next);
|
||||
std::cout << STD_FMT::format("{:2} | {:5%.2Q} | {:8} | {:>16.2} | {:>16.2}\n", iteration, gain, measured, current,
|
||||
next);
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -50,20 +52,20 @@ int main()
|
||||
using namespace units::isq;
|
||||
using namespace units::isq::si::references;
|
||||
|
||||
const estimation initial = { state{ 60. * m }, pow<2>(15. * m) };
|
||||
const std::array measurements = { 48.54 * m, 47.11 * m, 55.01 * m, 55.15 * m, 49.89 * m,
|
||||
40.85 * m, 46.72 * m, 50.05 * m, 51.27 * m, 49.95 * m };
|
||||
const estimation initial = {state{60. * m}, pow<2>(15. * m)};
|
||||
const std::array measurements = {48.54 * m, 47.11 * m, 55.01 * m, 55.15 * m, 49.89 * m,
|
||||
40.85 * m, 46.72 * m, 50.05 * m, 51.27 * m, 49.95 * m};
|
||||
const auto measurement_uncertainty = pow<2>(5. * m);
|
||||
|
||||
auto update = [=]<Quantity Q>(const estimation<Q>& previous, const Q& meassurement, Dimensionless auto gain) {
|
||||
return estimation{ state_update(previous.state, meassurement, gain), covariance_update(previous.uncertainty, gain) };
|
||||
return estimation{state_update(previous.state, meassurement, gain), covariance_update(previous.uncertainty, gain)};
|
||||
};
|
||||
|
||||
auto predict = []<Quantity Q>(const estimation<Q>& current) { return current; };
|
||||
|
||||
print_header(initial);
|
||||
estimation next = predict(initial);
|
||||
for(int index = 1; const auto& measured : measurements) {
|
||||
for (int index = 1; const auto& measured : measurements) {
|
||||
const auto& previous = next;
|
||||
const auto gain = kalman_gain(previous.uncertainty, measurement_uncertainty);
|
||||
const estimation current = update(previous, measured, gain);
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/isq/si/thermodynamic_temperature.h>
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/thermodynamic_temperature.h>
|
||||
#include <units/math.h>
|
||||
#include <units/quantity_point.h>
|
||||
#include <units/unit.h>
|
||||
@@ -56,13 +56,15 @@ template<QuantityPoint QP>
|
||||
void print_header(kalman::estimation<QP> initial)
|
||||
{
|
||||
std::cout << STD_FMT::format("Initial: {}\n", initial);
|
||||
std::cout << STD_FMT::format("{:>2} | {:>7} | {:>10} | {:>18} | {:>18}\n", "N", "Gain", "Measured", "Curr. Estimate", "Next Estimate");
|
||||
std::cout << STD_FMT::format("{:>2} | {:>7} | {:>10} | {:>18} | {:>18}\n", "N", "Gain", "Measured", "Curr. Estimate",
|
||||
"Next Estimate");
|
||||
}
|
||||
|
||||
template<QuantityPoint QP, Dimensionless K>
|
||||
void print(auto iteration, K gain, QP measured, kalman::estimation<QP> current, kalman::estimation<QP> next)
|
||||
{
|
||||
std::cout << STD_FMT::format("{:2} | {:7%.4Q} | {:10%.3Q %q} | {:>18.3} | {:>18.3}\n", iteration, gain, measured.relative(), current, next);
|
||||
std::cout << STD_FMT::format("{:2} | {:7%.4Q} | {:10%.3Q %q} | {:>18.3} | {:>18.3}\n", iteration, gain,
|
||||
measured.relative(), current, next);
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -72,32 +74,25 @@ int main()
|
||||
using namespace units::isq::si::references;
|
||||
|
||||
const auto process_noise_variance = 0.0001 * (deg_C * deg_C);
|
||||
const estimation initial = { state{ quantity_point(10. * deg_C) }, pow<2>(100. * deg_C) };
|
||||
const std::array measurements = {
|
||||
quantity_point(49.95 * deg_C),
|
||||
quantity_point(49.967 * deg_C),
|
||||
quantity_point(50.1 * deg_C),
|
||||
quantity_point(50.106 * deg_C),
|
||||
quantity_point(49.992 * deg_C),
|
||||
quantity_point(49.819 * deg_C),
|
||||
quantity_point(49.933 * deg_C),
|
||||
quantity_point(50.007 * deg_C),
|
||||
quantity_point(50.023 * deg_C),
|
||||
quantity_point(49.99 * deg_C)
|
||||
};
|
||||
const estimation initial = {state{quantity_point(10. * deg_C)}, pow<2>(100. * deg_C)};
|
||||
const std::array measurements = {quantity_point(49.95 * deg_C), quantity_point(49.967 * deg_C),
|
||||
quantity_point(50.1 * deg_C), quantity_point(50.106 * deg_C),
|
||||
quantity_point(49.992 * deg_C), quantity_point(49.819 * deg_C),
|
||||
quantity_point(49.933 * deg_C), quantity_point(50.007 * deg_C),
|
||||
quantity_point(50.023 * deg_C), quantity_point(49.99 * deg_C)};
|
||||
const auto measurement_uncertainty = pow<2>(0.1 * deg_C);
|
||||
|
||||
auto update = [=]<QuantityPoint QP>(const estimation<QP>& previous, const QP& meassurement, Dimensionless auto gain) {
|
||||
return estimation{ state_update(previous.state, meassurement, gain), covariance_update(previous.uncertainty, gain) };
|
||||
return estimation{state_update(previous.state, meassurement, gain), covariance_update(previous.uncertainty, gain)};
|
||||
};
|
||||
|
||||
auto predict = [=]<QuantityPoint QP>(const estimation<QP>& current) {
|
||||
return estimation{ current.state, covariance_extrapolation(current.uncertainty, process_noise_variance) };
|
||||
return estimation{current.state, covariance_extrapolation(current.uncertainty, process_noise_variance)};
|
||||
};
|
||||
|
||||
print_header(initial);
|
||||
estimation next = predict(initial);
|
||||
for(int index = 1; const auto& m : measurements) {
|
||||
for (int index = 1; const auto& m : measurements) {
|
||||
const auto& previous = next;
|
||||
const auto gain = kalman_gain(previous.uncertainty, measurement_uncertainty);
|
||||
const estimation current = update(previous, m, gain);
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/isq/si/thermodynamic_temperature.h>
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/thermodynamic_temperature.h>
|
||||
#include <units/math.h>
|
||||
#include <units/quantity_point.h>
|
||||
#include <units/unit.h>
|
||||
@@ -56,13 +56,15 @@ template<QuantityPoint QP>
|
||||
void print_header(kalman::estimation<QP> initial)
|
||||
{
|
||||
std::cout << STD_FMT::format("Initial: {}\n", initial);
|
||||
std::cout << STD_FMT::format("{:>2} | {:>7} | {:>10} | {:>18} | {:>18}\n", "N", "Gain", "Measured", "Curr. Estimate", "Next Estimate");
|
||||
std::cout << STD_FMT::format("{:>2} | {:>7} | {:>10} | {:>18} | {:>18}\n", "N", "Gain", "Measured", "Curr. Estimate",
|
||||
"Next Estimate");
|
||||
}
|
||||
|
||||
template<QuantityPoint QP, Dimensionless K>
|
||||
void print(auto iteration, K gain, QP measured, kalman::estimation<QP> current, kalman::estimation<QP> next)
|
||||
{
|
||||
std::cout << STD_FMT::format("{:2} | {:7%.4Q} | {:10%.3Q %q} | {:>18.3} | {:>18.3}\n", iteration, gain, measured.relative(), current, next);
|
||||
std::cout << STD_FMT::format("{:2} | {:7%.4Q} | {:10%.3Q %q} | {:>18.3} | {:>18.3}\n", iteration, gain,
|
||||
measured.relative(), current, next);
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -72,32 +74,25 @@ int main()
|
||||
using namespace units::isq::si::references;
|
||||
|
||||
const auto process_noise_variance = 0.0001 * (deg_C * deg_C);
|
||||
const estimation initial = { state{ quantity_point(10. * deg_C) }, pow<2>(100. * deg_C) };
|
||||
const std::array measurements = {
|
||||
quantity_point(50.45 * deg_C),
|
||||
quantity_point(50.967 * deg_C),
|
||||
quantity_point(51.6 * deg_C),
|
||||
quantity_point(52.106 * deg_C),
|
||||
quantity_point(52.492 * deg_C),
|
||||
quantity_point(52.819 * deg_C),
|
||||
quantity_point(53.433 * deg_C),
|
||||
quantity_point(54.007 * deg_C),
|
||||
quantity_point(54.523 * deg_C),
|
||||
quantity_point(54.99 * deg_C)
|
||||
};
|
||||
const estimation initial = {state{quantity_point(10. * deg_C)}, pow<2>(100. * deg_C)};
|
||||
const std::array measurements = {quantity_point(50.45 * deg_C), quantity_point(50.967 * deg_C),
|
||||
quantity_point(51.6 * deg_C), quantity_point(52.106 * deg_C),
|
||||
quantity_point(52.492 * deg_C), quantity_point(52.819 * deg_C),
|
||||
quantity_point(53.433 * deg_C), quantity_point(54.007 * deg_C),
|
||||
quantity_point(54.523 * deg_C), quantity_point(54.99 * deg_C)};
|
||||
const auto measurement_uncertainty = pow<2>(0.1 * deg_C);
|
||||
|
||||
auto update = [=]<QuantityPoint QP>(const estimation<QP>& previous, const QP& meassurement, Dimensionless auto gain) {
|
||||
return estimation{ state_update(previous.state, meassurement, gain), covariance_update(previous.uncertainty, gain) };
|
||||
return estimation{state_update(previous.state, meassurement, gain), covariance_update(previous.uncertainty, gain)};
|
||||
};
|
||||
|
||||
auto predict = [=]<QuantityPoint QP>(const estimation<QP>& current) {
|
||||
return estimation{ current.state, covariance_extrapolation(current.uncertainty, process_noise_variance) };
|
||||
return estimation{current.state, covariance_extrapolation(current.uncertainty, process_noise_variance)};
|
||||
};
|
||||
|
||||
print_header(initial);
|
||||
estimation next = predict(initial);
|
||||
for(int index = 1; const auto& m : measurements) {
|
||||
for (int index = 1; const auto& m : measurements) {
|
||||
const auto& previous = next;
|
||||
const auto gain = kalman_gain(previous.uncertainty, measurement_uncertainty);
|
||||
const estimation current = update(previous, m, gain);
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/isq/si/thermodynamic_temperature.h>
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/thermodynamic_temperature.h>
|
||||
#include <units/math.h>
|
||||
#include <units/quantity_point.h>
|
||||
#include <units/unit.h>
|
||||
@@ -56,13 +56,15 @@ template<QuantityPoint QP>
|
||||
void print_header(kalman::estimation<QP> initial)
|
||||
{
|
||||
std::cout << STD_FMT::format("Initial: {}\n", initial);
|
||||
std::cout << STD_FMT::format("{:>2} | {:>7} | {:>10} | {:>16} | {:>16}\n", "N", "Gain", "Measured", "Curr. Estimate", "Next Estimate");
|
||||
std::cout << STD_FMT::format("{:>2} | {:>7} | {:>10} | {:>16} | {:>16}\n", "N", "Gain", "Measured", "Curr. Estimate",
|
||||
"Next Estimate");
|
||||
}
|
||||
|
||||
template<QuantityPoint QP, Dimensionless K>
|
||||
void print(auto iteration, K gain, QP measured, kalman::estimation<QP> current, kalman::estimation<QP> next)
|
||||
{
|
||||
std::cout << STD_FMT::format("{:2} | {:7%.3Q} | {:10%.3Q %q} | {:>16.2} | {:>16.2}\n", iteration, gain, measured.relative(), current, next);
|
||||
std::cout << STD_FMT::format("{:2} | {:7%.3Q} | {:10%.3Q %q} | {:>16.2} | {:>16.2}\n", iteration, gain,
|
||||
measured.relative(), current, next);
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -72,32 +74,25 @@ int main()
|
||||
using namespace units::isq::si::references;
|
||||
|
||||
const auto process_noise_variance = 0.15 * (deg_C * deg_C);
|
||||
const estimation initial = { state{ quantity_point(10. * deg_C) }, pow<2>(100. * deg_C) };
|
||||
const std::array measurements = {
|
||||
quantity_point(50.45 * deg_C),
|
||||
quantity_point(50.967 * deg_C),
|
||||
quantity_point(51.6 * deg_C),
|
||||
quantity_point(52.106 * deg_C),
|
||||
quantity_point(52.492 * deg_C),
|
||||
quantity_point(52.819 * deg_C),
|
||||
quantity_point(53.433 * deg_C),
|
||||
quantity_point(54.007 * deg_C),
|
||||
quantity_point(54.523 * deg_C),
|
||||
quantity_point(54.99 * deg_C)
|
||||
};
|
||||
const estimation initial = {state{quantity_point(10. * deg_C)}, pow<2>(100. * deg_C)};
|
||||
const std::array measurements = {quantity_point(50.45 * deg_C), quantity_point(50.967 * deg_C),
|
||||
quantity_point(51.6 * deg_C), quantity_point(52.106 * deg_C),
|
||||
quantity_point(52.492 * deg_C), quantity_point(52.819 * deg_C),
|
||||
quantity_point(53.433 * deg_C), quantity_point(54.007 * deg_C),
|
||||
quantity_point(54.523 * deg_C), quantity_point(54.99 * deg_C)};
|
||||
const auto measurement_uncertainty = pow<2>(0.1 * deg_C);
|
||||
|
||||
auto update = [=]<QuantityPoint QP>(const estimation<QP>& previous, const QP& meassurement, Dimensionless auto gain) {
|
||||
return estimation{ state_update(previous.state, meassurement, gain), covariance_update(previous.uncertainty, gain) };
|
||||
return estimation{state_update(previous.state, meassurement, gain), covariance_update(previous.uncertainty, gain)};
|
||||
};
|
||||
|
||||
auto predict = [=]<QuantityPoint QP>(const estimation<QP>& current) {
|
||||
return estimation{ current.state, covariance_extrapolation(current.uncertainty, process_noise_variance) };
|
||||
return estimation{current.state, covariance_extrapolation(current.uncertainty, process_noise_variance)};
|
||||
};
|
||||
|
||||
print_header(initial);
|
||||
estimation next = predict(initial);
|
||||
for(int index = 1; const auto& m : measurements) {
|
||||
for (int index = 1; const auto& m : measurements) {
|
||||
const auto& previous = next;
|
||||
const auto gain = kalman_gain(previous.uncertainty, measurement_uncertainty);
|
||||
const estimation current = update(previous, m, gain);
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/si/cgs/length.h>
|
||||
#include <units/isq/si/cgs/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/cgs/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/international/length.h>
|
||||
#include <units/isq/si/international/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/length.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/international/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/length.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@@ -35,38 +35,31 @@ namespace {
|
||||
|
||||
using namespace units::isq;
|
||||
|
||||
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)
|
||||
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::speed<si::metre_per_second>
|
||||
fixed_double_si_avg_speed(si::length<si::metre> d,
|
||||
si::time<si::second> t)
|
||||
constexpr si::speed<si::metre_per_second> fixed_double_si_avg_speed(si::length<si::metre> d, si::time<si::second> t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
|
||||
template<typename U1, typename R1, typename U2, typename R2>
|
||||
constexpr Speed auto si_avg_speed(si::length<U1, R1> d,
|
||||
si::time<U2, R2> t)
|
||||
constexpr Speed auto si_avg_speed(si::length<U1, R1> d, si::time<U2, R2> t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
|
||||
constexpr Speed auto avg_speed(Length auto d, Time auto t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
constexpr Speed auto avg_speed(Length auto d, Time auto t) { return d / t; }
|
||||
|
||||
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::speed<si::kilometre_per_hour>>(speed);
|
||||
std::cout << "Average speed of a car that makes " << distance << " in "
|
||||
<< duration << " is " << result_in_kmph << ".\n";
|
||||
std::cout << "Average speed of a car that makes " << distance << " in " << duration << " is " << result_in_kmph
|
||||
<< ".\n";
|
||||
}
|
||||
|
||||
void example()
|
||||
@@ -94,7 +87,8 @@ void example()
|
||||
std::cout << "\nSI units with 'double' as representation\n";
|
||||
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<int>(distance), quantity_cast<int>(duration)));
|
||||
print_result(distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<int>(distance), quantity_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, si_avg_speed(distance, duration));
|
||||
@@ -130,7 +124,9 @@ void example()
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
// also it is not possible to make a lossless conversion of miles to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
print_result(
|
||||
distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, si_avg_speed(distance, duration));
|
||||
@@ -141,7 +137,7 @@ void example()
|
||||
{
|
||||
using namespace units::isq::si::cgs::literals;
|
||||
constexpr auto distance = 22'000'000_q_cm;
|
||||
constexpr si::cgs::time<si::hour, int> duration(2); // cannot use an SI literal here
|
||||
constexpr si::cgs::time<si::hour, int> duration(2); // cannot use an SI literal here
|
||||
|
||||
std::cout << "\nCGS units with 'int' as representation\n";
|
||||
|
||||
@@ -160,14 +156,16 @@ void example()
|
||||
{
|
||||
using namespace units::isq::si::cgs::literals;
|
||||
constexpr auto distance = 22'000'000._q_cm;
|
||||
constexpr si::cgs::time<si::hour, double> duration(2); // cannot use an SI literal here
|
||||
constexpr si::cgs::time<si::hour, double> duration(2); // cannot use an SI literal here
|
||||
|
||||
std::cout << "\nCGS units with 'double' as representation\n";
|
||||
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
// it is not possible to make a lossless conversion of centimeters to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
print_result(
|
||||
distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
|
||||
@@ -176,20 +174,17 @@ void example()
|
||||
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
example();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unhandled unknown exception caught\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <units/isq/si/force.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/mass.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/volume.h>
|
||||
#include <cassert>
|
||||
@@ -56,7 +56,10 @@ class Box {
|
||||
si::length<m> height_;
|
||||
si::density<kgpm3> density_ = air_density;
|
||||
public:
|
||||
constexpr Box(const si::length<m>& length, const si::length<m>& width, si::length<m> height) : base_(length * width), height_(std::move(height)) {}
|
||||
constexpr Box(const si::length<m>& length, const si::length<m>& width, si::length<m> height) :
|
||||
base_(length * width), height_(std::move(height))
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr si::force<N> filled_weight() const
|
||||
{
|
||||
@@ -94,13 +97,13 @@ int main()
|
||||
auto box = Box(1000.0_q_mm, 500.0_q_mm, height);
|
||||
box.set_contents_density(1000.0_q_kg_per_m3);
|
||||
|
||||
const auto fill_time = 200.0_q_s; // time since starting fill
|
||||
const auto measured_mass = 20.0_q_kg; // measured mass at fill_time
|
||||
const auto fill_time = 200.0_q_s; // time since starting fill
|
||||
const auto measured_mass = 20.0_q_kg; // measured mass at fill_time
|
||||
|
||||
const Length auto fill_level = box.fill_level(measured_mass);
|
||||
const Dimensionless auto fill_percent = quantity_cast<percent>(fill_level / height);
|
||||
const Volume auto spare_capacity = box.spare_capacity(measured_mass);
|
||||
const auto input_flow_rate = measured_mass / fill_time; // unknown dimension
|
||||
const auto input_flow_rate = measured_mass / fill_time; // unknown dimension
|
||||
const Speed auto float_rise_rate = fill_level / fill_time;
|
||||
const Time auto fill_time_left = (height / fill_level - 1) * fill_time;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <units/isq/si/resistance.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/voltage.h>
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/quantity_io.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ struct Ship {
|
||||
};
|
||||
|
||||
// Print 'a' in its current units and print its value cast to the units in each of Args
|
||||
template<class ...Args, units::Quantity Q>
|
||||
template<class... Args, units::Quantity Q>
|
||||
auto fmt_line(const Q a)
|
||||
{
|
||||
return STD_FMT::format("{:22}", a) + (STD_FMT::format(",{:20}", units::quantity_cast<Args>(a)) + ...);
|
||||
@@ -65,16 +65,27 @@ void print_details(std::string_view description, const Ship& ship)
|
||||
using namespace units::isq::si::fps::literals;
|
||||
const auto waterDensity = 62.4_q_lb_per_ft3;
|
||||
std::cout << STD_FMT::format("{}\n", description);
|
||||
std::cout << STD_FMT::format("{:20} : {}\n", "length", fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.length))
|
||||
<< STD_FMT::format("{:20} : {}\n", "draft", fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.draft))
|
||||
<< STD_FMT::format("{:20} : {}\n", "beam", fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.beam))
|
||||
<< STD_FMT::format("{:20} : {}\n", "mass", fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::tonne>>(ship.mass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "speed", fmt_line<si::fps::speed<si::fps::knot>, si::speed<si::kilometre_per_hour>>(ship.speed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "power", fmt_line<si::fps::power<si::fps::horse_power>, si::power<si::kilowatt>>(ship.power))
|
||||
<< STD_FMT::format("{:20} : {}\n", "main guns", fmt_line<si::fps::length<si::fps::inch>, si::length<si::millimetre>>(ship.mainGuns))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells weighing",fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::kilogram>>(ship.shellMass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells at",fmt_line<si::fps::speed<si::fps::mile_per_hour>, si::speed<si::kilometre_per_hour>>(ship.shellSpeed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "volume underwater", fmt_line<si::volume<si::cubic_metre>, si::volume<si::litre>>(ship.mass / waterDensity));
|
||||
std::cout << STD_FMT::format("{:20} : {}\n", "length",
|
||||
fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.length))
|
||||
<< STD_FMT::format("{:20} : {}\n", "draft",
|
||||
fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.draft))
|
||||
<< STD_FMT::format("{:20} : {}\n", "beam",
|
||||
fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.beam))
|
||||
<< STD_FMT::format("{:20} : {}\n", "mass",
|
||||
fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::tonne>>(ship.mass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "speed",
|
||||
fmt_line<si::fps::speed<si::fps::knot>, si::speed<si::kilometre_per_hour>>(ship.speed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "power",
|
||||
fmt_line<si::fps::power<si::fps::horse_power>, si::power<si::kilowatt>>(ship.power))
|
||||
<< STD_FMT::format("{:20} : {}\n", "main guns",
|
||||
fmt_line<si::fps::length<si::fps::inch>, si::length<si::millimetre>>(ship.mainGuns))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells weighing",
|
||||
fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::kilogram>>(ship.shellMass))
|
||||
<< STD_FMT::format(
|
||||
"{:20} : {}\n", "fire shells at",
|
||||
fmt_line<si::fps::speed<si::fps::mile_per_hour>, si::speed<si::kilometre_per_hour>>(ship.shellSpeed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "volume underwater",
|
||||
fmt_line<si::volume<si::cubic_metre>, si::volume<si::litre>>(ship.mass / waterDensity));
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -83,13 +94,37 @@ int main()
|
||||
using namespace units::isq::si::fps::literals;
|
||||
|
||||
// KMS Bismark, using the units the Germans would use, taken from Wiki
|
||||
auto bismark = Ship{.length{251._q_m}, .draft{9.3_q_m}, .beam{36_q_m}, .speed{56_q_km_per_h}, .mass{50'300_q_t}, .mainGuns{380_q_mm}, .shellMass{800_q_kg}, .shellSpeed{820._q_m_per_s}, .power{110.45_q_kW}};
|
||||
auto bismark = Ship{.length{251._q_m},
|
||||
.draft{9.3_q_m},
|
||||
.beam{36_q_m},
|
||||
.speed{56_q_km_per_h},
|
||||
.mass{50'300_q_t},
|
||||
.mainGuns{380_q_mm},
|
||||
.shellMass{800_q_kg},
|
||||
.shellSpeed{820._q_m_per_s},
|
||||
.power{110.45_q_kW}};
|
||||
|
||||
// USS Iowa, using units from the foot-pound-second system
|
||||
auto iowa = Ship{.length{860._q_ft}, .draft{37._q_ft + 2._q_in}, .beam{108._q_ft + 2._q_in}, .speed{33_q_knot}, .mass{57'540_q_lton}, .mainGuns{16_q_in}, .shellMass{2700_q_lb}, .shellSpeed{2690._q_ft_per_s}, .power{212'000_q_hp}};
|
||||
auto iowa = Ship{.length{860._q_ft},
|
||||
.draft{37._q_ft + 2._q_in},
|
||||
.beam{108._q_ft + 2._q_in},
|
||||
.speed{33_q_knot},
|
||||
.mass{57'540_q_lton},
|
||||
.mainGuns{16_q_in},
|
||||
.shellMass{2700_q_lb},
|
||||
.shellSpeed{2690._q_ft_per_s},
|
||||
.power{212'000_q_hp}};
|
||||
|
||||
// HMS King George V, using units from the foot-pound-second system
|
||||
auto kgv = Ship{.length{745.1_q_ft}, .draft{33._q_ft + 7.5_q_in}, .beam{103.2_q_ft + 2.5_q_in}, .speed{28.3_q_knot}, .mass{42'245_q_lton}, .mainGuns{14_q_in}, .shellMass{1'590_q_lb}, .shellSpeed{2483._q_ft_per_s}, .power{110'000_q_hp}};
|
||||
auto kgv = Ship{.length{745.1_q_ft},
|
||||
.draft{33._q_ft + 7.5_q_in},
|
||||
.beam{103.2_q_ft + 2.5_q_in},
|
||||
.speed{28.3_q_knot},
|
||||
.mass{42'245_q_lton},
|
||||
.mainGuns{14_q_in},
|
||||
.shellMass{1'590_q_lb},
|
||||
.shellSpeed{2483._q_ft_per_s},
|
||||
.power{110'000_q_hp}};
|
||||
|
||||
print_details("KMS Bismark, defined in appropriate units from the SI system", bismark);
|
||||
std::cout << "\n\n";
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <units/chrono.h>
|
||||
#include <units/generic/dimensionless.h>
|
||||
#include <units/isq/si/international/length.h>
|
||||
|
||||
#include <array>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@@ -43,14 +42,14 @@ using namespace units::isq;
|
||||
auto get_gliders()
|
||||
{
|
||||
using namespace si::literals;
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||
static const std::array gliders = {
|
||||
glider{"SZD-30 Pirat", {velocity(83_q_km_per_h), rate_of_climb(-0.7389_q_m_per_s)}},
|
||||
glider{"SZD-51 Junior", {velocity(80_q_km_per_h), rate_of_climb(-0.6349_q_m_per_s)}},
|
||||
glider{"SZD-48 Jantar Std 3", {velocity(110_q_km_per_h), rate_of_climb(-0.77355_q_m_per_s)}},
|
||||
glider{"SZD-56 Diana", {velocity(110_q_km_per_h), rate_of_climb(-0.63657_q_m_per_s)}}};
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
glider{"SZD-30 Pirat", {velocity(83_q_km_per_h), rate_of_climb(-0.7389_q_m_per_s)}},
|
||||
glider{"SZD-51 Junior", {velocity(80_q_km_per_h), rate_of_climb(-0.6349_q_m_per_s)}},
|
||||
glider{"SZD-48 Jantar Std 3", {velocity(110_q_km_per_h), rate_of_climb(-0.77355_q_m_per_s)}},
|
||||
glider{"SZD-56 Diana", {velocity(110_q_km_per_h), rate_of_climb(-0.63657_q_m_per_s)}}};
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
return gliders;
|
||||
}
|
||||
|
||||
@@ -58,9 +57,9 @@ auto get_weather_conditions()
|
||||
{
|
||||
using namespace si::literals;
|
||||
static const std::array weather_conditions = {
|
||||
std::pair("Good", weather{height(1900_q_m), rate_of_climb(4.3_q_m_per_s)}),
|
||||
std::pair("Medium", weather{height(1550_q_m), rate_of_climb(2.8_q_m_per_s)}),
|
||||
std::pair("Bad", weather{height(850_q_m), rate_of_climb(1.8_q_m_per_s)})};
|
||||
std::pair("Good", weather{height(1900_q_m), rate_of_climb(4.3_q_m_per_s)}),
|
||||
std::pair("Medium", weather{height(1550_q_m), rate_of_climb(2.8_q_m_per_s)}),
|
||||
std::pair("Bad", weather{height(850_q_m), rate_of_climb(1.8_q_m_per_s)})};
|
||||
return weather_conditions;
|
||||
}
|
||||
|
||||
@@ -69,14 +68,14 @@ auto get_waypoints()
|
||||
using namespace geographic::literals;
|
||||
using namespace units::isq::si::international::literals;
|
||||
static const std::array waypoints = {
|
||||
waypoint{"EPPR", {54.24772_N, 18.6745_E}, altitude(16_q_ft)}, // N54°14'51.8" E18°40'28.2"
|
||||
waypoint{"EPGI", {53.52442_N, 18.84947_E}, altitude(115_q_ft)} // N53°31'27.9" E18°50'58.1"
|
||||
waypoint{"EPPR", {54.24772_N, 18.6745_E}, altitude(16_q_ft)}, // N54°14'51.8" E18°40'28.2"
|
||||
waypoint{"EPGI", {53.52442_N, 18.84947_E}, altitude(115_q_ft)} // N53°31'27.9" E18°50'58.1"
|
||||
};
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, glider>
|
||||
requires(std::same_as<std::ranges::range_value_t<R>, glider>)
|
||||
void print(const R& gliders)
|
||||
{
|
||||
std::cout << "Gliders:\n";
|
||||
@@ -85,13 +84,14 @@ void print(const R& gliders)
|
||||
std::cout << "- Name: " << g.name << "\n";
|
||||
std::cout << "- Polar:\n";
|
||||
for (const auto& p : g.polar)
|
||||
std::cout << STD_FMT::format(" * {:%.4Q %q} @ {:%.1Q %q} -> {:%.1Q %q}\n", p.climb, p.v, units::quantity_cast<units::one>(glide_ratio(g.polar[0])));
|
||||
std::cout << STD_FMT::format(" * {:%.4Q %q} @ {:%.1Q %q} -> {:%.1Q %q}\n", p.climb, p.v,
|
||||
units::quantity_cast<units::one>(glide_ratio(g.polar[0])));
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, std::pair<const char*, weather>>
|
||||
requires(std::same_as<std::ranges::range_value_t<R>, std::pair<const char*, weather>>)
|
||||
void print(const R& conditions)
|
||||
{
|
||||
std::cout << "Weather:\n";
|
||||
@@ -106,7 +106,7 @@ void print(const R& conditions)
|
||||
}
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, waypoint>
|
||||
requires(std::same_as<std::ranges::range_value_t<R>, waypoint>)
|
||||
void print(const R& waypoints)
|
||||
{
|
||||
std::cout << "Waypoints:\n";
|
||||
@@ -125,7 +125,8 @@ void print(const task& t)
|
||||
std::cout << "- Finish: " << t.get_finish().name << "\n";
|
||||
std::cout << "- Length: " << STD_FMT::format("{:%.1Q %q}", t.get_length()) << "\n";
|
||||
|
||||
std::cout << "- Legs: " << "\n";
|
||||
std::cout << "- Legs: "
|
||||
<< "\n";
|
||||
for (const auto& l : t.get_legs())
|
||||
std::cout << STD_FMT::format(" * {} -> {} ({:%.1Q %q})\n", l.begin().name, l.end().name, l.get_length());
|
||||
std::cout << "\n";
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/si/energy.h> // IWYU pragma: keep
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/energy.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/force.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/quantity_io.h>
|
||||
#include <linear_algebra.hpp>
|
||||
#include <iostream>
|
||||
#include <linear_algebra.hpp>
|
||||
|
||||
namespace STD_LA {
|
||||
|
||||
@@ -73,9 +73,9 @@ void vector_of_quantity_add()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_add:\n";
|
||||
|
||||
vector<si::length<si::metre>> v = { 1_q_m, 2_q_m, 3_q_m };
|
||||
vector<si::length<si::metre>> u = { 3_q_m, 2_q_m, 1_q_m };
|
||||
vector<si::length<si::kilometre>> t = { 3_q_km, 2_q_km, 1_q_km };
|
||||
vector<si::length<si::metre>> v = {1_q_m, 2_q_m, 3_q_m};
|
||||
vector<si::length<si::metre>> u = {3_q_m, 2_q_m, 1_q_m};
|
||||
vector<si::length<si::kilometre>> t = {3_q_km, 2_q_km, 1_q_km};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -90,8 +90,8 @@ void vector_of_quantity_multiply_same()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_multiply_same:\n";
|
||||
|
||||
vector<si::length<si::metre>> v = { 1_q_m, 2_q_m, 3_q_m };
|
||||
vector<si::length<si::metre>> u = { 3_q_m, 2_q_m, 1_q_m };
|
||||
vector<si::length<si::metre>> v = {1_q_m, 2_q_m, 3_q_m};
|
||||
vector<si::length<si::metre>> u = {3_q_m, 2_q_m, 1_q_m};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -104,8 +104,8 @@ void vector_of_quantity_multiply_different()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_multiply_different:\n";
|
||||
|
||||
vector<si::force<si::newton>> v = { 1_q_N, 2_q_N, 3_q_N };
|
||||
vector<si::length<si::metre>> u = { 3_q_m, 2_q_m, 1_q_m };
|
||||
vector<si::force<si::newton>> v = {1_q_N, 2_q_N, 3_q_N};
|
||||
vector<si::length<si::metre>> u = {3_q_m, 2_q_m, 1_q_m};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -119,7 +119,7 @@ void vector_of_quantity_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_divide_by_scalar:\n";
|
||||
|
||||
vector<si::length<si::metre>> v = { 4_q_m, 8_q_m, 12_q_m };
|
||||
vector<si::length<si::metre>> v = {4_q_m, 8_q_m, 12_q_m};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
|
||||
@@ -140,9 +140,9 @@ void matrix_of_quantity_add()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_add:\n";
|
||||
|
||||
matrix<si::length<si::metre>> v = {{ 1_q_m, 2_q_m, 3_q_m }, { 4_q_m, 5_q_m, 6_q_m }, { 7_q_m, 8_q_m, 9_q_m }};
|
||||
matrix<si::length<si::metre>> u = {{ 3_q_m, 2_q_m, 1_q_m }, { 3_q_m, 2_q_m, 1_q_m }, { 3_q_m, 2_q_m, 1_q_m }};
|
||||
matrix<si::length<si::millimetre>> t = {{ 3_q_mm, 2_q_mm, 1_q_mm }, { 3_q_mm, 2_q_mm, 1_q_mm }, { 3_q_mm, 2_q_mm, 1_q_mm }};
|
||||
matrix<si::length<si::metre>> v = {{1_q_m, 2_q_m, 3_q_m}, {4_q_m, 5_q_m, 6_q_m}, {7_q_m, 8_q_m, 9_q_m}};
|
||||
matrix<si::length<si::metre>> u = {{3_q_m, 2_q_m, 1_q_m}, {3_q_m, 2_q_m, 1_q_m}, {3_q_m, 2_q_m, 1_q_m}};
|
||||
matrix<si::length<si::millimetre>> t = {{3_q_mm, 2_q_mm, 1_q_mm}, {3_q_mm, 2_q_mm, 1_q_mm}, {3_q_mm, 2_q_mm, 1_q_mm}};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -159,8 +159,8 @@ void matrix_of_quantity_multiply_same()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_multiply_same:\n";
|
||||
|
||||
matrix<si::length<si::metre>> v = {{ 1_q_m, 2_q_m, 3_q_m }, { 4_q_m, 5_q_m, 6_q_m }, { 7_q_m, 8_q_m, 9_q_m }};
|
||||
vector<si::length<si::metre>> u = { 3_q_m, 2_q_m, 1_q_m };
|
||||
matrix<si::length<si::metre>> v = {{1_q_m, 2_q_m, 3_q_m}, {4_q_m, 5_q_m, 6_q_m}, {7_q_m, 8_q_m, 9_q_m}};
|
||||
vector<si::length<si::metre>> u = {3_q_m, 2_q_m, 1_q_m};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -173,8 +173,8 @@ void matrix_of_quantity_multiply_different()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_multiply_different:\n";
|
||||
|
||||
vector<si::force<si::newton>> v = { 1_q_N, 2_q_N, 3_q_N };
|
||||
matrix<si::length<si::metre>> u = {{ 1_q_m, 2_q_m, 3_q_m }, { 4_q_m, 5_q_m, 6_q_m }, { 7_q_m, 8_q_m, 9_q_m }};
|
||||
vector<si::force<si::newton>> v = {1_q_N, 2_q_N, 3_q_N};
|
||||
matrix<si::length<si::metre>> u = {{1_q_m, 2_q_m, 3_q_m}, {4_q_m, 5_q_m, 6_q_m}, {7_q_m, 8_q_m, 9_q_m}};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -188,7 +188,7 @@ void matrix_of_quantity_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_divide_by_scalar:\n";
|
||||
|
||||
matrix<si::length<si::metre>> v = {{ 2_q_m, 4_q_m, 6_q_m }, { 4_q_m, 6_q_m, 8_q_m }, { 8_q_m, 4_q_m, 2_q_m }};
|
||||
matrix<si::length<si::metre>> v = {{2_q_m, 4_q_m, 6_q_m}, {4_q_m, 6_q_m, 8_q_m}, {8_q_m, 4_q_m, 2_q_m}};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
|
||||
@@ -215,9 +215,9 @@ void quantity_of_vector_add()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_add:\n";
|
||||
|
||||
length_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
length_v<si::kilometre> t(vector<>{ 3, 2, 1 });
|
||||
length_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
length_v<si::kilometre> t(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -232,8 +232,8 @@ void quantity_of_vector_multiply_same()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_multiply_same:\n";
|
||||
|
||||
length_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
length_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -246,8 +246,8 @@ void quantity_of_vector_multiply_different()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_multiply_different:\n";
|
||||
|
||||
force_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
force_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -261,7 +261,7 @@ void quantity_of_vector_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_divide_by_scalar:\n";
|
||||
|
||||
length_v<> v(vector<>{ 4, 8, 12 });
|
||||
length_v<> v(vector<>{4, 8, 12});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
|
||||
@@ -285,9 +285,9 @@ void quantity_of_matrix_add()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_add:\n";
|
||||
|
||||
length_m<> v(matrix<>{{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }});
|
||||
length_m<> u(matrix<>{{ 3, 2, 1 }, { 3, 2, 1 }, { 3, 2, 1 }});
|
||||
length_m<si::kilometre> t(matrix<>{{ 3, 2, 1 }, { 3, 2, 1 }, { 3, 2, 1 }});
|
||||
length_m<> v(matrix<>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
|
||||
length_m<> u(matrix<>{{3, 2, 1}, {3, 2, 1}, {3, 2, 1}});
|
||||
length_m<si::kilometre> t(matrix<>{{3, 2, 1}, {3, 2, 1}, {3, 2, 1}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -304,8 +304,8 @@ void quantity_of_matrix_multiply_same()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_multiply_same:\n";
|
||||
|
||||
length_m<> v(matrix<>{{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }});
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
length_m<> v(matrix<>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -318,8 +318,8 @@ void quantity_of_matrix_multiply_different()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_multiply_different:\n";
|
||||
|
||||
force_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_m<> u(matrix<>{{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }});
|
||||
force_v<> v(vector<>{1, 2, 3});
|
||||
length_m<> u(matrix<>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -333,7 +333,7 @@ void quantity_of_matrix_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_divide_by_scalar:\n";
|
||||
|
||||
length_m<> v(matrix<>{{ 2, 4, 6 }, { 4, 6, 8 }, { 8, 4, 2 }});
|
||||
length_m<> v(matrix<>{{2, 4, 6}, {4, 6, 8}, {8, 4, 2}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/natural/natural.h>
|
||||
#include <units/isq/si/constants.h>
|
||||
#include <units/isq/si/energy.h>
|
||||
#include <units/isq/si/mass.h>
|
||||
#include <units/isq/si/momentum.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/constants.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/math.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <exception>
|
||||
@@ -88,18 +88,16 @@ void natural_example()
|
||||
<< "E = " << E << "\n";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
si_example();
|
||||
natural_example();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unhandled unknown exception caught\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <exception>
|
||||
@@ -44,8 +44,9 @@ void example()
|
||||
Time auto t1 = 10_q_s;
|
||||
Speed auto v1 = avg_speed(d1, t1);
|
||||
|
||||
auto temp1 = v1 * 50_q_m; // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit'
|
||||
Speed auto v2 = temp1 / 100_q_m; // back to known dimensions again
|
||||
auto temp1 =
|
||||
v1 * 50_q_m; // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit'
|
||||
Speed auto v2 = temp1 / 100_q_m; // back to known dimensions again
|
||||
Length auto d2 = v2 * 60_q_s;
|
||||
|
||||
std::cout << "d1 = " << d1 << '\n';
|
||||
@@ -56,17 +57,15 @@ void example()
|
||||
std::cout << "d2 = " << d2 << '\n';
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
example();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unhandled unknown exception caught\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@ public:
|
||||
|
||||
measurement() = default;
|
||||
|
||||
constexpr explicit measurement(const value_type& val, const value_type& err = {}) :
|
||||
value_(val)
|
||||
constexpr explicit measurement(const value_type& val, const value_type& err = {}) : value_(val)
|
||||
{
|
||||
// it sucks that using declaration cannot be provided for a constructor initializer list
|
||||
using namespace std;
|
||||
@@ -133,7 +132,8 @@ void example()
|
||||
|
||||
const Speed auto v1 = a * t;
|
||||
#if UNITS_DOWNCAST_MODE == 0
|
||||
std::cout << a << " * " << t << " = " << v1 << " = " << quantity_cast<si::dim_speed, si::kilometre_per_hour>(v1) << '\n';
|
||||
std::cout << a << " * " << t << " = " << v1 << " = " << quantity_cast<si::dim_speed, si::kilometre_per_hour>(v1)
|
||||
<< '\n';
|
||||
#else
|
||||
std::cout << a << " * " << t << " = " << v1 << " = " << quantity_cast<si::kilometre_per_hour>(v1) << '\n';
|
||||
#endif
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/si/cgs/length.h>
|
||||
#include <units/isq/si/cgs/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/cgs/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/international/length.h>
|
||||
#include <units/isq/si/international/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/length.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/international/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/length.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@@ -35,38 +35,31 @@ namespace {
|
||||
|
||||
using namespace units::isq;
|
||||
|
||||
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)
|
||||
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::speed<si::metre_per_second>
|
||||
fixed_double_si_avg_speed(si::length<si::metre> d,
|
||||
si::time<si::second> t)
|
||||
constexpr si::speed<si::metre_per_second> fixed_double_si_avg_speed(si::length<si::metre> d, si::time<si::second> t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
|
||||
template<typename U1, typename R1, typename U2, typename R2>
|
||||
constexpr Speed auto si_avg_speed(si::length<U1, R1> d,
|
||||
si::time<U2, R2> t)
|
||||
constexpr Speed auto si_avg_speed(si::length<U1, R1> d, si::time<U2, R2> t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
|
||||
constexpr Speed auto avg_speed(Length auto d, Time auto t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
constexpr Speed auto avg_speed(Length auto d, Time auto t) { return d / t; }
|
||||
|
||||
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::speed<si::kilometre_per_hour>>(speed);
|
||||
std::cout << "Average speed of a car that makes " << distance << " in "
|
||||
<< duration << " is " << result_in_kmph << ".\n";
|
||||
std::cout << "Average speed of a car that makes " << distance << " in " << duration << " is " << result_in_kmph
|
||||
<< ".\n";
|
||||
}
|
||||
|
||||
void example()
|
||||
@@ -94,7 +87,8 @@ void example()
|
||||
std::cout << "\nSI units with 'double' as representation\n";
|
||||
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<int>(distance), quantity_cast<int>(duration)));
|
||||
print_result(distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<int>(distance), quantity_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, si_avg_speed(distance, duration));
|
||||
@@ -130,7 +124,9 @@ void example()
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
// also it is not possible to make a lossless conversion of miles to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
print_result(
|
||||
distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, si_avg_speed(distance, duration));
|
||||
@@ -169,7 +165,9 @@ void example()
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
// it is not possible to make a lossless conversion of centimeters to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
print_result(
|
||||
distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
|
||||
@@ -178,20 +176,17 @@ void example()
|
||||
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
example();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unhandled unknown exception caught\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <units/isq/si/force.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/mass.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/volume.h>
|
||||
#include <cassert>
|
||||
@@ -50,7 +50,10 @@ class Box {
|
||||
si::length<si::metre> height_;
|
||||
si::density<si::kilogram_per_metre_cub> density_ = air_density;
|
||||
public:
|
||||
constexpr Box(const si::length<si::metre>& length, const si::length<si::metre>& width, si::length<si::metre> height) : base_(length * width), height_(std::move(height)) {}
|
||||
constexpr Box(const si::length<si::metre>& length, const si::length<si::metre>& width, si::length<si::metre> height) :
|
||||
base_(length * width), height_(std::move(height))
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr si::force<si::newton> filled_weight() const
|
||||
{
|
||||
@@ -90,13 +93,13 @@ int main()
|
||||
auto box = Box(1000.0 * mm, 500.0 * mm, height);
|
||||
box.set_contents_density(1000.0 * (kg / m3));
|
||||
|
||||
const auto fill_time = 200.0 * s; // time since starting fill
|
||||
const auto measured_mass = 20.0 * kg; // measured mass at fill_time
|
||||
const auto fill_time = 200.0 * s; // time since starting fill
|
||||
const auto measured_mass = 20.0 * kg; // measured mass at fill_time
|
||||
|
||||
const Length auto fill_level = box.fill_level(measured_mass);
|
||||
const Dimensionless auto fill_percent = quantity_cast<percent>(fill_level / height);
|
||||
const Volume auto spare_capacity = box.spare_capacity(measured_mass);
|
||||
const auto input_flow_rate = measured_mass / fill_time; // unknown dimension
|
||||
const auto input_flow_rate = measured_mass / fill_time; // unknown dimension
|
||||
const Speed auto float_rise_rate = fill_level / fill_time;
|
||||
const Time auto fill_time_left = (height / fill_level - 1) * fill_time;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <units/isq/si/resistance.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/voltage.h>
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/quantity_io.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -39,15 +39,15 @@ void simple_quantities()
|
||||
using distance = si::length<si::metre>;
|
||||
using duration = si::time<si::second>;
|
||||
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
constexpr distance km = 1.0 * references::km;
|
||||
constexpr distance miles = 1.0 * mi;
|
||||
|
||||
constexpr duration sec = 1 * s;
|
||||
constexpr duration min = 1 * references::min;
|
||||
constexpr duration hr = 1 * h;
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
|
||||
std::cout << "A physical quantities library can choose the simple\n";
|
||||
std::cout << "option to provide output using a single type for each base unit:\n\n";
|
||||
@@ -66,8 +66,8 @@ void quantities_with_typed_units()
|
||||
using namespace units::isq::si::international;
|
||||
using namespace units::isq::si::international::references;
|
||||
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
constexpr length<kilometre> km = 1.0 * si::references::km;
|
||||
constexpr length<mile> miles = 1.0 * mi;
|
||||
|
||||
@@ -76,7 +76,7 @@ UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
constexpr si::time<second> sec = 1 * s;
|
||||
constexpr si::time<minute> min = 1 * si::references::min;
|
||||
constexpr si::time<hour> hr = 1 * h;
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
|
||||
std::cout << "A more flexible option is to provide separate types for each unit,\n\n";
|
||||
std::cout << km << '\n';
|
||||
|
||||
@@ -20,17 +20,17 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/bits/external/hacks.h> // IWYU pragma: keep
|
||||
#include <units/bits/external/hacks.h> // IWYU pragma: keep
|
||||
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
#include <units/isq/si/force.h> // 'N' (Newton) shadows a template parameter traditionally used as a size of the array
|
||||
#include <units/isq/si/force.h> // 'N' (Newton) shadows a template parameter traditionally used as a size of the array
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
|
||||
#include <units/generic/angle.h>
|
||||
#include <units/isq/si/energy.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/torque.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/torque.h> // IWYU pragma: keep
|
||||
#include <units/quantity_io.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/fps/density.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/fps/density.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/fps/length.h>
|
||||
#include <units/isq/si/fps/mass.h>
|
||||
#include <units/isq/si/fps/power.h>
|
||||
@@ -56,7 +56,7 @@ struct Ship {
|
||||
};
|
||||
|
||||
// Print 'a' in its current units and print its value cast to the units in each of Args
|
||||
template<class ...Args, units::Quantity Q>
|
||||
template<class... Args, units::Quantity Q>
|
||||
auto fmt_line(const Q a)
|
||||
{
|
||||
return STD_FMT::format("{:22}", a) + (STD_FMT::format(",{:20}", units::quantity_cast<Args>(a)) + ...);
|
||||
@@ -68,16 +68,27 @@ void print_details(std::string_view description, const Ship& ship)
|
||||
using namespace units::isq::si::fps::references;
|
||||
const auto waterDensity = 62.4 * (lb / ft3);
|
||||
std::cout << STD_FMT::format("{}\n", description);
|
||||
std::cout << STD_FMT::format("{:20} : {}\n", "length", fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.length))
|
||||
<< STD_FMT::format("{:20} : {}\n", "draft", fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.draft))
|
||||
<< STD_FMT::format("{:20} : {}\n", "beam", fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.beam))
|
||||
<< STD_FMT::format("{:20} : {}\n", "mass", fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::tonne>>(ship.mass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "speed", fmt_line<si::fps::speed<si::fps::knot>, si::speed<si::kilometre_per_hour>>(ship.speed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "power", fmt_line<si::fps::power<si::fps::horse_power>, si::power<si::kilowatt>>(ship.power))
|
||||
<< STD_FMT::format("{:20} : {}\n", "main guns", fmt_line<si::fps::length<si::fps::inch>, si::length<si::millimetre>>(ship.mainGuns))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells weighing", fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::kilogram>>(ship.shellMass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells at", fmt_line<si::fps::speed<si::fps::mile_per_hour>, si::speed<si::kilometre_per_hour>>(ship.shellSpeed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "volume underwater", fmt_line<si::volume<si::cubic_metre>, si::volume<si::litre>>(ship.mass / waterDensity));
|
||||
std::cout << STD_FMT::format("{:20} : {}\n", "length",
|
||||
fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.length))
|
||||
<< STD_FMT::format("{:20} : {}\n", "draft",
|
||||
fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.draft))
|
||||
<< STD_FMT::format("{:20} : {}\n", "beam",
|
||||
fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.beam))
|
||||
<< STD_FMT::format("{:20} : {}\n", "mass",
|
||||
fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::tonne>>(ship.mass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "speed",
|
||||
fmt_line<si::fps::speed<si::fps::knot>, si::speed<si::kilometre_per_hour>>(ship.speed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "power",
|
||||
fmt_line<si::fps::power<si::fps::horse_power>, si::power<si::kilowatt>>(ship.power))
|
||||
<< STD_FMT::format("{:20} : {}\n", "main guns",
|
||||
fmt_line<si::fps::length<si::fps::inch>, si::length<si::millimetre>>(ship.mainGuns))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells weighing",
|
||||
fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::kilogram>>(ship.shellMass))
|
||||
<< STD_FMT::format(
|
||||
"{:20} : {}\n", "fire shells at",
|
||||
fmt_line<si::fps::speed<si::fps::mile_per_hour>, si::speed<si::kilometre_per_hour>>(ship.shellSpeed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "volume underwater",
|
||||
fmt_line<si::volume<si::cubic_metre>, si::volume<si::litre>>(ship.mass / waterDensity));
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -87,13 +98,37 @@ int main()
|
||||
using units::isq::si::fps::references::ft; // collides with si::femtotonne (alias unit of mass)
|
||||
|
||||
// KMS Bismark, using the units the Germans would use, taken from Wiki
|
||||
auto bismark = Ship{.length{251. * m}, .draft{9.3 * m}, .beam{36 * m}, .speed{56 * (km / h)}, .mass{50'300 * t}, .mainGuns{380 * mm}, .shellMass{800 * kg}, .shellSpeed{820. * (m / s)}, .power{110.45 * kW}};
|
||||
auto bismark = Ship{.length{251. * m},
|
||||
.draft{9.3 * m},
|
||||
.beam{36 * m},
|
||||
.speed{56 * (km / h)},
|
||||
.mass{50'300 * t},
|
||||
.mainGuns{380 * mm},
|
||||
.shellMass{800 * kg},
|
||||
.shellSpeed{820. * (m / s)},
|
||||
.power{110.45 * kW}};
|
||||
|
||||
// USS Iowa, using units from the foot-pound-second system
|
||||
auto iowa = Ship{.length{860. * ft}, .draft{37. * ft + 2. * in}, .beam{108. * ft + 2. * in}, .speed{33 * knot}, .mass{57'540 * lton}, .mainGuns{16 * in}, .shellMass{2700 * lb}, .shellSpeed{2690. * (ft / s)}, .power{212'000 * hp}};
|
||||
auto iowa = Ship{.length{860. * ft},
|
||||
.draft{37. * ft + 2. * in},
|
||||
.beam{108. * ft + 2. * in},
|
||||
.speed{33 * knot},
|
||||
.mass{57'540 * lton},
|
||||
.mainGuns{16 * in},
|
||||
.shellMass{2700 * lb},
|
||||
.shellSpeed{2690. * (ft / s)},
|
||||
.power{212'000 * hp}};
|
||||
|
||||
// HMS King George V, using units from the foot-pound-second system
|
||||
auto kgv = Ship{.length{745.1 * ft}, .draft{33. * ft + 7.5 * in}, .beam{103.2 * ft + 2.5 * in}, .speed{28.3 * knot}, .mass{42'245 * lton}, .mainGuns{14 * in}, .shellMass{1'590 * lb}, .shellSpeed{2483. * (ft / s)}, .power{110'000 * hp}};
|
||||
auto kgv = Ship{.length{745.1 * ft},
|
||||
.draft{33. * ft + 7.5 * in},
|
||||
.beam{103.2 * ft + 2.5 * in},
|
||||
.speed{28.3 * knot},
|
||||
.mass{42'245 * lton},
|
||||
.mainGuns{14 * in},
|
||||
.shellMass{1'590 * lb},
|
||||
.shellSpeed{2483. * (ft / s)},
|
||||
.power{110'000 * hp}};
|
||||
|
||||
print_details("KMS Bismark, defined in appropriate units from the SI system", bismark);
|
||||
std::cout << "\n\n";
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <units/chrono.h>
|
||||
#include <units/generic/dimensionless.h>
|
||||
#include <units/isq/si/international/length.h>
|
||||
|
||||
#include <array>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@@ -43,14 +42,14 @@ using namespace units::isq;
|
||||
auto get_gliders()
|
||||
{
|
||||
using namespace si::references;
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||
static const std::array gliders = {
|
||||
glider{"SZD-30 Pirat", {velocity(83 * (km / h)), rate_of_climb(-0.7389 * (m / s))}},
|
||||
glider{"SZD-51 Junior", {velocity(80 * (km / h)), rate_of_climb(-0.6349 * (m / s))}},
|
||||
glider{"SZD-48 Jantar Std 3", {velocity(110 * (km / h)), rate_of_climb(-0.77355 * (m / s))}},
|
||||
glider{"SZD-56 Diana", {velocity(110 * (km / h)), rate_of_climb(-0.63657 * (m / s))}}};
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
glider{"SZD-30 Pirat", {velocity(83 * (km / h)), rate_of_climb(-0.7389 * (m / s))}},
|
||||
glider{"SZD-51 Junior", {velocity(80 * (km / h)), rate_of_climb(-0.6349 * (m / s))}},
|
||||
glider{"SZD-48 Jantar Std 3", {velocity(110 * (km / h)), rate_of_climb(-0.77355 * (m / s))}},
|
||||
glider{"SZD-56 Diana", {velocity(110 * (km / h)), rate_of_climb(-0.63657 * (m / s))}}};
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
return gliders;
|
||||
}
|
||||
|
||||
@@ -58,9 +57,9 @@ auto get_weather_conditions()
|
||||
{
|
||||
using namespace si::references;
|
||||
static const std::array weather_conditions = {
|
||||
std::pair("Good", weather{height(1900 * m), rate_of_climb(4.3 * (m / s))}),
|
||||
std::pair("Medium", weather{height(1550 * m), rate_of_climb(2.8 * (m / s))}),
|
||||
std::pair("Bad", weather{height(850 * m), rate_of_climb(1.8 * (m / s))})};
|
||||
std::pair("Good", weather{height(1900 * m), rate_of_climb(4.3 * (m / s))}),
|
||||
std::pair("Medium", weather{height(1550 * m), rate_of_climb(2.8 * (m / s))}),
|
||||
std::pair("Bad", weather{height(850 * m), rate_of_climb(1.8 * (m / s))})};
|
||||
return weather_conditions;
|
||||
}
|
||||
|
||||
@@ -69,14 +68,14 @@ auto get_waypoints()
|
||||
using namespace geographic::literals;
|
||||
using namespace units::isq::si::international::references;
|
||||
static const std::array waypoints = {
|
||||
waypoint{"EPPR", {54.24772_N, 18.6745_E}, altitude(16 * ft)}, // N54°14'51.8" E18°40'28.2"
|
||||
waypoint{"EPGI", {53.52442_N, 18.84947_E}, altitude(115 * ft)} // N53°31'27.9" E18°50'58.1"
|
||||
waypoint{"EPPR", {54.24772_N, 18.6745_E}, altitude(16 * ft)}, // N54°14'51.8" E18°40'28.2"
|
||||
waypoint{"EPGI", {53.52442_N, 18.84947_E}, altitude(115 * ft)} // N53°31'27.9" E18°50'58.1"
|
||||
};
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, glider>
|
||||
requires(std::same_as<std::ranges::range_value_t<R>, glider>)
|
||||
void print(const R& gliders)
|
||||
{
|
||||
std::cout << "Gliders:\n";
|
||||
@@ -85,13 +84,14 @@ void print(const R& gliders)
|
||||
std::cout << "- Name: " << g.name << "\n";
|
||||
std::cout << "- Polar:\n";
|
||||
for (const auto& p : g.polar)
|
||||
std::cout << STD_FMT::format(" * {:%.4Q %q} @ {:%.1Q %q} -> {:%.1Q %q}\n", p.climb, p.v, units::quantity_cast<units::one>(glide_ratio(g.polar[0])));
|
||||
std::cout << STD_FMT::format(" * {:%.4Q %q} @ {:%.1Q %q} -> {:%.1Q %q}\n", p.climb, p.v,
|
||||
units::quantity_cast<units::one>(glide_ratio(g.polar[0])));
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, std::pair<const char*, weather>>
|
||||
requires(std::same_as<std::ranges::range_value_t<R>, std::pair<const char*, weather>>)
|
||||
void print(const R& conditions)
|
||||
{
|
||||
std::cout << "Weather:\n";
|
||||
@@ -106,7 +106,7 @@ void print(const R& conditions)
|
||||
}
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, waypoint>
|
||||
requires(std::same_as<std::ranges::range_value_t<R>, waypoint>)
|
||||
void print(const R& waypoints)
|
||||
{
|
||||
std::cout << "Waypoints:\n";
|
||||
@@ -125,7 +125,8 @@ void print(const task& t)
|
||||
std::cout << "- Finish: " << t.get_finish().name << "\n";
|
||||
std::cout << "- Length: " << STD_FMT::format("{:%.1Q %q}", t.get_length()) << "\n";
|
||||
|
||||
std::cout << "- Legs: " << "\n";
|
||||
std::cout << "- Legs: "
|
||||
<< "\n";
|
||||
for (const auto& l : t.get_legs())
|
||||
std::cout << STD_FMT::format(" * {} -> {} ({:%.1Q %q})\n", l.begin().name, l.end().name, l.get_length());
|
||||
std::cout << "\n";
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/si/energy.h> // IWYU pragma: keep
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/energy.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/force.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/quantity_io.h>
|
||||
#include <linear_algebra.hpp>
|
||||
#include <iostream>
|
||||
#include <linear_algebra.hpp>
|
||||
|
||||
namespace STD_LA {
|
||||
|
||||
@@ -73,9 +73,9 @@ void vector_of_quantity_add()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_add:\n";
|
||||
|
||||
vector<si::length<si::metre>> v = { 1 * m, 2 * m, 3 * m };
|
||||
vector<si::length<si::metre>> u = { 3 * m, 2 * m, 1 * m };
|
||||
vector<si::length<si::kilometre>> t = { 3 * km, 2 * km, 1 * km };
|
||||
vector<si::length<si::metre>> v = {1 * m, 2 * m, 3 * m};
|
||||
vector<si::length<si::metre>> u = {3 * m, 2 * m, 1 * m};
|
||||
vector<si::length<si::kilometre>> t = {3 * km, 2 * km, 1 * km};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -90,8 +90,8 @@ void vector_of_quantity_multiply_same()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_multiply_same:\n";
|
||||
|
||||
vector<si::length<si::metre>> v = { 1 * m, 2 * m, 3 * m };
|
||||
vector<si::length<si::metre>> u = { 3 * m, 2 * m, 1 * m };
|
||||
vector<si::length<si::metre>> v = {1 * m, 2 * m, 3 * m};
|
||||
vector<si::length<si::metre>> u = {3 * m, 2 * m, 1 * m};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -104,8 +104,8 @@ void vector_of_quantity_multiply_different()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_multiply_different:\n";
|
||||
|
||||
vector<si::force<si::newton>> v = { 1 * N, 2 * N, 3 * N };
|
||||
vector<si::length<si::metre>> u = { 3 * m, 2 * m, 1 * m };
|
||||
vector<si::force<si::newton>> v = {1 * N, 2 * N, 3 * N};
|
||||
vector<si::length<si::metre>> u = {3 * m, 2 * m, 1 * m};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -119,7 +119,7 @@ void vector_of_quantity_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_divide_by_scalar:\n";
|
||||
|
||||
vector<si::length<si::metre>> v = { 4 * m, 8 * m, 12 * m };
|
||||
vector<si::length<si::metre>> v = {4 * m, 8 * m, 12 * m};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
|
||||
@@ -140,9 +140,9 @@ void matrix_of_quantity_add()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_add:\n";
|
||||
|
||||
matrix<si::length<si::metre>> v = {{ 1 * m, 2 * m, 3 * m }, { 4 * m, 5 * m, 6 * m }, { 7 * m, 8 * m, 9 * m }};
|
||||
matrix<si::length<si::metre>> u = {{ 3 * m, 2 * m, 1 * m }, { 3 * m, 2 * m, 1 * m }, { 3 * m, 2 * m, 1 * m }};
|
||||
matrix<si::length<si::millimetre>> t = {{ 3 * mm, 2 * mm, 1 * mm }, { 3 * mm, 2 * mm, 1 * mm }, { 3 * mm, 2 * mm, 1 * mm }};
|
||||
matrix<si::length<si::metre>> v = {{1 * m, 2 * m, 3 * m}, {4 * m, 5 * m, 6 * m}, {7 * m, 8 * m, 9 * m}};
|
||||
matrix<si::length<si::metre>> u = {{3 * m, 2 * m, 1 * m}, {3 * m, 2 * m, 1 * m}, {3 * m, 2 * m, 1 * m}};
|
||||
matrix<si::length<si::millimetre>> t = {{3 * mm, 2 * mm, 1 * mm}, {3 * mm, 2 * mm, 1 * mm}, {3 * mm, 2 * mm, 1 * mm}};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -159,8 +159,8 @@ void matrix_of_quantity_multiply_same()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_multiply_same:\n";
|
||||
|
||||
matrix<si::length<si::metre>> v = {{ 1 * m, 2 * m, 3 * m }, { 4 * m, 5 * m, 6 * m }, { 7 * m, 8 * m, 9 * m }};
|
||||
vector<si::length<si::metre>> u = { 3 * m, 2 * m, 1 * m };
|
||||
matrix<si::length<si::metre>> v = {{1 * m, 2 * m, 3 * m}, {4 * m, 5 * m, 6 * m}, {7 * m, 8 * m, 9 * m}};
|
||||
vector<si::length<si::metre>> u = {3 * m, 2 * m, 1 * m};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -173,8 +173,8 @@ void matrix_of_quantity_multiply_different()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_multiply_different:\n";
|
||||
|
||||
vector<si::force<si::newton>> v = { 1 * N, 2 * N, 3 * N };
|
||||
matrix<si::length<si::metre>> u = {{ 1 * m, 2 * m, 3 * m }, { 4 * m, 5 * m, 6 * m }, { 7 * m, 8 * m, 9 * m }};
|
||||
vector<si::force<si::newton>> v = {1 * N, 2 * N, 3 * N};
|
||||
matrix<si::length<si::metre>> u = {{1 * m, 2 * m, 3 * m}, {4 * m, 5 * m, 6 * m}, {7 * m, 8 * m, 9 * m}};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -188,7 +188,7 @@ void matrix_of_quantity_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_divide_by_scalar:\n";
|
||||
|
||||
matrix<si::length<si::metre>> v = {{ 2 * m, 4 * m, 6 * m }, { 4 * m, 6 * m, 8 * m }, { 8 * m, 4 * m, 2 * m }};
|
||||
matrix<si::length<si::metre>> v = {{2 * m, 4 * m, 6 * m}, {4 * m, 6 * m, 8 * m}, {8 * m, 4 * m, 2 * m}};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
|
||||
@@ -215,9 +215,9 @@ void quantity_of_vector_add()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_add:\n";
|
||||
|
||||
length_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
length_v<si::kilometre> t(vector<>{ 3, 2, 1 });
|
||||
length_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
length_v<si::kilometre> t(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -232,8 +232,8 @@ void quantity_of_vector_multiply_same()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_multiply_same:\n";
|
||||
|
||||
length_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
length_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -246,8 +246,8 @@ void quantity_of_vector_multiply_different()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_multiply_different:\n";
|
||||
|
||||
force_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
force_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -261,7 +261,7 @@ void quantity_of_vector_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_divide_by_scalar:\n";
|
||||
|
||||
length_v<> v(vector<>{ 4, 8, 12 });
|
||||
length_v<> v(vector<>{4, 8, 12});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
|
||||
@@ -285,9 +285,9 @@ void quantity_of_matrix_add()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_add:\n";
|
||||
|
||||
length_m<> v(matrix<>{{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }});
|
||||
length_m<> u(matrix<>{{ 3, 2, 1 }, { 3, 2, 1 }, { 3, 2, 1 }});
|
||||
length_m<si::kilometre> t(matrix<>{{ 3, 2, 1 }, { 3, 2, 1 }, { 3, 2, 1 }});
|
||||
length_m<> v(matrix<>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
|
||||
length_m<> u(matrix<>{{3, 2, 1}, {3, 2, 1}, {3, 2, 1}});
|
||||
length_m<si::kilometre> t(matrix<>{{3, 2, 1}, {3, 2, 1}, {3, 2, 1}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -304,8 +304,8 @@ void quantity_of_matrix_multiply_same()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_multiply_same:\n";
|
||||
|
||||
length_m<> v(matrix<>{{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }});
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
length_m<> v(matrix<>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -318,8 +318,8 @@ void quantity_of_matrix_multiply_different()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_multiply_different:\n";
|
||||
|
||||
force_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_m<> u(matrix<>{{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }});
|
||||
force_v<> v(vector<>{1, 2, 3});
|
||||
length_m<> u(matrix<>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -333,7 +333,7 @@ void quantity_of_matrix_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_divide_by_scalar:\n";
|
||||
|
||||
length_m<> v(matrix<>{{ 2, 4, 6 }, { 4, 6, 8 }, { 8, 4, 2 }});
|
||||
length_m<> v(matrix<>{{2, 4, 6}, {4, 6, 8}, {8, 4, 2}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <units/isq/si/energy.h>
|
||||
#include <units/isq/si/mass.h>
|
||||
#include <units/isq/si/momentum.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/math.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <exception>
|
||||
@@ -87,18 +87,16 @@ void natural_example()
|
||||
<< "E = " << E << "\n";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
si_example();
|
||||
natural_example();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unhandled unknown exception caught\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <exception>
|
||||
@@ -44,8 +44,9 @@ void example()
|
||||
Time auto t1 = 10 * s;
|
||||
Speed auto v1 = avg_speed(d1, t1);
|
||||
|
||||
auto temp1 = v1 * (50 * m); // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit'
|
||||
Speed auto v2 = temp1 / (100 * m); // back to known dimensions again
|
||||
auto temp1 =
|
||||
v1 * (50 * m); // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit'
|
||||
Speed auto v2 = temp1 / (100 * m); // back to known dimensions again
|
||||
Length auto d2 = v2 * (60 * s);
|
||||
|
||||
std::cout << "d1 = " << d1 << '\n';
|
||||
@@ -56,17 +57,15 @@ void example()
|
||||
std::cout << "d2 = " << d2 << '\n';
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
example();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unhandled unknown exception caught\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user