mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
Ref T111, normalize utility functions
This commit is contained in:
committed by
Mathew Sutcliffe
parent
4e45496431
commit
9445bd56a3
@@ -79,9 +79,15 @@ namespace BlackMisc
|
|||||||
return radians * 180.0 / CMathUtils::PI();
|
return radians * 180.0 / CMathUtils::PI();
|
||||||
}
|
}
|
||||||
|
|
||||||
double CMathUtils::normalizeDegrees(double degrees)
|
double CMathUtils::normalizeDegrees180(double degrees)
|
||||||
{
|
{
|
||||||
double result = std::fmod(degrees, 360.0);
|
const double result = CMathUtils::normalizeDegrees360(degrees + 180.0) - 180.0;
|
||||||
|
return (result <= -180.0) ? 180.0 : result; // -180->180
|
||||||
|
}
|
||||||
|
|
||||||
|
double CMathUtils::normalizeDegrees360(double degrees)
|
||||||
|
{
|
||||||
|
const double result = std::fmod(degrees, 360.0);
|
||||||
return (result >= 0.0) ? result : result + 360.0;
|
return (result >= 0.0) ? result : result + 360.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,8 +96,11 @@ namespace BlackMisc
|
|||||||
//! Radians to degrees
|
//! Radians to degrees
|
||||||
static double rad2deg(double radians);
|
static double rad2deg(double radians);
|
||||||
|
|
||||||
|
//! Normalize: -180< degrees ≤180
|
||||||
|
static double normalizeDegrees180(double degrees);
|
||||||
|
|
||||||
//! Normalize: 0≤ degrees <360
|
//! Normalize: 0≤ degrees <360
|
||||||
static double normalizeDegrees(double degrees);
|
static double normalizeDegrees360(double degrees);
|
||||||
|
|
||||||
//! Random number between low and high
|
//! Random number between low and high
|
||||||
static int randomInteger(int low, int high);
|
static int randomInteger(int low, int high);
|
||||||
|
|||||||
@@ -126,5 +126,18 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
return std::tan(this->value(CAngleUnit::rad()));
|
return std::tan(this->value(CAngleUnit::rad()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double CAngle::normalizeDegrees180(double degrees, int roundDigits)
|
||||||
|
{
|
||||||
|
double d = CMathUtils::normalizeDegrees360(degrees + 180.0) - 180.0;
|
||||||
|
if (d <= -180.0) { d = 180.0; } // -180 -> 180
|
||||||
|
return roundDigits < 0 ? d : CMathUtils::round(d, roundDigits);
|
||||||
|
}
|
||||||
|
|
||||||
|
double CAngle::normalizeDegrees360(double degrees, int roundDigits)
|
||||||
|
{
|
||||||
|
const double d = CMathUtils::normalizeDegrees360(degrees);
|
||||||
|
return roundDigits < 0 ? d : CMathUtils::round(d, roundDigits);
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -96,6 +96,12 @@ namespace BlackMisc
|
|||||||
|
|
||||||
//! Tangent of angle
|
//! Tangent of angle
|
||||||
double tan() const;
|
double tan() const;
|
||||||
|
|
||||||
|
//! Normalize: -180< degrees ≤180
|
||||||
|
static double normalizeDegrees180(double degrees, int roundDigits = -1);
|
||||||
|
|
||||||
|
//! Normalize: 0≤ degrees <360
|
||||||
|
static double normalizeDegrees360(double degrees, int roundDigits = -1);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
Reference in New Issue
Block a user