Trying to fix specialization before instantiation error
This commit is contained in:
parent
47ba024619
commit
52de55d7d0
178
Angle.cpp
178
Angle.cpp
@ -11,98 +11,12 @@ const float Deg2Rad = 0.0174532924F;
|
|||||||
|
|
||||||
//----------------------
|
//----------------------
|
||||||
|
|
||||||
//===== AngleSingle, AngleOf<float>
|
|
||||||
|
|
||||||
template <> AngleOf<float> AngleOf<float>::Degrees(float degrees) {
|
|
||||||
if (isfinite(degrees)) {
|
|
||||||
while (degrees < -180)
|
|
||||||
degrees += 360;
|
|
||||||
while (degrees >= 180)
|
|
||||||
degrees -= 360;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Binary(degrees);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <> AngleOf<float> AngleOf<float>::Radians(float radians) {
|
|
||||||
if (isfinite(radians)) {
|
|
||||||
while (radians <= -pi)
|
|
||||||
radians += 2 * pi;
|
|
||||||
while (radians > pi)
|
|
||||||
radians -= 2 * pi;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Binary(radians * Rad2Deg);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <> float AngleOf<float>::InDegrees() const { return this->value; }
|
|
||||||
|
|
||||||
template <> float AngleOf<float>::InRadians() const {
|
|
||||||
return this->value * Deg2Rad;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===== Angle16, AngleOf<signed short>
|
|
||||||
|
|
||||||
template <>
|
|
||||||
AngleOf<signed short> AngleOf<signed short>::Degrees(float degrees) {
|
|
||||||
// map float [-180..180) to integer [-32768..32767]
|
|
||||||
signed short value = (signed short)roundf(degrees / 360.0F * 65536.0F);
|
|
||||||
return Binary(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
AngleOf<signed short> AngleOf<signed short>::Radians(float radians) {
|
|
||||||
if (!isfinite(radians))
|
|
||||||
return AngleOf<signed short>::zero;
|
|
||||||
|
|
||||||
// map float [-PI..PI) to integer [-32768..32767]
|
|
||||||
signed short value = (signed short)roundf(radians / pi * 32768.0F);
|
|
||||||
return Binary(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <> float AngleOf<signed short>::InDegrees() const {
|
|
||||||
float degrees = this->value / 65536.0f * 360.0f;
|
|
||||||
return degrees;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <> float AngleOf<signed short>::InRadians() const {
|
|
||||||
float radians = this->value / 65536.0f * (2 * pi);
|
|
||||||
return radians;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===== Angle8, AngleOf<signed char>
|
|
||||||
|
|
||||||
template <> AngleOf<signed char> AngleOf<signed char>::Degrees(float degrees) {
|
|
||||||
// map float [-180..180) to integer [-128..127)
|
|
||||||
signed char value = (signed char)roundf(degrees / 360.0F * 256.0F);
|
|
||||||
return Binary(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <> AngleOf<signed char> AngleOf<signed char>::Radians(float radians) {
|
|
||||||
if (!isfinite(radians))
|
|
||||||
return AngleOf<signed char>::zero;
|
|
||||||
|
|
||||||
// map float [-pi..pi) to integer [-128..127)
|
|
||||||
signed char value = (signed char)roundf(radians / pi * 128.0f);
|
|
||||||
return Binary(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <> float AngleOf<signed char>::InDegrees() const {
|
|
||||||
float degrees = this->value / 256.0f * 360.0f;
|
|
||||||
return degrees;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <> float AngleOf<signed char>::InRadians() const {
|
|
||||||
float radians = this->value / 128.0f * pi;
|
|
||||||
return radians;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===== Generic
|
|
||||||
|
|
||||||
template <typename T> AngleOf<T>::AngleOf() : value(0) {}
|
template <typename T> AngleOf<T>::AngleOf() : value(0) {}
|
||||||
|
|
||||||
template <typename T> const AngleOf<T> AngleOf<T>::zero = AngleOf<T>();
|
template <typename T> const AngleOf<T> AngleOf<T>::zero = AngleOf<T>();
|
||||||
|
|
||||||
|
//===== Generic
|
||||||
|
|
||||||
template <typename T> AngleOf<T> AngleOf<T>::Binary(T rawValue) {
|
template <typename T> AngleOf<T> AngleOf<T>::Binary(T rawValue) {
|
||||||
AngleOf<T> angle = AngleOf<T>();
|
AngleOf<T> angle = AngleOf<T>();
|
||||||
angle.SetBinary(rawValue);
|
angle.SetBinary(rawValue);
|
||||||
@ -356,4 +270,90 @@ AngleOf<T> AngleOf<T>::SineRuleAngle(float a, AngleOf<T> beta, float b) {
|
|||||||
|
|
||||||
template class AngleOf<float>;
|
template class AngleOf<float>;
|
||||||
template class AngleOf<signed char>;
|
template class AngleOf<signed char>;
|
||||||
template class AngleOf<signed short>;
|
template class AngleOf<signed short>;
|
||||||
|
|
||||||
|
//===== AngleSingle, AngleOf<float>
|
||||||
|
|
||||||
|
template <> AngleOf<float> AngleOf<float>::Degrees(float degrees) {
|
||||||
|
if (isfinite(degrees)) {
|
||||||
|
while (degrees < -180)
|
||||||
|
degrees += 360;
|
||||||
|
while (degrees >= 180)
|
||||||
|
degrees -= 360;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Binary(degrees);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> AngleOf<float> AngleOf<float>::Radians(float radians) {
|
||||||
|
if (isfinite(radians)) {
|
||||||
|
while (radians <= -pi)
|
||||||
|
radians += 2 * pi;
|
||||||
|
while (radians > pi)
|
||||||
|
radians -= 2 * pi;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Binary(radians * Rad2Deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> float AngleOf<float>::InDegrees() const { return this->value; }
|
||||||
|
|
||||||
|
template <> float AngleOf<float>::InRadians() const {
|
||||||
|
return this->value * Deg2Rad;
|
||||||
|
}
|
||||||
|
|
||||||
|
//===== Angle16, AngleOf<signed short>
|
||||||
|
|
||||||
|
template <>
|
||||||
|
AngleOf<signed short> AngleOf<signed short>::Degrees(float degrees) {
|
||||||
|
// map float [-180..180) to integer [-32768..32767]
|
||||||
|
signed short value = (signed short)roundf(degrees / 360.0F * 65536.0F);
|
||||||
|
return Binary(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
AngleOf<signed short> AngleOf<signed short>::Radians(float radians) {
|
||||||
|
if (!isfinite(radians))
|
||||||
|
return AngleOf<signed short>::zero;
|
||||||
|
|
||||||
|
// map float [-PI..PI) to integer [-32768..32767]
|
||||||
|
signed short value = (signed short)roundf(radians / pi * 32768.0F);
|
||||||
|
return Binary(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> float AngleOf<signed short>::InDegrees() const {
|
||||||
|
float degrees = this->value / 65536.0f * 360.0f;
|
||||||
|
return degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> float AngleOf<signed short>::InRadians() const {
|
||||||
|
float radians = this->value / 65536.0f * (2 * pi);
|
||||||
|
return radians;
|
||||||
|
}
|
||||||
|
|
||||||
|
//===== Angle8, AngleOf<signed char>
|
||||||
|
|
||||||
|
template <> AngleOf<signed char> AngleOf<signed char>::Degrees(float degrees) {
|
||||||
|
// map float [-180..180) to integer [-128..127)
|
||||||
|
signed char value = (signed char)roundf(degrees / 360.0F * 256.0F);
|
||||||
|
return Binary(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> AngleOf<signed char> AngleOf<signed char>::Radians(float radians) {
|
||||||
|
if (!isfinite(radians))
|
||||||
|
return AngleOf<signed char>::zero;
|
||||||
|
|
||||||
|
// map float [-pi..pi) to integer [-128..127)
|
||||||
|
signed char value = (signed char)roundf(radians / pi * 128.0f);
|
||||||
|
return Binary(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> float AngleOf<signed char>::InDegrees() const {
|
||||||
|
float degrees = this->value / 256.0f * 360.0f;
|
||||||
|
return degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> float AngleOf<signed char>::InRadians() const {
|
||||||
|
float radians = this->value / 128.0f * pi;
|
||||||
|
return radians;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user