Board index FlightGear Development Nasal

Bugs in "search-by-ID" Nasal APIs

Nasal is the scripting language of FlightGear.

Bugs in "search-by-ID" Nasal APIs

Postby Red Leader » Sat Nov 28, 2015 9:45 pm

Hi all,

As many have probably noticed, I have been documenting the Nasal library (hist). While testing some APIs that search for an object using an ID/code, namely findFixesByID() and findNavaidsByID(), I discovered a bug in both (although they are quite similar and probably related): inputting partial IDs/codes doesn't work as expected.

findFixesByID():
Code: Select all
# Expected result: Print all fix IDs beginning with "B"
# Actual result: Prints just one ID, but it is "B," which isn't a valid fix name
var fixes = findFixesByID("B");
foreach(var fix; fixes){
    print("ID: ", fix.id);
}

Code: Select all
# Expected result: Print all fix IDs beginning with "N"
# Actual result: Prints a list of IDs, but all of them are "N," which isn't a valid fix name
var fixes = findFixesByID("N");
foreach(var fix; fixes){
    print("ID: ", fix.id);
}

Code: Select all
# Expected result: Print all fix IDs beginning with "ZUNA"
# Actual result: Prints nothing; should at least print "ZUNAP" (a real fix)
var fixes = findFixesByID("ZUNA");
foreach(var fix; fixes){
    print("ID: ", fix.id);
}

Code: Select all
# Expected result: Print "ZUNAP"
# Actual result: Works as expected (prints "ZUNAP")
var fixes = findFixesByID("ZUNAP");
foreach(var fix; fixes){
    print("ID: ", fix.id); # prints "ZUNAP"
}


findNavaidsByID():
Code: Select all
# Expected result: Print all navaid codes beginning with "K"
# Actual result: Prints a list of navaid codes, but all of them are "K"
var fixes = findNavaidsByID("K");
foreach(var fix; fixes){
    print("ID: ", fix.id);
}

Code: Select all
# Expected result: Print all navaid codes containing "MX"
# Actual result: Prints several codes, but they are all "MX"
var fixes = findNavaidsByID("MX");
foreach(var fix; fixes){
    print("ID: ", fix.id);
}

Code: Select all
# Expected result: Print "MXW"
# Actual result: Works as expected (prints "MXW")
var fixes = findNavaidsByID("MXW");
foreach(var fix; fixes){
    print("ID: ", fix.id); # prints "MXW"
}


I have looked through the Doxygen documentation, and here's what I think is the solution:

findFixesByID():
The search function that this uses is FGPositioned::findAllWithIdent. One argument is called aExact, which defaults to true. Now, findAirportsByICAO() uses the same function, and behaves correctly, however, it sets this aExact to false. So I think that line 1,641 of src/Scripting/NasalPositioned.cxx needs changing from:
Code: Select all
FGPositionedList fixes = FGPositioned::findAllWithIdent(ident, &filter);

to
Code: Select all
FGPositionedList fixes = FGPositioned::findAllWithIdent(ident, &filter, false);


findNavaidsByID():
Very similar to the above, but something needs changing in a different place. Line 272 of src/Navaids/navlist.cxx needs changing from:
Code: Select all
FGPositionedList stations = FGPositioned::findAllWithIdent(ident, filter);

to
Code: Select all
FGPositionedList stations = FGPositioned::findAllWithIdent(ident, filter, false);


Hopefully this will solve the problem.

For system specs, see my profile. I am using Scenery 1.0 (from FG 2.12) with custom EGOD scenery from FGUK and no TerraSync.

Regards,
Red Leader

P.S. I know this is in the wrong place for a bug report (I don't have access to SourceForge).
For once you have tasted flight you will walk the earth with your eyes turned skywards, for there you have been and there you will long to return.
Leonardo da Vinci

Projects:
BAe Sea Harrier FA2Scripted AI Objects frameworkDocumenting Nasal
Red Leader
 
Posts: 22
Joined: Sat Oct 25, 2014 8:52 pm
Location: United Kingdom
Callsign: Red-Led
Version: 2017.3.1
OS: Microsoft Windows 10

Re: Bugs in "search-by-ID" Nasal APIs

Postby wkitty42 » Sat Nov 28, 2015 11:54 pm

i forwarded this to the dev list... let's see what they say...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Bugs in "search-by-ID" Nasal APIs

Postby wkitty42 » Sun Nov 29, 2015 4:18 pm

here's zakalawe's response...

Thanks for forward this!

The quick answer is it’s intentional that the default version of these functions is exact, because exactly looks are much more common, and (much) faster on the database than partial lookups.

Hence, the question is how to expose partial/inexact lookups to Nasal:

- new functions
OR
- additional arguments.

Adding additional arguments has the problem for findNavaidByIdent, there’s already quite a few (poorly documented, as ever) optional arguments; you can filter by type, specify a search location in the usual ways, and more. Hence my preference would be to add a new function there, eg:

findNavaidByPartialIdent.

For fixes we could do the same for clarity, although there it’s easy enough to add a new trailing argument to specify exact vs inexact.


if i may, i suggest to take this to the dev list and continue the discussion there... the topic there is the same as here... i copied it exactly to keep things clear and easy to find ;)
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Bugs in "search-by-ID" Nasal APIs

Postby bugman » Sun Nov 29, 2015 4:30 pm

The mailing list thread can be followed at:


And responded to at that link by anyone signed up to the list.

Regards,
Edward
bugman
Moderator
 
Posts: 1808
Joined: Thu Mar 19, 2015 10:01 am
Version: next

Re: Bugs in "search-by-ID" Nasal APIs

Postby wkitty42 » Sun Nov 29, 2015 5:01 pm

thanks for doing that, edward... that's almost as good as doing the mailing list thing ;) ;) :mrgreen:
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Bugs in "search-by-ID" Nasal APIs

Postby Red Leader » Wed Dec 02, 2015 3:29 pm

Hello again,

Reply to James:

I would prefer a new argument, instead of a new function. As far as I know, most, if not all, of the navigation database search methods aren't used, so a new function is also likely to be unused as well.

I have done some tests using the following code:
Code: Select all
var start = systime();
##
# test code ...
##
var end = systime();
print("Took ", end - start, " sec");

For findNavaidsByID(), findFixesByID() and findAirportsByICAO() (using a partial ICAO code of three letters), the time taken is usually under one-thousandth of a second (findAirportsByICAO() uses an inexact search, see here). I therefore think that switching to an inexact search is absolutely fine, bearing in mind that these functions are unlikely to be called every frame.

Even if the changes I suggested weren't made, the main problem of incorrect navaid/fix IDs being returned by inexact searches would need addressing. If you try out some of the examples I gave in my first post, you will find that the returned IDs always match the search string, not what their actual ID is.

Regards,
Red Leader

P.S. Thanks wkitty for taking the trouble to shuttle this forward and back between the devel mailing list. :)
For once you have tasted flight you will walk the earth with your eyes turned skywards, for there you have been and there you will long to return.
Leonardo da Vinci

Projects:
BAe Sea Harrier FA2Scripted AI Objects frameworkDocumenting Nasal
Red Leader
 
Posts: 22
Joined: Sat Oct 25, 2014 8:52 pm
Location: United Kingdom
Callsign: Red-Led
Version: 2017.3.1
OS: Microsoft Windows 10

Re: Bugs in "search-by-ID" Nasal APIs

Postby Hooray » Thu Dec 03, 2015 3:37 pm

note that there's also a new NasalPositioned_cppbind module that is using the cppbind framework, which would probably also need to be updated accordingly
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Nasal

Who is online

Users browsing this forum: No registered users and 2 guests