Skip to content
Snippets Groups Projects
Commit 00b57387 authored by Alberto Nidasio's avatar Alberto Nidasio
Browse files

tmp

parent d33b4859
Branches
No related tags found
1 merge request!233Implement custom units
Pipeline #7454 failed
......@@ -34,10 +34,7 @@ namespace Angle
{
template <class Ratio = std::ratio<1>>
class Angle : public Unit<Ratio>
{
using Unit<Ratio>::Unit;
};
using Angle = Unit<UnitKind::Angle, Ratio>;
using Degree = Angle<>; // Angle in degrees
using Radian = // Angle in radians
......
......@@ -32,14 +32,20 @@ namespace Boardcore
namespace Units
{
template <class Ratio = std::ratio<1>>
enum class UnitKind
{
Angle,
Length
};
template <UnitKind Kind, class Ratio = std::ratio<1>>
// Base class to implement custom measurement units logic.
class Unit
{
public:
Unit(float val) : _value(val){};
template <class FromRatio>
constexpr explicit Unit(Unit<FromRatio> const &from)
constexpr explicit Unit(Unit<Kind, FromRatio> const &from)
: _value(from.template value<Ratio>())
{
}
......@@ -67,10 +73,11 @@ private:
};
// Sum, Subtraction, Multiplication, Division
template <class DerivedUnit>
constexpr auto operator+(const DerivedUnit &lhs, const DerivedUnit &rhs)
template <UnitKind Kind, class Ratio>
constexpr auto operator+(const Unit<Kind, Ratio> &lhs,
const Unit<Kind, Ratio> &rhs)
{
return DerivedUnit(lhs.template value() + rhs.template value());
return Unit(lhs.template value() + rhs.template value());
}
template <class DerivedUnit>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment