I want the angle class to be initialized in radians or degrees, but I don't know if this is a good idea. I am thinking of something like this:

class Radian;
class Degree;
class Angle
{
private:
float m_radian;
public:
explicit Angle(const Radian& rad);
explicit Angle(const Degree& deg);
float GetRadian(void) const
{
return this->m_radian;
}
float GetDegree(void) const
{
return ToDegree(this->m_radian);
}
bool IsEqual(const Angle& angle, float epsilon = 0.001f) const
{
return Abs<float>(this->m_radian - angle.m_radian) < epsilon;
}
void Set(const Angle& ang);
protected:
Angle(void) : m_radian(0.0f)
{}
Angle(float rad) : m_radian(rad)
{}
};
class Radian : public Angle
{
public:
Radian(void)
{}
Radian(float r) : Angle(r)
{}
};
class Degree : public Angle
{
public:
Degree(void)
{}
Degree(float d) : Angle(ToRadian(d))
{}
};
float Sin(const Angle& angle);
...
This way, I will not confuse radians and degrees in my code. But is this a good idea, or should I use a different design?
source
share