From bde5d1d3c9e82bad50711b1319e5ba39f0a4c891 Mon Sep 17 00:00:00 2001 From: cybutek Date: Sun, 28 May 2017 18:45:05 +0100 Subject: [PATCH] Angle clamps check for parameter validity (not NaN or Infinity) before processing. --- Documents/CHANGES.txt | 1 + KerbalEngineer/Helpers/AngleHelper.cs | 96 +++++++++++++++------------ 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/Documents/CHANGES.txt b/Documents/CHANGES.txt index e03c092f..937253ec 100644 --- a/Documents/CHANGES.txt +++ b/Documents/CHANGES.txt @@ -1,4 +1,5 @@ 1.1.3.0, 2017-05-28, KSP 1.3.0 #1804 + Fixed: Check for NaN and Infinities before clamping angles, resolving a hang state caused by the Intercept Angle readout. Added: Setting for enabling/disabling whether the toolbar icon in-flight activates on mouse hover. Added: Body category with the following readouts: Body Name diff --git a/KerbalEngineer/Helpers/AngleHelper.cs b/KerbalEngineer/Helpers/AngleHelper.cs index e6ea1fd5..e4eb548f 100644 --- a/KerbalEngineer/Helpers/AngleHelper.cs +++ b/KerbalEngineer/Helpers/AngleHelper.cs @@ -1,80 +1,88 @@ -// -// Kerbal Engineer Redux -// -// Copyright (C) 2014 CYBUTEK -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// +// Kerbal Engineer Redux +// +// Copyright (C) 2014 CYBUTEK +// +// This program is free software: you can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along with this program. If not, +// see . namespace KerbalEngineer.Helpers { using UnityEngine; + using Extensions; public static class AngleHelper { public static double Clamp180(double angle) { - if (angle < -180.0) + if (angle.IsValid()) { - do + if (angle < -180.0) { - angle += 360.0; + do + { + angle += 360.0; + } + while (angle < -180.0); } - while (angle < -180.0); - } - else if (angle > 180.0) - { - do + else if (angle > 180.0) { - angle -= 360.0; + do + { + angle -= 360.0; + } + while (angle > 180.0); } - while (angle > 180.0); } + return angle; } public static double Clamp360(double angle) { - if (angle < 0.0) + if (angle.IsValid()) { - do + if (angle < 0.0) { - angle += 360.0; + do + { + angle += 360.0; + } + while (angle < 0.0); } - while (angle < 0.0); - } - else if (angle >= 360.0) - { - do + else if (angle >= 360.0) { - angle -= 360.0; + do + { + angle -= 360.0; + } + while (angle >= 360.0); } - while (angle >= 360.0); } + return angle; } public static double ClampBetween(double value, double minimum, double maximum) { - while (value < minimum) + if (value.IsValid() && minimum.IsValid() && maximum.IsValid()) { - value += maximum; - } + while (value < minimum) + { + value += maximum; + } - while (value > maximum) - { - value -= maximum; + while (value > maximum) + { + value -= maximum; + } } return value;