Ezriilc / HyperEdit

A plugin for Kerbal Space Program.
http://www.Kerbaltek.com/hyperedit
GNU General Public License v3.0
41 stars 30 forks source link

Lander: fine tuning coords causes red (invalid numbers) to appear in the Lat box. #62

Open Ezriilc opened 5 years ago

Ezriilc commented 5 years ago

This problem exists in KSP 1.4.5, with HyperEdit 1.5.8. The report is here in the forum thread.

Ezriilc commented 5 years ago

It was reported that using fine tuning puts some bizarre numbers in the lat box (-359.902677420287), and the Land button says "Cannot Land".

Ezriilc commented 5 years ago

I've confirmed this as follows.

While at the KSC Launch Pad (and likely other places), if the Lat (North/South) coords are adjusted with I and K (and NOT the Lon East/West with J and L) to a negative number (Southern hemisphere), that is when the problem occurs.

The LAT entry changes to -359.xxx and turns red since that value is not valid (technically). The game seems to like those values just fine, and the Lander appears to still work mostly, but the Land/Drop button isn't available, nor is the Save button.

In the past, I added code to turn the LAT entry red if the value is outside of -89.9 to +89.9, because that is the reality of navigating a spheroid body. I think the reason the -359.xxx entries still work (sorta) is because the game is just wrapping around the body (dividing the value by 360). I believe the game doesn't care for anything exactly at 90 North or South, so that's why I added the limits.

We should probably change the limit to finer divisions, such as 89.999, as well as auto-correcting the numbers instead of just complaining. This may be simple enough for me to do, but I'll have to take a long look at the code again, and I would not refuse some C# help here.

EDIT: Sorry for all the tiny edits!

Kirikou974 commented 5 years ago

TL DR : DegreeFix function is causing the issue. The function is not written to handle -90 => +90° range. It was made for 360°. The fix could be to modify the DegreeFix to make work the way we want (limit to -90 to +90° in this case). The function should also be used with absoule values. Not negative ones.

Long version : It comes down to how the view is beeing built in the LanderView.cs class. The View() function creates a TextBoxView for lattitude on line 147. The building of the TextBoxView uses the latTryParse function. The latTryParse function calls Extensions.DegreeFix function with the latitude (that can be negative or positive) and a range start of 0. If I go through the function with a positive latitude value of 1 it goes like this : double rangeEnd = rangeStart + 360.0; //rangeStart is 0 so rangeEnd is 360 double outAngle = inAngle; //outAngle equals to inAngle so 1 while (outAngle > rangeEnd) //outAngle is less than rangeEnd so nothing is done here outAngle -= 360.0; while (outAngle < rangeStart) //outAngle is greater than rangeStart so nothing is done here outAngle += 360.0; return outAngle; //returns 1 which is correct

If I go through the function with a negative latitude value of -1 it goes like this : double rangeEnd = rangeStart + 360.0; //rangeStart is 0 so rangeEnd is 360 double outAngle = inAngle; //outAngle is equal to inAngle so -1 while (outAngle > rangeEnd) //outAngle is less than rangeEnd so nothing is done here outAngle -= 360.0; while (outAngle < rangeStart) //outAngle is less than rangeStart so outAngle becomes 359 = problem outAngle += 360.0; return outAngle; //returns 359 which is incorrect

So if the latitude is negative the return value for display is always going to be out of boundaries. The fix that I put in place is using Math.Abs and Math.Sign functions to get absolute value in the latTryParse function and returning the right value afterwards. But this is one of many possibilities. We could also change the DegreeFix function to match what we want to achieve ie limit the value between -90 and +90 (using a new parameter maybe ?).