Skip to content

Commit

Permalink
Angle clamps check for parameter validity (not NaN or Infinity) befor…
Browse files Browse the repository at this point in the history
…e processing.
  • Loading branch information
CYBUTEK committed May 28, 2017
1 parent b4967f0 commit bde5d1d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 44 deletions.
1 change: 1 addition & 0 deletions Documents/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
96 changes: 52 additions & 44 deletions KerbalEngineer/Helpers/AngleHelper.cs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//
// 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 <http://www.gnu.org/licenses/>.

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;
Expand Down

0 comments on commit bde5d1d

Please sign in to comment.