feat: preventing possible future units crash when using namespace std;
Resolves #317
This commit is contained in:
1 parent
6b72dd39c1
commit
2cf736a1e6
123 files changed
+1205
-1092
No files matched your search
@@ -20,18 +20,18 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/quantity_io.h>
|
||||
#include <units/systems/cgs/cgs.h>
|
||||
#include <units/systems/international/international.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/quantity_io.h>
|
||||
#include <mp_units/systems/cgs/cgs.h>
|
||||
#include <mp_units/systems/international/international.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace units;
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
|
||||
constexpr quantity<isq::speed[m / s], int> fixed_int_si_avg_speed(quantity<isq::length[m], int> d,
|
||||
quantity<isq::time[s], int> t)
|
||||
@@ -87,7 +87,7 @@ void example()
|
||||
|
||||
// Customary Units (int)
|
||||
{
|
||||
using namespace units::international::unit_symbols;
|
||||
using namespace mp_units::international::unit_symbols;
|
||||
|
||||
constexpr auto distance = isq::length(140, mi);
|
||||
constexpr auto duration = isq::time(2, h);
|
||||
@@ -103,7 +103,7 @@ void example()
|
||||
|
||||
// Customary Units (double)
|
||||
{
|
||||
using namespace units::international::unit_symbols;
|
||||
using namespace mp_units::international::unit_symbols;
|
||||
|
||||
constexpr auto distance = isq::length(140., mi);
|
||||
constexpr auto duration = isq::time(2., h);
|
||||
|
||||
+11
-11
@@ -20,24 +20,24 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/format.h>
|
||||
#include <units/systems/isq/mechanics.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/systems/si/constants.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <units/systems/si/units.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/systems/isq/mechanics.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/constants.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/systems/si/units.h>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
|
||||
template<class T>
|
||||
requires units::is_scalar<T>
|
||||
inline constexpr bool units::is_vector<T> = true;
|
||||
requires mp_units::is_scalar<T>
|
||||
inline constexpr bool mp_units::is_vector<T> = true;
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace units;
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
|
||||
inline constexpr auto g = si::standard_gravity(1);
|
||||
inline constexpr auto air_density = isq::mass_density(1.225, kg / m3);
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace units::si;
|
||||
using namespace mp_units::si;
|
||||
|
||||
constexpr auto mm = isq::length[unit_symbols::mm]; // helper reference object
|
||||
|
||||
|
||||
@@ -20,16 +20,16 @@
|
||||
physical_quantities
|
||||
*/
|
||||
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/quantity_io.h>
|
||||
#include <units/systems/isq/electromagnetism.h>
|
||||
#include <units/systems/si/si.h>
|
||||
#include <mp_units/math.h> // IWYU pragma: keep
|
||||
#include <mp_units/quantity_io.h>
|
||||
#include <mp_units/systems/isq/electromagnetism.h>
|
||||
#include <mp_units/systems/si/si.h>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace units;
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
|
||||
std::cout << "mp-units capacitor time curve example...\n";
|
||||
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
|
||||
@@ -40,7 +40,7 @@ int main()
|
||||
constexpr auto R = isq::resistance(4.7, si::kilo<si::ohm>);
|
||||
|
||||
for (auto t = isq::time(0, ms); t <= isq::time(50, ms); ++t) {
|
||||
const weak_quantity_of<isq::voltage> auto Vt = V0 * units::exp(-t / (R * C));
|
||||
const weak_quantity_of<isq::voltage> auto Vt = V0 * mp_units::exp(-t / (R * C));
|
||||
|
||||
std::cout << "at " << t << " voltage is ";
|
||||
|
||||
|
||||
+17
-17
@@ -15,24 +15,24 @@
|
||||
along with this program. If not, see http://www.gnu.org/licenses./
|
||||
*/
|
||||
|
||||
#include <units/format.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <units/systems/iau/iau.h>
|
||||
#include <units/systems/imperial/imperial.h>
|
||||
#include <units/systems/international/international.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/systems/si/si.h>
|
||||
#include <units/systems/typographic/typographic.h>
|
||||
#include <units/systems/usc/usc.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/quantity_io.h>
|
||||
#include <mp_units/systems/iau/iau.h>
|
||||
#include <mp_units/systems/imperial/imperial.h>
|
||||
#include <mp_units/systems/international/international.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/si.h>
|
||||
#include <mp_units/systems/typographic/typographic.h>
|
||||
#include <mp_units/systems/usc/usc.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
|
||||
void simple_quantities()
|
||||
{
|
||||
using namespace units;
|
||||
using namespace units::si;
|
||||
using namespace units::international;
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::si;
|
||||
using namespace mp_units::international;
|
||||
|
||||
using distance = quantity<isq::distance[kilo<metre>]>;
|
||||
using duration = quantity<isq::duration[second]>;
|
||||
@@ -55,9 +55,9 @@ void simple_quantities()
|
||||
|
||||
void quantities_with_typed_units()
|
||||
{
|
||||
using namespace units;
|
||||
using namespace units::si;
|
||||
using namespace units::international;
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::si;
|
||||
using namespace mp_units::international;
|
||||
|
||||
constexpr auto km = isq::distance[kilo<metre>](1.0);
|
||||
constexpr auto miles = isq::distance[mile](1.0);
|
||||
@@ -103,8 +103,8 @@ void quantities_with_typed_units()
|
||||
|
||||
void calcs_comparison()
|
||||
{
|
||||
using namespace units;
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
|
||||
std::cout << "\nA distinct unit for each type is efficient and accurate\n"
|
||||
"when adding two values of the same very big\n"
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
along with this program. If not, see http://www.gnu.org/licenses./
|
||||
*/
|
||||
|
||||
#include <units/format.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/systems/si/units.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/units.h>
|
||||
#include <iostream>
|
||||
#include <type_traits>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
namespace {
|
||||
|
||||
template<units::Quantity Target, units::Quantity Source>
|
||||
template<mp_units::Quantity Target, mp_units::Quantity Source>
|
||||
requires std::constructible_from<Target, Source>
|
||||
inline constexpr double conversion_factor(Target, Source)
|
||||
{
|
||||
@@ -39,7 +39,7 @@ inline constexpr double conversion_factor(Target, Source)
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
std::cout << "conversion factor in mp-units...\n\n";
|
||||
|
||||
|
||||
@@ -20,17 +20,17 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/format.h>
|
||||
#include <units/systems/imperial/imperial.h>
|
||||
#include <units/systems/international/international.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/systems/imperial/imperial.h>
|
||||
#include <mp_units/systems/international/international.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <iostream>
|
||||
#include <string_view>
|
||||
|
||||
using namespace units;
|
||||
using namespace units::international::unit_symbols;
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::international::unit_symbols;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
|
||||
|
||||
// Some basic specs for the warship
|
||||
@@ -74,7 +74,7 @@ void print_details(std::string_view description, const Ship& ship)
|
||||
|
||||
int main()
|
||||
{
|
||||
using units::international::unit_symbols::ft; // collides with si::femto<si::tonne>
|
||||
using mp_units::international::unit_symbols::ft; // collides with si::femto<si::tonne>
|
||||
|
||||
// KMS Bismark, using the units the Germans would use, taken from Wiki
|
||||
auto bismark = Ship{.length{isq::length[m](251.)},
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
namespace glide_computer {
|
||||
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
task::legs task::make_legs(const waypoints& wpts)
|
||||
{
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "ranged_representation.h"
|
||||
#include <units/bits/fmt_hacks.h>
|
||||
#include <units/quantity.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/systems/si/units.h>
|
||||
#include <mp_units/bits/fmt_hacks.h>
|
||||
#include <mp_units/quantity.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/units.h>
|
||||
#include <compare>
|
||||
#include <limits>
|
||||
#include <numbers>
|
||||
@@ -35,10 +35,12 @@
|
||||
namespace geographic {
|
||||
|
||||
template<typename T = double>
|
||||
using latitude = units::quantity<units::isq::angular_measure[units::si::degree], ranged_representation<T, -90, 90>>;
|
||||
using latitude =
|
||||
mp_units::quantity<mp_units::isq::angular_measure[mp_units::si::degree], ranged_representation<T, -90, 90>>;
|
||||
|
||||
template<typename T = double>
|
||||
using longitude = units::quantity<units::isq::angular_measure[units::si::degree], ranged_representation<T, -180, 180>>;
|
||||
using longitude =
|
||||
mp_units::quantity<mp_units::isq::angular_measure[mp_units::si::degree], ranged_representation<T, -180, 180>>;
|
||||
|
||||
template<class CharT, class Traits, typename T>
|
||||
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const latitude<T>& lat)
|
||||
@@ -125,7 +127,7 @@ struct STD_FMT::formatter<geographic::longitude<T>> : formatter<T> {
|
||||
|
||||
namespace geographic {
|
||||
|
||||
using distance = units::quantity<units::isq::distance[units::si::kilo<units::si::metre>]>;
|
||||
using distance = mp_units::quantity<mp_units::isq::distance[mp_units::si::kilo<mp_units::si::metre>]>;
|
||||
|
||||
template<typename T>
|
||||
struct position {
|
||||
@@ -136,7 +138,7 @@ struct position {
|
||||
template<typename T>
|
||||
distance spherical_distance(position<T> from, position<T> to)
|
||||
{
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
constexpr auto earth_radius = 6371 * isq::radius[si::kilo<si::metre>];
|
||||
|
||||
constexpr auto p = std::numbers::pi_v<T> / 180;
|
||||
|
||||
@@ -23,11 +23,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "geographic.h"
|
||||
#include <units/chrono.h>
|
||||
#include <units/format.h>
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/quantity_point.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/chrono.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/math.h> // IWYU pragma: keep
|
||||
#include <mp_units/quantity_point.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <initializer_list>
|
||||
@@ -54,23 +54,23 @@
|
||||
namespace glide_computer {
|
||||
|
||||
// https://en.wikipedia.org/wiki/Flight_planning#Units_of_measurement
|
||||
inline constexpr struct mean_sea_level : units::absolute_point_origin<units::isq::height> {
|
||||
inline constexpr struct mean_sea_level : mp_units::absolute_point_origin<mp_units::isq::height> {
|
||||
} mean_sea_level;
|
||||
QUANTITY_SPEC(rate_of_climb_speed, units::isq::height / units::isq::time);
|
||||
QUANTITY_SPEC(rate_of_climb_speed, mp_units::isq::height / mp_units::isq::time);
|
||||
|
||||
// length
|
||||
using distance = units::quantity<units::isq::distance[units::si::kilo<units::si::metre>]>;
|
||||
using height = units::quantity<units::isq::height[units::si::metre]>;
|
||||
using altitude = units::quantity_point<units::isq::altitude[units::si::metre], mean_sea_level>;
|
||||
using distance = mp_units::quantity<mp_units::isq::distance[mp_units::si::kilo<mp_units::si::metre>]>;
|
||||
using height = mp_units::quantity<mp_units::isq::height[mp_units::si::metre]>;
|
||||
using altitude = mp_units::quantity_point<mp_units::isq::altitude[mp_units::si::metre], mean_sea_level>;
|
||||
|
||||
// time
|
||||
using duration = units::quantity<units::isq::duration[units::si::second]>;
|
||||
using timestamp =
|
||||
units::quantity_point<units::isq::time[units::si::second], units::chrono_point_origin<std::chrono::system_clock>{}>;
|
||||
using duration = mp_units::quantity<mp_units::isq::duration[mp_units::si::second]>;
|
||||
using timestamp = mp_units::quantity_point<mp_units::isq::time[mp_units::si::second],
|
||||
mp_units::chrono_point_origin<std::chrono::system_clock>{}>;
|
||||
|
||||
// speed
|
||||
using velocity = units::quantity<units::isq::speed[units::si::kilo<units::si::metre> / units::si::hour]>;
|
||||
using rate_of_climb = units::quantity<rate_of_climb_speed[units::si::metre / units::si::second]>;
|
||||
using velocity = mp_units::quantity<mp_units::isq::speed[mp_units::si::kilo<mp_units::si::metre> / mp_units::si::hour]>;
|
||||
using rate_of_climb = mp_units::quantity<rate_of_climb_speed[mp_units::si::metre / mp_units::si::second]>;
|
||||
|
||||
// text output
|
||||
template<class CharT, class Traits>
|
||||
@@ -83,11 +83,11 @@ std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>&
|
||||
|
||||
template<>
|
||||
struct STD_FMT::formatter<glide_computer::altitude> :
|
||||
formatter<units::quantity<units::isq::altitude[units::si::metre]>> {
|
||||
formatter<mp_units::quantity<mp_units::isq::altitude[mp_units::si::metre]>> {
|
||||
template<typename FormatContext>
|
||||
auto format(const glide_computer::altitude& a, FormatContext& ctx)
|
||||
{
|
||||
formatter<units::quantity<units::isq::altitude[units::si::metre]>>::format(a.absolute(), ctx);
|
||||
formatter<mp_units::quantity<mp_units::isq::altitude[mp_units::si::metre]>>::format(a.absolute(), ctx);
|
||||
return STD_FMT::format_to(ctx.out(), " AMSL");
|
||||
}
|
||||
};
|
||||
@@ -105,7 +105,7 @@ struct glider {
|
||||
std::array<polar_point, 1> polar;
|
||||
};
|
||||
|
||||
constexpr units::weak_quantity_of<units::dimensionless> auto glide_ratio(const glider::polar_point& polar)
|
||||
constexpr mp_units::weak_quantity_of<mp_units::dimensionless> auto glide_ratio(const glider::polar_point& polar)
|
||||
{
|
||||
return polar.v / -polar.climb;
|
||||
}
|
||||
@@ -193,10 +193,11 @@ altitude terrain_level_alt(const task& t, const flight_point& pos);
|
||||
|
||||
constexpr height agl(altitude glider_alt, altitude terrain_level) { return glider_alt - terrain_level; }
|
||||
|
||||
inline units::quantity<units::isq::length[units::si::kilo<units::si::metre>]> length_3d(distance dist, height h)
|
||||
inline mp_units::quantity<mp_units::isq::length[mp_units::si::kilo<mp_units::si::metre>]> length_3d(distance dist,
|
||||
height h)
|
||||
{
|
||||
// TODO Should we be able to calculate this on quantity of different kinds? What to return?
|
||||
return hypot(quantity_cast<units::isq::length>(dist), quantity_cast<units::isq::length>(h));
|
||||
return hypot(quantity_cast<mp_units::isq::length>(dist), quantity_cast<mp_units::isq::length>(h));
|
||||
}
|
||||
|
||||
distance glide_distance(const flight_point& pos, const glider& g, const task& t, const safety& s, altitude ground_alt);
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "glide_computer.h"
|
||||
#include <units/bits/fmt_hacks.h>
|
||||
#include <units/chrono.h>
|
||||
#include <units/systems/international/international.h>
|
||||
#include <units/math.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/bits/fmt_hacks.h>
|
||||
#include <mp_units/chrono.h>
|
||||
#include <mp_units/math.h>
|
||||
#include <mp_units/systems/international/international.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@@ -38,11 +38,11 @@ namespace {
|
||||
|
||||
using namespace glide_computer;
|
||||
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
auto get_gliders()
|
||||
{
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||
static const std::array gliders = {
|
||||
@@ -56,7 +56,7 @@ auto get_gliders()
|
||||
|
||||
auto get_weather_conditions()
|
||||
{
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
static const std::array weather_conditions = {
|
||||
std::pair{"Good", weather{1900 * isq::height[m], 4.3 * rate_of_climb_speed[m / s]}},
|
||||
std::pair{"Medium", weather{1550 * isq::height[m], 2.8 * rate_of_climb_speed[m / s]}},
|
||||
@@ -67,7 +67,7 @@ auto get_weather_conditions()
|
||||
auto get_waypoints()
|
||||
{
|
||||
using namespace geographic::literals;
|
||||
using namespace units::international::unit_symbols;
|
||||
using namespace mp_units::international::unit_symbols;
|
||||
static const std::array waypoints = {
|
||||
waypoint{"EPPR", {54.24772_N, 18.6745_E}, altitude{16. * isq::altitude[ft]}}, // N54°14'51.8" E18°40'28.2"
|
||||
waypoint{"EPGI", {53.52442_N, 18.84947_E}, altitude{115. * isq::altitude[ft]}} // N53°31'27.9" E18°50'58.1"
|
||||
@@ -157,7 +157,7 @@ void print(const aircraft_tow& tow)
|
||||
|
||||
void example()
|
||||
{
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
|
||||
const safety sfty = {300 * isq::height[m]};
|
||||
const auto gliders = get_gliders();
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/format.h>
|
||||
#include <units/systems/international/international.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/quantity_io.h>
|
||||
#include <mp_units/systems/international/international.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
constexpr quantity_of<isq::speed> auto avg_speed(quantity_of<isq::distance> auto d, quantity_of<isq::duration> auto t)
|
||||
{
|
||||
@@ -36,8 +36,8 @@ constexpr quantity_of<isq::speed> auto avg_speed(quantity_of<isq::distance> auto
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace units::international::unit_symbols;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
using namespace mp_units::international::unit_symbols;
|
||||
|
||||
constexpr auto v1 = isq::speed(110, km / h);
|
||||
constexpr auto v2 = isq::speed(70., mph);
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "validated_type.h"
|
||||
#include <units/bits/external/hacks.h>
|
||||
#include <units/customization_points.h>
|
||||
#include <mp_units/bits/external/hacks.h>
|
||||
#include <mp_units/customization_points.h>
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
};
|
||||
|
||||
template<typename T, auto Min, auto Max>
|
||||
inline constexpr bool units::is_scalar<ranged_representation<T, Min, Max>> = units::is_scalar<T>;
|
||||
inline constexpr bool mp_units::is_scalar<ranged_representation<T, Min, Max>> = mp_units::is_scalar<T>;
|
||||
|
||||
template<typename T, auto Min, auto Max>
|
||||
struct std::common_type<std::intmax_t, ranged_representation<T, Min, Max>> :
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <gsl/gsl-lite.hpp>
|
||||
#include <units/bits/external/hacks.h>
|
||||
#include <mp_units/bits/external/hacks.h>
|
||||
#include <utility>
|
||||
|
||||
inline constexpr struct validated_tag {
|
||||
|
||||
@@ -22,28 +22,28 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <units/bits/fmt_hacks.h>
|
||||
#include <units/format.h>
|
||||
#include <units/math.h>
|
||||
#include <units/quantity.h>
|
||||
#include <units/quantity_point.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/bits/fmt_hacks.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/math.h>
|
||||
#include <mp_units/quantity.h>
|
||||
#include <mp_units/quantity_point.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <tuple>
|
||||
|
||||
namespace kalman {
|
||||
|
||||
template<typename T>
|
||||
concept QuantityOrQuantityPoint = units::Quantity<T> || units::QuantityPoint<T>;
|
||||
concept QuantityOrQuantityPoint = mp_units::Quantity<T> || mp_units::QuantityPoint<T>;
|
||||
|
||||
template<units::Dimension auto... Ds>
|
||||
template<mp_units::Dimension auto... Ds>
|
||||
inline constexpr bool are_time_derivatives = false;
|
||||
|
||||
template<units::Dimension auto D>
|
||||
template<mp_units::Dimension auto D>
|
||||
inline constexpr bool are_time_derivatives<D> = true;
|
||||
|
||||
template<units::Dimension auto D1, units::Dimension auto D2, units::Dimension auto... Ds>
|
||||
template<mp_units::Dimension auto D1, mp_units::Dimension auto D2, mp_units::Dimension auto... Ds>
|
||||
inline constexpr bool are_time_derivatives<D1, D2, Ds...> =
|
||||
(D1 / D2 == units::isq::dim_time) && are_time_derivatives<D2, Ds...>;
|
||||
(D1 / D2 == mp_units::isq::dim_time) && are_time_derivatives<D2, Ds...>;
|
||||
|
||||
// state
|
||||
template<QuantityOrQuantityPoint... QQPs>
|
||||
@@ -54,7 +54,7 @@ struct state {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
concept State = units::is_specialization_of<T, state>;
|
||||
concept State = mp_units::is_specialization_of<T, state>;
|
||||
|
||||
template<std::size_t Idx, typename... Qs>
|
||||
constexpr auto& get(state<Qs...>& s)
|
||||
@@ -73,7 +73,7 @@ template<QuantityOrQuantityPoint QQP, QuantityOrQuantityPoint... QQPs>
|
||||
struct estimation {
|
||||
private:
|
||||
static constexpr auto uncertainty_ref = QQP::reference * QQP::reference;
|
||||
using uncertainty_type = units::quantity<uncertainty_ref, typename QQP::rep>;
|
||||
using uncertainty_type = mp_units::quantity<uncertainty_ref, typename QQP::rep>;
|
||||
public:
|
||||
kalman::state<QQP, QQPs...> state; // TODO extend kalman functions to work with this variadic parameter list
|
||||
uncertainty_type uncertainty;
|
||||
@@ -81,29 +81,29 @@ public:
|
||||
|
||||
#if UNITS_COMP_CLANG <= 14
|
||||
|
||||
template<QuantityOrQuantityPoint QQP, units::Quantity U>
|
||||
template<QuantityOrQuantityPoint QQP, mp_units::Quantity U>
|
||||
estimation(state<QQP>, U) -> estimation<QQP>;
|
||||
|
||||
#endif
|
||||
|
||||
// kalman gain
|
||||
template<units::Quantity Q>
|
||||
constexpr units::quantity<units::dimensionless[units::one]> kalman_gain(Q estimate_uncertainty,
|
||||
Q measurement_uncertainty)
|
||||
template<mp_units::Quantity Q>
|
||||
constexpr mp_units::quantity<mp_units::dimensionless[mp_units::one]> kalman_gain(Q estimate_uncertainty,
|
||||
Q measurement_uncertainty)
|
||||
{
|
||||
return estimate_uncertainty / (estimate_uncertainty + measurement_uncertainty);
|
||||
}
|
||||
|
||||
// state update
|
||||
template<typename Q, QuantityOrQuantityPoint QM, units::quantity_of<units::dimensionless> K>
|
||||
template<typename Q, QuantityOrQuantityPoint QM, mp_units::quantity_of<mp_units::dimensionless> K>
|
||||
requires(Q::quantity_spec == QM::quantity_spec)
|
||||
constexpr state<Q> state_update(const state<Q>& predicted, QM measured, K gain)
|
||||
{
|
||||
return {get<0>(predicted) + gain * (measured - get<0>(predicted))};
|
||||
}
|
||||
|
||||
template<typename Q1, typename Q2, QuantityOrQuantityPoint QM, units::quantity_of<units::dimensionless> K,
|
||||
units::quantity_of<units::isq::time> T>
|
||||
template<typename Q1, typename Q2, QuantityOrQuantityPoint QM, mp_units::quantity_of<mp_units::dimensionless> K,
|
||||
mp_units::quantity_of<mp_units::isq::time> T>
|
||||
requires(Q1::quantity_spec == QM::quantity_spec)
|
||||
constexpr state<Q1, Q2> state_update(const state<Q1, Q2>& predicted, QM measured, std::array<K, 2> gain, T interval)
|
||||
{
|
||||
@@ -112,8 +112,8 @@ constexpr state<Q1, Q2> state_update(const state<Q1, Q2>& predicted, QM measured
|
||||
return {q1, q2};
|
||||
}
|
||||
|
||||
template<typename Q1, typename Q2, typename Q3, QuantityOrQuantityPoint QM, units::quantity_of<units::dimensionless> K,
|
||||
units::quantity_of<units::isq::time> T>
|
||||
template<typename Q1, typename Q2, typename Q3, QuantityOrQuantityPoint QM,
|
||||
mp_units::quantity_of<mp_units::dimensionless> K, mp_units::quantity_of<mp_units::isq::time> T>
|
||||
requires(Q1::quantity_spec == QM::quantity_spec)
|
||||
constexpr state<Q1, Q2, Q3> state_update(const state<Q1, Q2, Q3>& predicted, QM measured, std::array<K, 3> gain,
|
||||
T interval)
|
||||
@@ -125,14 +125,14 @@ constexpr state<Q1, Q2, Q3> state_update(const state<Q1, Q2, Q3>& predicted, QM
|
||||
}
|
||||
|
||||
// covariance update
|
||||
template<units::Quantity Q, units::quantity_of<units::dimensionless> K>
|
||||
template<mp_units::Quantity Q, mp_units::quantity_of<mp_units::dimensionless> K>
|
||||
constexpr Q covariance_update(Q uncertainty, K gain)
|
||||
{
|
||||
return (1 - gain) * uncertainty;
|
||||
}
|
||||
|
||||
// state extrapolation
|
||||
template<typename Q1, typename Q2, units::quantity_of<units::isq::time> T>
|
||||
template<typename Q1, typename Q2, mp_units::quantity_of<mp_units::isq::time> T>
|
||||
constexpr state<Q1, Q2> state_extrapolation(const state<Q1, Q2>& estimated, T interval)
|
||||
{
|
||||
const auto q1 = get<0>(estimated) + get<1>(estimated) * interval;
|
||||
@@ -140,7 +140,7 @@ constexpr state<Q1, Q2> state_extrapolation(const state<Q1, Q2>& estimated, T in
|
||||
return {q1, q2};
|
||||
}
|
||||
|
||||
template<typename Q1, typename Q2, typename Q3, units::quantity_of<units::isq::time> T>
|
||||
template<typename Q1, typename Q2, typename Q3, mp_units::quantity_of<mp_units::isq::time> T>
|
||||
constexpr state<Q1, Q2, Q3> state_extrapolation(const state<Q1, Q2, Q3>& estimated, T interval)
|
||||
{
|
||||
const auto q1 = get<0>(estimated) + get<1>(estimated) * interval + get<2>(estimated) * pow<2>(interval) / 2;
|
||||
@@ -150,7 +150,7 @@ constexpr state<Q1, Q2, Q3> state_extrapolation(const state<Q1, Q2, Q3>& estimat
|
||||
}
|
||||
|
||||
// covariance extrapolation
|
||||
template<units::Quantity Q>
|
||||
template<mp_units::Quantity Q>
|
||||
constexpr Q covariance_extrapolation(Q uncertainty, Q process_noise_variance)
|
||||
{
|
||||
return uncertainty + process_noise_variance;
|
||||
@@ -162,8 +162,8 @@ template<typename... Qs>
|
||||
struct STD_FMT::formatter<kalman::state<Qs...>> {
|
||||
constexpr auto parse(format_parse_context& ctx)
|
||||
{
|
||||
units::detail::dynamic_specs_handler handler(specs, ctx);
|
||||
return units::detail::parse_format_specs(ctx.begin(), ctx.end(), handler);
|
||||
mp_units::detail::dynamic_specs_handler handler(specs, ctx);
|
||||
return mp_units::detail::parse_format_specs(ctx.begin(), ctx.end(), handler);
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
@@ -191,28 +191,28 @@ struct STD_FMT::formatter<kalman::state<Qs...>> {
|
||||
}
|
||||
|
||||
std::string global_format_buffer;
|
||||
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);
|
||||
mp_units::detail::quantity_global_format_specs<char> global_specs = {specs.fill, specs.align, specs.width};
|
||||
mp_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));
|
||||
}
|
||||
private:
|
||||
units::detail::dynamic_format_specs<char> specs;
|
||||
mp_units::detail::dynamic_format_specs<char> specs;
|
||||
};
|
||||
|
||||
template<typename Q>
|
||||
struct STD_FMT::formatter<kalman::estimation<Q>> {
|
||||
constexpr auto parse(format_parse_context& ctx)
|
||||
{
|
||||
units::detail::dynamic_specs_handler handler(specs, ctx);
|
||||
return units::detail::parse_format_specs(ctx.begin(), ctx.end(), handler);
|
||||
mp_units::detail::dynamic_specs_handler handler(specs, ctx);
|
||||
return mp_units::detail::parse_format_specs(ctx.begin(), ctx.end(), handler);
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(kalman::estimation<Q> e, FormatContext& ctx)
|
||||
{
|
||||
units::Quantity auto q = [](const Q& t) {
|
||||
if constexpr (units::Quantity<Q>)
|
||||
mp_units::Quantity auto q = [](const Q& t) {
|
||||
if constexpr (mp_units::Quantity<Q>)
|
||||
return t;
|
||||
else
|
||||
return t.relative();
|
||||
@@ -227,11 +227,11 @@ struct STD_FMT::formatter<kalman::estimation<Q>> {
|
||||
}
|
||||
|
||||
std::string global_format_buffer;
|
||||
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);
|
||||
mp_units::detail::quantity_global_format_specs<char> global_specs = {specs.fill, specs.align, specs.width};
|
||||
mp_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));
|
||||
}
|
||||
private:
|
||||
units::detail::dynamic_format_specs<char> specs;
|
||||
mp_units::detail::dynamic_format_specs<char> specs;
|
||||
};
|
||||
@@ -21,15 +21,15 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/format.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/alphabeta.html#ex1
|
||||
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
void print_header(const kalman::State auto& initial)
|
||||
{
|
||||
@@ -46,7 +46,7 @@ void print(auto iteration, quantity_of<dimensionless> auto gain, Quantity auto m
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
using state = kalman::state<quantity<isq::mass[g]>>;
|
||||
|
||||
const state initial = {1 * isq::mass[kg]};
|
||||
|
||||
@@ -21,19 +21,19 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/format.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/alphabeta.html#ex2
|
||||
|
||||
template<class T>
|
||||
requires units::is_scalar<T>
|
||||
inline constexpr bool units::is_vector<T> = true;
|
||||
requires mp_units::is_scalar<T>
|
||||
inline constexpr bool mp_units::is_vector<T> = true;
|
||||
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
void print_header(const kalman::State auto& initial)
|
||||
{
|
||||
@@ -48,7 +48,7 @@ void print(auto iteration, Quantity auto measured, const kalman::State auto& cur
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
using state = kalman::state<quantity<isq::position_vector[m]>, quantity<isq::velocity[m / s]>>;
|
||||
|
||||
const auto interval = 5 * isq::period_duration[s];
|
||||
|
||||
@@ -21,19 +21,19 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/format.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/alphabeta.html#ex3
|
||||
|
||||
template<class T>
|
||||
requires units::is_scalar<T>
|
||||
inline constexpr bool units::is_vector<T> = true;
|
||||
requires mp_units::is_scalar<T>
|
||||
inline constexpr bool mp_units::is_vector<T> = true;
|
||||
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
void print_header(const kalman::State auto& initial)
|
||||
{
|
||||
@@ -48,7 +48,7 @@ void print(auto iteration, Quantity auto measured, const kalman::State auto& cur
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
using state = kalman::state<quantity<isq::position_vector[m]>, quantity<isq::velocity[m / s]>>;
|
||||
|
||||
const auto interval = 5 * isq::period_duration[s];
|
||||
|
||||
@@ -21,19 +21,19 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/format.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/alphabeta.html#ex4
|
||||
|
||||
template<class T>
|
||||
requires units::is_scalar<T>
|
||||
inline constexpr bool units::is_vector<T> = true;
|
||||
requires mp_units::is_scalar<T>
|
||||
inline constexpr bool mp_units::is_vector<T> = true;
|
||||
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
void print_header(const kalman::State auto& initial)
|
||||
{
|
||||
@@ -48,7 +48,7 @@ void print(auto iteration, Quantity auto measured, const kalman::State auto& cur
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
using state = kalman::state<quantity<isq::position_vector[m]>, quantity<isq::velocity[m / s]>,
|
||||
quantity<isq::acceleration[m / s2]>>;
|
||||
const auto interval = 5. * isq::period_duration[s];
|
||||
|
||||
@@ -21,16 +21,16 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/format.h>
|
||||
#include <units/math.h>
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/math.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/kalman1d.html#ex5
|
||||
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
template<Quantity Q>
|
||||
void print_header(kalman::estimation<Q> initial)
|
||||
@@ -50,7 +50,7 @@ void print(auto iteration, K gain, Q measured, kalman::estimation<Q> current, ka
|
||||
int main()
|
||||
{
|
||||
using namespace kalman;
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
|
||||
const estimation initial = {state{60. * isq::height[m]}, pow<2>(15. * isq::height[m])};
|
||||
const std::array measurements = {48.54 * isq::height[m], 47.11 * isq::height[m], 55.01 * isq::height[m],
|
||||
|
||||
@@ -21,17 +21,17 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/format.h>
|
||||
#include <units/math.h>
|
||||
#include <units/quantity_point.h>
|
||||
#include <units/systems/isq/thermodynamics.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/math.h>
|
||||
#include <mp_units/quantity_point.h>
|
||||
#include <mp_units/systems/isq/thermodynamics.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/kalman1d.html#ex6
|
||||
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
template<QuantityPoint QP>
|
||||
void print_header(kalman::estimation<QP> initial)
|
||||
|
||||
@@ -21,17 +21,17 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/format.h>
|
||||
#include <units/math.h>
|
||||
#include <units/quantity_point.h>
|
||||
#include <units/systems/isq/thermodynamics.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/math.h>
|
||||
#include <mp_units/quantity_point.h>
|
||||
#include <mp_units/systems/isq/thermodynamics.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/kalman1d.html#ex7
|
||||
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
template<QuantityPoint QP>
|
||||
void print_header(kalman::estimation<QP> initial)
|
||||
|
||||
@@ -21,17 +21,17 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <units/format.h>
|
||||
#include <units/math.h>
|
||||
#include <units/quantity_point.h>
|
||||
#include <units/systems/isq/thermodynamics.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/math.h>
|
||||
#include <mp_units/quantity_point.h>
|
||||
#include <mp_units/systems/isq/thermodynamics.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/kalman1d.html#ex8
|
||||
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
template<QuantityPoint QP>
|
||||
void print_header(kalman::estimation<QP> initial)
|
||||
|
||||
+312
-226
@@ -22,11 +22,13 @@
|
||||
|
||||
#include <linear_algebra.hpp>
|
||||
// linear_algebra.hpp has to be included first otherwise the header will fail to compile!
|
||||
#include <units/format.h>
|
||||
#include <units/isq/mechanics.h>
|
||||
#include <units/isq/space_and_time.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <units/si/units.h>
|
||||
#include <mp_units/customization_points.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/quantity_io.h>
|
||||
#include <mp_units/systems/isq/mechanics.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/systems/si/units.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace STD_LA {
|
||||
@@ -57,170 +59,81 @@ std::ostream& operator<<(std::ostream& os, const matrix<ET, OT>& v)
|
||||
|
||||
} // namespace STD_LA
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace units;
|
||||
|
||||
template<typename Rep = double>
|
||||
using vector = std::math::fs_vector<Rep, 3>;
|
||||
|
||||
template<typename Rep = double>
|
||||
using matrix = std::math::fs_matrix<Rep, 3, 3>;
|
||||
template<typename Rep>
|
||||
inline constexpr bool mp_units::is_vector<vector<Rep>> = true;
|
||||
|
||||
constexpr auto mm = isq::length[si::milli<si::metre>];
|
||||
constexpr auto m = isq::length[si::metre];
|
||||
constexpr auto km = isq::length[si::kilo<si::metre>];
|
||||
constexpr auto N = isq::force[si::newton];
|
||||
namespace {
|
||||
|
||||
void vector_of_quantity_add()
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
|
||||
// template<typename Rep = double>
|
||||
// using matrix = std::math::fs_matrix<Rep, 3, 3>;
|
||||
|
||||
|
||||
// constexpr auto mm = isq::length[si::milli<si::metre>];
|
||||
// constexpr auto m = isq::length[si::metre];
|
||||
// constexpr auto km = isq::length[si::kilo<si::metre>];
|
||||
// constexpr auto N = isq::force[si::newton];
|
||||
|
||||
// template<Unit auto U = si::metre, Representation Rep = double>
|
||||
// using length_v = quantity<isq::length[U], vector<Rep>>;
|
||||
|
||||
// template<Unit auto U = si::newton, Representation Rep = double>
|
||||
// using force_v = quantity<isq::force[U], vector<Rep>>;
|
||||
|
||||
void quantity_of_vector_cast()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_add:\n";
|
||||
std::cout << "\nquantity_of_vector_cast:\n";
|
||||
|
||||
vector<quantity<m>> v = {1 * m, 2 * m, 3 * m};
|
||||
vector<quantity<m>> u = {3 * m, 2 * m, 1 * m};
|
||||
vector<quantity<km>> t = {3 * km, 2 * km, 1 * km};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
std::cout << "t = " << t << "\n";
|
||||
|
||||
std::cout << "v + u = " << v + u << "\n";
|
||||
std::cout << "v + t = " << v + t << "\n";
|
||||
std::cout << "t[m] = " << vector<quantity<m>>(t) << "\n";
|
||||
}
|
||||
|
||||
void vector_of_quantity_multiply_same()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_multiply_same:\n";
|
||||
|
||||
vector<quantity<m>> v = {1 * m, 2 * m, 3 * m};
|
||||
vector<quantity<m>> u = {3 * m, 2 * m, 1 * m};
|
||||
quantity<isq::position_vector[m], vector<int>> v{vector<int>{1001, 1002, 1003}};
|
||||
quantity<isq::position_vector[km], vector<int>> u{vector<int>{3, 2, 1}};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
|
||||
std::cout << "v * u = " << v * u << "\n";
|
||||
std::cout << "2 * m * v = " << 2. * m * v << "\n";
|
||||
std::cout << "v[km] = " << quantity_cast<km>(v) << "\n";
|
||||
std::cout << "u[m] = " << u[m] << "\n";
|
||||
}
|
||||
|
||||
void vector_of_quantity_multiply_different()
|
||||
void quantity_of_vector_multiply_by_scalar_value()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_multiply_different:\n";
|
||||
std::cout << "\nquantity_of_vector_multiply_scalar_value:\n";
|
||||
|
||||
vector<quantity<N>> v = {1 * N, 2 * N, 3 * N};
|
||||
vector<quantity<m>> u = {3 * m, 2 * m, 1 * m};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
|
||||
std::cout << "v * u = " << v * u << "\n";
|
||||
std::cout << "2 * N * u = " << 2. * N * u << "\n";
|
||||
std::cout << "2 * u = " << 2 * u << "\n";
|
||||
}
|
||||
|
||||
void vector_of_quantity_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_divide_by_scalar:\n";
|
||||
|
||||
vector<quantity<m>> v = {4 * m, 8 * m, 12 * m};
|
||||
quantity<isq::position_vector[m], vector<int>> v{vector<int>{1, 2, 3}};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
|
||||
// TODO Uncomment when bug in the LA is fixed
|
||||
// std::cout << "v / (2 * s) = " << v / (2 * s) << "\n";
|
||||
// std::cout << "v / 2 = " << v / 2 << "\n";
|
||||
std::cout << "2 * v = " << 2 * v << "\n";
|
||||
}
|
||||
|
||||
void vector_of_quantity_tests()
|
||||
void quantity_of_vector_divide_by_scalar_value()
|
||||
{
|
||||
vector_of_quantity_add();
|
||||
vector_of_quantity_multiply_same();
|
||||
vector_of_quantity_multiply_different();
|
||||
vector_of_quantity_divide_by_scalar();
|
||||
std::cout << "\nquantity_of_vector_divide_scalar_value:\n";
|
||||
|
||||
quantity<isq::position_vector[m], vector<int>> v{vector<int>{2, 4, 6}};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
|
||||
std::cout << "v / 2 = " << v / 2 << "\n";
|
||||
}
|
||||
|
||||
void matrix_of_quantity_add()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_add:\n";
|
||||
|
||||
matrix<quantity<m>> v = {{1 * m, 2 * m, 3 * m}, {4 * m, 5 * m, 6 * m}, {7 * m, 8 * m, 9 * m}};
|
||||
matrix<quantity<m>> u = {{3 * m, 2 * m, 1 * m}, {3 * m, 2 * m, 1 * m}, {3 * m, 2 * m, 1 * m}};
|
||||
matrix<quantity<mm>> 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";
|
||||
std::cout << "t =\n" << t << "\n";
|
||||
|
||||
std::cout << "v + u =\n" << v + u << "\n";
|
||||
std::cout << "v + t =\n" << v + t << "\n";
|
||||
|
||||
// TODO Uncomment when fixed in the LA lib
|
||||
// std::cout << "v[mm] =\n" << matrix<si::length<si::millimetre>>(v) << "\n";
|
||||
}
|
||||
|
||||
void matrix_of_quantity_multiply_same()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_multiply_same:\n";
|
||||
|
||||
matrix<quantity<m>> v = {{1 * m, 2 * m, 3 * m}, {4 * m, 5 * m, 6 * m}, {7 * m, 8 * m, 9 * m}};
|
||||
vector<quantity<m>> u = {3 * m, 2 * m, 1 * m};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
|
||||
std::cout << "v * u =\n" << v * u << "\n";
|
||||
std::cout << "2 * m * u =\n" << 2. * m * u << "\n";
|
||||
}
|
||||
|
||||
void matrix_of_quantity_multiply_different()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_multiply_different:\n";
|
||||
|
||||
vector<quantity<N>> v = {1 * N, 2 * N, 3 * N};
|
||||
matrix<quantity<m>> 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";
|
||||
|
||||
std::cout << "v * u =\n" << v * u << "\n";
|
||||
std::cout << "2 * N * u =\n" << 2. * N * u << "\n";
|
||||
std::cout << "2 * u =\n" << 2 * u << "\n";
|
||||
}
|
||||
|
||||
void matrix_of_quantity_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_divide_by_scalar:\n";
|
||||
|
||||
matrix<quantity<m>> 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";
|
||||
|
||||
// TODO Uncomment when bug in the LA is fixed
|
||||
// std::cout << "v / (2 * s) =\n" << v / (2 * s) << "\n";
|
||||
// std::cout << "v / 2 =\n" << v / 2 << "\n";
|
||||
}
|
||||
|
||||
void matrix_of_quantity_tests()
|
||||
{
|
||||
matrix_of_quantity_add();
|
||||
matrix_of_quantity_multiply_same();
|
||||
matrix_of_quantity_multiply_different();
|
||||
matrix_of_quantity_divide_by_scalar();
|
||||
}
|
||||
|
||||
template<Unit auto U = si::metre, Representation Rep = double>
|
||||
using length_v = quantity<isq::length[U], vector<Rep>>;
|
||||
|
||||
template<Unit auto U = si::newton, Representation Rep = double>
|
||||
using force_v = quantity<isq::force[U], vector<Rep>>;
|
||||
|
||||
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::kilo<si::metre>> t(vector<>{3, 2, 1});
|
||||
// TODO Does not compile (LA bug)
|
||||
// auto v = vector<int>{1, 2, 3} * isq::position_vector[m];
|
||||
// auto u = vector<int>{3, 2, 1} * isq::position_vector[m];
|
||||
// auto t = vector<int>{3, 2, 1} * isq::position_vector[km];
|
||||
|
||||
// quantity<isq::distance[m], vector<int>> v{vector<int>{1, 2, 3}}; // should not compile
|
||||
quantity<isq::position_vector[m], vector<int>> v{vector<int>{1, 2, 3}};
|
||||
quantity<isq::position_vector[m], vector<int>> u{vector<int>{3, 2, 1}};
|
||||
quantity<isq::position_vector[km], vector<int>> t{vector<int>{3, 2, 1}};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -228,137 +141,310 @@ void quantity_of_vector_add()
|
||||
|
||||
std::cout << "v + u = " << v + u << "\n";
|
||||
std::cout << "v + t = " << v + t << "\n";
|
||||
std::cout << "t[m] = " << quantity_cast<si::metre>(t) << "\n";
|
||||
}
|
||||
|
||||
void quantity_of_vector_multiply_same()
|
||||
void quantity_of_vector_subtract()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_multiply_same:\n";
|
||||
std::cout << "\nquantity_of_vector_subtract:\n";
|
||||
|
||||
length_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
quantity<isq::position_vector[m], vector<int>> v{vector<int>{1, 2, 3}};
|
||||
quantity<isq::position_vector[m], vector<int>> u{vector<int>{3, 2, 1}};
|
||||
quantity<isq::position_vector[km], vector<int>> t{vector<int>{3, 2, 1}};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
std::cout << "t = " << t << "\n";
|
||||
|
||||
std::cout << "v * u = " << v * u << "\n";
|
||||
std::cout << "2 * m * v = " << 2. * m * v << "\n";
|
||||
std::cout << "v - u = " << v - u << "\n";
|
||||
std::cout << "v - t = " << v - t << "\n";
|
||||
}
|
||||
|
||||
void quantity_of_vector_multiply_different()
|
||||
void quantity_of_vector_divide_by_scalar_quantity()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_multiply_different:\n";
|
||||
std::cout << "\nquantity_of_vector_divide_scalar:\n";
|
||||
|
||||
force_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
quantity<isq::position_vector[km], vector<int>> pos{vector<int>{30, 20, 10}};
|
||||
auto dur = 2 * isq::duration[h];
|
||||
quantity<isq::velocity[km / h], vector<int>> v = pos / dur;
|
||||
|
||||
std::cout << "pos = " << pos << "\n";
|
||||
std::cout << "dur = " << dur << "\n";
|
||||
|
||||
std::cout << "pos / dur = " << pos / dur << "\n";
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
|
||||
std::cout << "v * u = " << v * u << "\n";
|
||||
std::cout << "2 * N * u = " << 2. * N * u << "\n";
|
||||
std::cout << "2 * u = " << 2 * u << "\n";
|
||||
}
|
||||
|
||||
void quantity_of_vector_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_divide_by_scalar:\n";
|
||||
|
||||
length_v<> v(vector<>{4, 8, 12});
|
||||
// void quantity_of_vector_multiply_same()
|
||||
// {
|
||||
// std::cout << "\nquantity_of_vector_multiply_same:\n";
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
// length_v<> v(vector<>{1, 2, 3});
|
||||
// length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
// TODO Uncomment when bug in the LA is fixed
|
||||
// std::cout << "v / 2 * s = " << v / 2 * s << "\n";
|
||||
// std::cout << "v / 2 = " << v / 2 << "\n";
|
||||
}
|
||||
// std::cout << "v = " << v << "\n";
|
||||
// std::cout << "u = " << u << "\n";
|
||||
|
||||
// std::cout << "v * u = " << v * u << "\n";
|
||||
// std::cout << "2 * m * v = " << 2. * m * v << "\n";
|
||||
// }
|
||||
|
||||
// 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});
|
||||
|
||||
// std::cout << "v = " << v << "\n";
|
||||
// std::cout << "u = " << u << "\n";
|
||||
|
||||
// std::cout << "v * u = " << v * u << "\n";
|
||||
// std::cout << "2 * N * u = " << 2. * N * u << "\n";
|
||||
// std::cout << "2 * u = " << 2 * u << "\n";
|
||||
// }
|
||||
|
||||
// void quantity_of_vector_divide_by_scalar()
|
||||
// {
|
||||
// std::cout << "\nquantity_of_vector_divide_by_scalar:\n";
|
||||
|
||||
// length_v<> v(vector<>{4, 8, 12});
|
||||
|
||||
// std::cout << "v = " << v << "\n";
|
||||
|
||||
// // TODO Uncomment when bug in the LA is fixed
|
||||
// // std::cout << "v / 2 * s = " << v / 2 * s << "\n";
|
||||
// // std::cout << "v / 2 = " << v / 2 << "\n";
|
||||
// }
|
||||
|
||||
void quantity_of_vector_tests()
|
||||
{
|
||||
quantity_of_vector_cast();
|
||||
quantity_of_vector_multiply_by_scalar_value();
|
||||
quantity_of_vector_divide_by_scalar_value();
|
||||
quantity_of_vector_add();
|
||||
quantity_of_vector_multiply_same();
|
||||
quantity_of_vector_multiply_different();
|
||||
quantity_of_vector_divide_by_scalar();
|
||||
quantity_of_vector_subtract();
|
||||
quantity_of_vector_divide_by_scalar_quantity();
|
||||
// quantity_of_vector_multiply_same();
|
||||
// quantity_of_vector_multiply_different();
|
||||
// quantity_of_vector_divide_by_scalar();
|
||||
}
|
||||
|
||||
template<Unit auto U = si::metre, Representation Rep = double>
|
||||
using length_m = quantity<isq::length[U], matrix<Rep>>;
|
||||
// template<Unit auto U = si::metre, Representation Rep = double>
|
||||
// using length_m = quantity<isq::length[U], matrix<Rep>>;
|
||||
|
||||
void quantity_of_matrix_add()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_add:\n";
|
||||
// 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::kilo<si::metre>> 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::kilo<si::metre>> t(matrix<>{{3, 2, 1}, {3, 2, 1}, {3, 2, 1}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
std::cout << "t =\n" << t << "\n";
|
||||
// std::cout << "v =\n" << v << "\n";
|
||||
// std::cout << "u =\n" << u << "\n";
|
||||
// std::cout << "t =\n" << t << "\n";
|
||||
|
||||
std::cout << "v + u =\n" << v + u << "\n";
|
||||
std::cout << "v + t =\n" << v + t << "\n";
|
||||
// std::cout << "v + u =\n" << v + u << "\n";
|
||||
// std::cout << "v + t =\n" << v + t << "\n";
|
||||
|
||||
// TODO Uncomment when fixed in the LA lib
|
||||
// std::cout << "v[mm] =\n" << matrix<si::length<si::millimetre>>(v) << "\n";
|
||||
}
|
||||
// // TODO Uncomment when fixed in the LA lib
|
||||
// // std::cout << "v[mm] =\n" << matrix<si::length<si::millimetre>>(v) << "\n";
|
||||
// }
|
||||
|
||||
void quantity_of_matrix_multiply_same()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_multiply_same:\n";
|
||||
// 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";
|
||||
// std::cout << "v =\n" << v << "\n";
|
||||
// std::cout << "u =\n" << u << "\n";
|
||||
|
||||
std::cout << "v * u =\n" << v * u << "\n";
|
||||
std::cout << "2 * m * u =\n" << 2. * m * u << "\n";
|
||||
}
|
||||
// std::cout << "v * u =\n" << v * u << "\n";
|
||||
// std::cout << "2 * m * u =\n" << 2. * m * u << "\n";
|
||||
// }
|
||||
|
||||
void quantity_of_matrix_multiply_different()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_multiply_different:\n";
|
||||
// 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";
|
||||
// std::cout << "v =\n" << v << "\n";
|
||||
// std::cout << "u =\n" << u << "\n";
|
||||
|
||||
std::cout << "v * u =\n" << v * u << "\n";
|
||||
std::cout << "2 * N * u =\n" << 2. * N * u << "\n";
|
||||
std::cout << "2 * u =\n" << 2 * u << "\n";
|
||||
}
|
||||
// std::cout << "v * u =\n" << v * u << "\n";
|
||||
// std::cout << "2 * N * u =\n" << 2. * N * u << "\n";
|
||||
// std::cout << "2 * u =\n" << 2 * u << "\n";
|
||||
// }
|
||||
|
||||
void quantity_of_matrix_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_divide_by_scalar:\n";
|
||||
// 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";
|
||||
// std::cout << "v =\n" << v << "\n";
|
||||
|
||||
// TODO Uncomment when bug in the LA is fixed
|
||||
// std::cout << "v / (2 * s) =\n" << v / (2 * s) << "\n";
|
||||
// std::cout << "v / 2 =\n" << v / 2 << "\n";
|
||||
}
|
||||
// // TODO Uncomment when bug in the LA is fixed
|
||||
// // std::cout << "v / (2 * s) =\n" << v / (2 * s) << "\n";
|
||||
// // std::cout << "v / 2 =\n" << v / 2 << "\n";
|
||||
// }
|
||||
|
||||
void quantity_of_matrix_tests()
|
||||
{
|
||||
quantity_of_matrix_add();
|
||||
quantity_of_matrix_multiply_same();
|
||||
quantity_of_matrix_multiply_different();
|
||||
quantity_of_matrix_divide_by_scalar();
|
||||
}
|
||||
// void quantity_of_matrix_tests()
|
||||
// {
|
||||
// quantity_of_matrix_add();
|
||||
// quantity_of_matrix_multiply_same();
|
||||
// quantity_of_matrix_multiply_different();
|
||||
// quantity_of_matrix_divide_by_scalar();
|
||||
// }
|
||||
|
||||
|
||||
// void vector_of_quantity_add()
|
||||
// {
|
||||
// std::cout << "\nvector_of_quantity_add:\n";
|
||||
|
||||
// vector<quantity<m>> v = {1 * m, 2 * m, 3 * m};
|
||||
// vector<quantity<m>> u = {3 * m, 2 * m, 1 * m};
|
||||
// vector<quantity<km>> t = {3 * km, 2 * km, 1 * km};
|
||||
|
||||
// std::cout << "v = " << v << "\n";
|
||||
// std::cout << "u = " << u << "\n";
|
||||
// std::cout << "t = " << t << "\n";
|
||||
|
||||
// std::cout << "v + u = " << v + u << "\n";
|
||||
// std::cout << "v + t = " << v + t << "\n";
|
||||
// std::cout << "t[m] = " << vector<quantity<m>>(t) << "\n";
|
||||
// }
|
||||
|
||||
// void vector_of_quantity_multiply_same()
|
||||
// {
|
||||
// std::cout << "\nvector_of_quantity_multiply_same:\n";
|
||||
|
||||
// vector<quantity<m>> v = {1 * m, 2 * m, 3 * m};
|
||||
// vector<quantity<m>> u = {3 * m, 2 * m, 1 * m};
|
||||
|
||||
// std::cout << "v = " << v << "\n";
|
||||
// std::cout << "u = " << u << "\n";
|
||||
|
||||
// std::cout << "v * u = " << v * u << "\n";
|
||||
// std::cout << "2 * m * v = " << 2. * m * v << "\n";
|
||||
// }
|
||||
|
||||
// void vector_of_quantity_multiply_different()
|
||||
// {
|
||||
// std::cout << "\nvector_of_quantity_multiply_different:\n";
|
||||
|
||||
// vector<quantity<N>> v = {1 * N, 2 * N, 3 * N};
|
||||
// vector<quantity<m>> u = {3 * m, 2 * m, 1 * m};
|
||||
|
||||
// std::cout << "v = " << v << "\n";
|
||||
// std::cout << "u = " << u << "\n";
|
||||
|
||||
// std::cout << "v * u = " << v * u << "\n";
|
||||
// std::cout << "2 * N * u = " << 2. * N * u << "\n";
|
||||
// std::cout << "2 * u = " << 2 * u << "\n";
|
||||
// }
|
||||
|
||||
// void vector_of_quantity_divide_by_scalar()
|
||||
// {
|
||||
// std::cout << "\nvector_of_quantity_divide_by_scalar:\n";
|
||||
|
||||
// vector<quantity<m>> v = {4 * m, 8 * m, 12 * m};
|
||||
|
||||
// std::cout << "v = " << v << "\n";
|
||||
|
||||
// // TODO Uncomment when bug in the LA is fixed
|
||||
// // std::cout << "v / (2 * s) = " << v / (2 * s) << "\n";
|
||||
// // std::cout << "v / 2 = " << v / 2 << "\n";
|
||||
// }
|
||||
|
||||
// void vector_of_quantity_tests()
|
||||
// {
|
||||
// vector_of_quantity_add();
|
||||
// vector_of_quantity_multiply_same();
|
||||
// vector_of_quantity_multiply_different();
|
||||
// vector_of_quantity_divide_by_scalar();
|
||||
// }
|
||||
|
||||
// void matrix_of_quantity_add()
|
||||
// {
|
||||
// std::cout << "\nmatrix_of_quantity_add:\n";
|
||||
|
||||
// matrix<quantity<m>> v = {{1 * m, 2 * m, 3 * m}, {4 * m, 5 * m, 6 * m}, {7 * m, 8 * m, 9 * m}};
|
||||
// matrix<quantity<m>> u = {{3 * m, 2 * m, 1 * m}, {3 * m, 2 * m, 1 * m}, {3 * m, 2 * m, 1 * m}};
|
||||
// matrix<quantity<mm>> 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";
|
||||
// std::cout << "t =\n" << t << "\n";
|
||||
|
||||
// std::cout << "v + u =\n" << v + u << "\n";
|
||||
// std::cout << "v + t =\n" << v + t << "\n";
|
||||
|
||||
// // TODO Uncomment when fixed in the LA lib
|
||||
// // std::cout << "v[mm] =\n" << matrix<si::length<si::millimetre>>(v) << "\n";
|
||||
// }
|
||||
|
||||
// void matrix_of_quantity_multiply_same()
|
||||
// {
|
||||
// std::cout << "\nmatrix_of_quantity_multiply_same:\n";
|
||||
|
||||
// matrix<quantity<m>> v = {{1 * m, 2 * m, 3 * m}, {4 * m, 5 * m, 6 * m}, {7 * m, 8 * m, 9 * m}};
|
||||
// vector<quantity<m>> u = {3 * m, 2 * m, 1 * m};
|
||||
|
||||
// std::cout << "v =\n" << v << "\n";
|
||||
// std::cout << "u =\n" << u << "\n";
|
||||
|
||||
// std::cout << "v * u =\n" << v * u << "\n";
|
||||
// std::cout << "2 * m * u =\n" << 2. * m * u << "\n";
|
||||
// }
|
||||
|
||||
// void matrix_of_quantity_multiply_different()
|
||||
// {
|
||||
// std::cout << "\nmatrix_of_quantity_multiply_different:\n";
|
||||
|
||||
// vector<quantity<N>> v = {1 * N, 2 * N, 3 * N};
|
||||
// matrix<quantity<m>> 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";
|
||||
|
||||
// std::cout << "v * u =\n" << v * u << "\n";
|
||||
// std::cout << "2 * N * u =\n" << 2. * N * u << "\n";
|
||||
// std::cout << "2 * u =\n" << 2 * u << "\n";
|
||||
// }
|
||||
|
||||
// void matrix_of_quantity_divide_by_scalar()
|
||||
// {
|
||||
// std::cout << "\nmatrix_of_quantity_divide_by_scalar:\n";
|
||||
|
||||
// matrix<quantity<m>> 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";
|
||||
|
||||
// // TODO Uncomment when bug in the LA is fixed
|
||||
// // std::cout << "v / (2 * s) =\n" << v / (2 * s) << "\n";
|
||||
// // std::cout << "v / 2 =\n" << v / 2 << "\n";
|
||||
// }
|
||||
|
||||
// void matrix_of_quantity_tests()
|
||||
// {
|
||||
// matrix_of_quantity_add();
|
||||
// matrix_of_quantity_multiply_same();
|
||||
// matrix_of_quantity_multiply_different();
|
||||
// matrix_of_quantity_divide_by_scalar();
|
||||
// }
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
vector_of_quantity_tests();
|
||||
matrix_of_quantity_tests();
|
||||
quantity_of_vector_tests();
|
||||
quantity_of_matrix_tests();
|
||||
// quantity_of_matrix_tests();
|
||||
// vector_of_quantity_tests();
|
||||
// matrix_of_quantity_tests();
|
||||
}
|
||||
@@ -20,10 +20,10 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/systems/isq/space_and_time.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <units/systems/si/units.h>
|
||||
#include <mp_units/quantity_io.h>
|
||||
#include <mp_units/systems/isq/space_and_time.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/systems/si/units.h>
|
||||
#include <cmath>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@@ -118,18 +118,18 @@ private:
|
||||
} // namespace
|
||||
|
||||
template<class T>
|
||||
inline constexpr bool units::is_scalar<measurement<T>> = true;
|
||||
inline constexpr bool mp_units::is_scalar<measurement<T>> = true;
|
||||
template<class T>
|
||||
inline constexpr bool units::is_vector<measurement<T>> = true;
|
||||
inline constexpr bool mp_units::is_vector<measurement<T>> = true;
|
||||
|
||||
static_assert(units::RepresentationOf<measurement<double>, units::quantity_character::scalar>);
|
||||
static_assert(mp_units::RepresentationOf<measurement<double>, mp_units::quantity_character::scalar>);
|
||||
|
||||
namespace {
|
||||
|
||||
void example()
|
||||
{
|
||||
using namespace units;
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
|
||||
const auto a = isq::acceleration(measurement{9.8, 0.1}, m / s2);
|
||||
const auto t = isq::time(measurement{1.2, 0.1}, s);
|
||||
|
||||
@@ -20,19 +20,19 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/format.h>
|
||||
#include <units/systems/si/constants.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/format.h>
|
||||
#include <mp_units/systems/si/constants.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <iostream>
|
||||
|
||||
template<class T>
|
||||
requires units::is_scalar<T>
|
||||
inline constexpr bool units::is_vector<T> = true;
|
||||
requires mp_units::is_scalar<T>
|
||||
inline constexpr bool mp_units::is_vector<T> = true;
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace units::si;
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units::si;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
|
||||
std::cout << "The seven defining constants of the SI and the seven corresponding units they define:\n";
|
||||
std::cout << STD_FMT::format("- hyperfine transition frequency of Cs: {} = {:%.0Q %q}\n",
|
||||
|
||||
@@ -20,23 +20,23 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/math.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <units/systems/isq_angle/isq_angle.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/math.h>
|
||||
#include <mp_units/quantity_io.h>
|
||||
#include <mp_units/systems/isq_angle/isq_angle.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <iostream>
|
||||
|
||||
template<class T>
|
||||
requires units::is_scalar<T>
|
||||
inline constexpr bool units::is_vector<T> = true;
|
||||
requires mp_units::is_scalar<T>
|
||||
inline constexpr bool mp_units::is_vector<T> = true;
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace units;
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace units::angular::unit_symbols;
|
||||
using units::angular::unit_symbols::deg;
|
||||
using units::angular::unit_symbols::rad;
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
using namespace mp_units::angular::unit_symbols;
|
||||
using mp_units::angular::unit_symbols::deg;
|
||||
using mp_units::angular::unit_symbols::rad;
|
||||
|
||||
const auto lever = isq_angle::position_vector[cm](20);
|
||||
const auto force = isq_angle::force[N](500);
|
||||
|
||||
+12
-12
@@ -20,22 +20,22 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/math.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <units/systems/isq/mechanics.h>
|
||||
#include <units/systems/natural/natural.h>
|
||||
#include <units/systems/si/constants.h>
|
||||
#include <units/systems/si/unit_symbols.h>
|
||||
#include <mp_units/math.h>
|
||||
#include <mp_units/quantity_io.h>
|
||||
#include <mp_units/systems/isq/mechanics.h>
|
||||
#include <mp_units/systems/natural/natural.h>
|
||||
#include <mp_units/systems/si/constants.h>
|
||||
#include <mp_units/systems/si/unit_symbols.h>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
template<class T>
|
||||
requires units::is_scalar<T>
|
||||
inline constexpr bool units::is_vector<T> = true;
|
||||
requires mp_units::is_scalar<T>
|
||||
inline constexpr bool mp_units::is_vector<T> = true;
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace units;
|
||||
using namespace mp_units;
|
||||
|
||||
quantity_of<isq::mechanical_energy> auto total_energy(weak_quantity_of<isq::momentum> auto p,
|
||||
weak_quantity_of<isq::mass> auto m,
|
||||
@@ -46,7 +46,7 @@ quantity_of<isq::mechanical_energy> auto total_energy(weak_quantity_of<isq::mome
|
||||
|
||||
void si_example()
|
||||
{
|
||||
using namespace units::si::unit_symbols;
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
constexpr auto GeV = si::giga<si::electronvolt>;
|
||||
|
||||
constexpr quantity_of<isq::speed> auto c = si::si2019::speed_of_light_in_vacuum(1.);
|
||||
@@ -85,8 +85,8 @@ void si_example()
|
||||
|
||||
void natural_example()
|
||||
{
|
||||
using namespace units::natural;
|
||||
using namespace units::natural::unit_symbols;
|
||||
using namespace mp_units::natural;
|
||||
using namespace mp_units::natural::unit_symbols;
|
||||
|
||||
constexpr quantity_of<isq::speed> auto c = 1. * speed_of_light_in_vacuum;
|
||||
const quantity_of<isq::momentum> auto p = 4. * momentum[GeV];
|
||||
|
||||
Reference in new issue
Block a user