Bug fix
This commit is contained in:
parent
3714507059
commit
0468031b4b
@ -4,6 +4,7 @@
|
||||
|
||||
#include "DiscreteAngle.h"
|
||||
|
||||
#include "Angle.h"
|
||||
#include <math.h>
|
||||
|
||||
template <> AngleUsing<unsigned char>::AngleUsing(unsigned char angle) {
|
||||
@ -12,19 +13,16 @@ template <> AngleUsing<unsigned char>::AngleUsing(unsigned char angle) {
|
||||
return;
|
||||
}
|
||||
|
||||
// clamp the float range to -1..1
|
||||
while (angle <= -180.0F)
|
||||
angle += 360.0F;
|
||||
while (angle > 180.0F)
|
||||
angle -= 360.0F;
|
||||
// normalize to (-180..180]
|
||||
angle = Angle::Normalize(angle);
|
||||
|
||||
// map (-180..180] to 1..256
|
||||
// map (-180..180] to (0..255], which is equivaluent to 1..255
|
||||
// This means that range value 0 is not used
|
||||
this->value = (unsigned char)((angle + 180.0F) * 255.0F);
|
||||
this->value = (unsigned char)((angle + 180.0F) / 360.0F * 255.0F);
|
||||
}
|
||||
|
||||
template <> float AngleUsing<unsigned char>::ToFloat() {
|
||||
float f = ((float)this->value / 255.0F) - 180.0F;
|
||||
float f = ((float)this->value / 255.0F) * 360.0F - 180.0F;
|
||||
return f;
|
||||
}
|
||||
|
||||
@ -34,18 +32,15 @@ template <> AngleUsing<unsigned short>::AngleUsing(unsigned short angle) {
|
||||
return;
|
||||
}
|
||||
|
||||
// clamp the float range to -1..1
|
||||
while (angle <= -180.0F)
|
||||
angle += 360.0F;
|
||||
while (angle > 180.0F)
|
||||
angle -= 360.0F;
|
||||
// normalize to (-180..180]
|
||||
angle = Angle::Normalize(angle);
|
||||
|
||||
// map (-180..180] to 1..256
|
||||
// map (-180..180] to (0..65535] which is equivalent to 1..65535
|
||||
// This means that range value 0 is not used
|
||||
this->value = (unsigned short)((angle + 180.0F) * 65535.0F);
|
||||
this->value = (unsigned short)((angle + 180.0F) / 360.0F * 65535.0F);
|
||||
}
|
||||
|
||||
template <> float AngleUsing<unsigned short>::ToFloat() {
|
||||
float f = ((float)this->value / 65535.0F) - 180.0F;
|
||||
float f = ((float)this->value / 65535.0F) * 360.0F - 180.0F;
|
||||
return f;
|
||||
}
|
@ -3,13 +3,7 @@
|
||||
|
||||
#include "Range.h"
|
||||
|
||||
// A fixed point 16-bit signed angle between (-180..180]
|
||||
// class DiscreteAngle16 : public Range16 {
|
||||
// public:
|
||||
// DiscreteAngle16(float angle);
|
||||
|
||||
// inline DiscreteAngle16 &operator-() override;
|
||||
// };
|
||||
// A fixed angle between (-180..180]
|
||||
|
||||
template <typename T> class AngleUsing : RangeUsing<T> {
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user