Tronald / CoordinateSharp

A library designed to ease geographic coordinate format conversions, and determine sun/moon information in C#
Other
364 stars 59 forks source link

Coordinate.TryParse doesn't honor EagerLoad provided when parsing from MGRS value. #196

Closed dakelley95 closed 2 years ago

dakelley95 commented 2 years ago

When attempting to use TryParse to convert an MGRS value to a coordinate, the provided EagerLoad is not used when calling MilitaryGridReferenceSystem.MGRStoLatLong in FormatFinder.TryParse. EagerLoad is not being passed to the subsequent TryParse calls in the call stack.

This is causing performance issues if converting lots of MGRS values to a coordinate in bulk.

Notice TryParse on line 411 in this file:https://github.com/Tronald/CoordinateSharp/blob/51a40b78a7cb1ed2fb1c810177e90c5217c959c2/CoordinateSharp/Coordinate/Coordinate.Parse.cs doesn't pass on the EagerLoad value.

Which then causes it to not be used on line 192 in this file:https://github.com/Tronald/CoordinateSharp/blob/51a40b78a7cb1ed2fb1c810177e90c5217c959c2/CoordinateSharp/Parsers/FormatFinder.Coordinate.cs

Tronald commented 2 years ago

Hi @dakelley95 thanks for reporting this issue. Can you provide me an example of your code to replicate the issue you are having. The following example is honoring the eager load settings I have passed (with less than a 1ms benchmark), so I am having trouble replicating.

MilitaryGridReferenceSystem mgrs = new MilitaryGridReferenceSystem("10T", "FR", 54543, 27282);
Coordinate c = MilitaryGridReferenceSystem.MGRStoLatLong(mgrs, new EagerLoad(false));  
Console.WriteLine(c.CelestialInfo.SunSet); //Throws NullReferenceException as expected eager loading is turned off.
Tronald commented 2 years ago

Just to clarify before we go too deep as well, the reason the code block you referenced doesn't pass eager loading is because FormatFinder turns it off all together for speed. The eager loading settings specified are injected back in after the format is found. You shouldn't be having issues with speed, but let's look at your code when able to see what might be occurring.

Tronald commented 2 years ago

Closing issue due to non-response and lack of replication. Will reopen if needed.