2019-12-17 10:48:54 +01:00
|
|
|
// The MIT License (MIT)
|
|
|
|
//
|
|
|
|
// Copyright (c) 2018 Mateusz Pusz
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
// SOFTWARE.
|
|
|
|
|
|
|
|
#include <units/physical/si/velocity.h>
|
2020-01-12 00:27:03 +00:00
|
|
|
#include <units/physical/international/velocity.h>
|
2019-12-17 10:48:54 +01:00
|
|
|
#include <units/format.h>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace units;
|
|
|
|
|
2019-12-17 10:51:59 +01:00
|
|
|
constexpr Velocity AUTO avg_speed(Length AUTO d, Time AUTO t)
|
2019-12-17 10:48:54 +01:00
|
|
|
{
|
|
|
|
return d / t;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
using namespace si::literals;
|
|
|
|
Velocity AUTO v1 = avg_speed(220km, 2h);
|
Split the various non-si length units into their own namespaces.
new namespaces are
international ( combination of us and imperial + Canada etc)
iau (https://www.iau.org/
imperial ( old imperial units)
typographical ( for sizes of printing fonts etc)
These namespace are based on some research , mainly on wikipedia.
Look in src/include/units/physical/si/length.h to see links to see the references to documentation justifying the change.
Unfortunately there are 3 foot units for example, an old imperial version, an old us version and an international version, which is more recent and attempts to unify the two previous ones. All versions have slight changes in value, so I opted to use the international version
The main change in the layout is that inch,foot and yard have been moved from us to international.
With this modification, I also modified the physical/us/area.hpp, volume.hpp and volume.hpp headers to refer to the international units.
This may not be correct, but if the modified us::foot (rather than international foot is used as a basis for these units, then
there is a ratio integer overflow during compilation, probably due to taking 3rd power of a ratio. After this commit. I will try to show that on another branch.
2020-01-10 02:03:27 +00:00
|
|
|
Velocity AUTO v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
|
2019-12-17 10:48:54 +01:00
|
|
|
Velocity AUTO v3 = quantity_cast<si::metre_per_second>(v2);
|
|
|
|
Velocity AUTO v4 = quantity_cast<int>(v3);
|
|
|
|
|
|
|
|
std::cout << v1 << '\n'; // 110 km/h
|
|
|
|
std::cout << fmt::format("{}", v2) << '\n'; // 70 mi/h
|
|
|
|
std::cout << fmt::format("{:%Q in %q}", v3) << '\n'; // 31.2928 in m/s
|
|
|
|
std::cout << fmt::format("{:%Q}", v4) << '\n'; // 31
|
|
|
|
}
|