26 lines
709 B
C++
26 lines
709 B
C++
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0.If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
|
|
|
|
#include "DiscreteAngle.h"
|
|
|
|
#include <math.h>
|
|
|
|
DiscreteAngle16::DiscreteAngle16(float angle) : Range16() {
|
|
if (!isfinite(angle)) {
|
|
range = 0;
|
|
return;
|
|
}
|
|
|
|
// clamp the float range to -1..1
|
|
while (angle <= -180.0F)
|
|
angle += 360.0F;
|
|
while (angle > 180.0F)
|
|
angle -= 360.0F;
|
|
|
|
// map (-180..180] to 1..65535
|
|
// This means that range value 0 is not used
|
|
this->range = (unsigned short)((angle + 180.0F) * 65535.0F);
|
|
}
|
|
|
|
DiscreteAngle16 &DiscreteAngle16::operator-() { -this->range; } |