deg2rad
Started writing up a thing using radians and degrees safely, interchangeably, and understandably. And then realised half of the assumptions were wrong. Note-taking:
Degrees and Radians ctors both take in the named unit (the Degrees float is degrees). Every other usage is rads, always.
struct Degrees {
float rads = 0.f;
Degrees(float degrees) /* should be fine */
: rads(to_radians(degrees))
{}
};
struct Radians {
float rads = 0.f;
Radians(float rads_) /* should be fine */
: rads(rads_)
{}
};
No implicit conversions for affecting their value, ever. Operators for neither should take in raw primitive types.
They should explicitly take in each other.
We still need an implicit conversion to be able to use these with data that is typed as float
. The prior explicit conversions are important because they should take precedent over this.
Usage:
Degrees rot1 = Degrees(45); /* Valid */
Degrees rot2 = Radians(PI) + Degrees(45); /* Valid */
rot1 += Degrees(45); /* Valid */
rot2 += 45.f; /* Invalid */
Possible addition but not really a fan, overload the dereference operator for radians.