WINTERMUTE: Add a warning for off-by-one errors in normalizeAngle()

This commit is contained in:
Filippos Karapetis 2019-07-14 14:28:40 +03:00
parent 212cd5aa78
commit 71a9def71e

View File

@ -44,9 +44,22 @@ void BaseUtils::swap(int *a, int *b) {
//////////////////////////////////////////////////////////////////////////
float BaseUtils::normalizeAngle(float angle) {
float origAngle = angle;
// The original WME engine checked against 360 here, which is an off-by one
// error, as when normalizing an angle, we expect the number to be between 0
// and 359 (since 360 is 0). This check has been fixed in ScummVM to 359. If
// the resulting angle is negative, it will be corrected in the while loop
// below.
while (angle > 359) {
angle -= 360;
}
// Report cases where the above off-by-one error might occur
if (origAngle > 360 && angle < 0) {
warning("BaseUtils::normalizeAngle: off-by-one error detected while normalizing angle %f to %f", origAngle, angle);
}
while (angle < 0) {
angle += 360;
}