Nasal library/geo: Difference between revisions

Jump to navigation Jump to search
→‎PositionedSearch: Should be finished now
(→‎PositionedSearch: some more, but still WIP)
(→‎PositionedSearch: Should be finished now)
Line 280: Line 280:
|mode = class
|mode = class
|version = 3.0
|version = 3.0
|text = This class can be used to show differences between '''FGPositioned''' (navcache)) search queries<ref>https://forum.flightgear.org/search.php?st=0&sk=t&sd=d&sr=posts&keywords=PositionedSearch</ref>. Although it is only used for [[MapStructure]] and the [[Nasal Browser]] as of 09/2016, it can also be used for other applications.
|text = This class can be used to show differences between FGPositioned (namespace: <code>positioned</code>) search queries. Although it is only used for [[MapStructure]] and the [[Nasal Browser]] as of 09/2016, it can also be used for other applications.
}}
}}
==== new() ====
==== new() ====
Line 295: Line 295:
|param4text = Optional <code>'''me'''</code> reference. This will be used as the <code>'''me'''</code> reference in each of the above fucntions.
|param4text = Optional <code>'''me'''</code> reference. This will be used as the <code>'''me'''</code> reference in each of the above fucntions.
|example1 = var searchCmd = func(){
|example1 = var searchCmd = func(){
     return positioned.findAirportsWithinRange(2);
     return positioned.findAirportsWithinRange(10);
};
};
var added = func(apt){
var added = func(apt){
Line 305: Line 305:


var searcher = geo.PositionedSearch.new(searchCmd, added, removed);
var searcher = geo.PositionedSearch.new(searchCmd, added, removed);
searcher.update();
}}
}}
==== test() ====
==== test() ====
Line 324: Line 325:
|param1text = Optional search function to use instead of the one given in <code>[[#new()_2|PositionedSearch.new()]]</code>.
|param1text = Optional search function to use instead of the one given in <code>[[#new()_2|PositionedSearch.new()]]</code>.
|example1 = var searchCmd = func(){
|example1 = var searchCmd = func(){
     return positioned.findAirportsWithinRange(2);
     return positioned.findAirportsWithinRange(10);
};
};
var added = func(apt){
var added = func(apt){
Line 339: Line 340:
{{Nasal doc
{{Nasal doc
|syntax = geo.PositionedSearch._equals;
|syntax = geo.PositionedSearch._equals;
|text = Checks if two objects are equal. You must redefine this function to use <code>geo.PositionedSearch</code> for other uses.
|text = Function that checks if two objects are equal. You must redefine this function to use <code>geo.PositionedSearch</code> for other uses.
|param1 = searchCmd
|param1text = Optional search function to use instead of the one given in <code>[[#new()_2|PositionedSearch.new()]]</code>.
|example1 = var searchCmd = func(){
|example1 = var searchCmd = func(){
     return positioned.findAirportsWithinRange(2);
     var vec = [];
    var max = rand() * 10;
    for(var i = 1; i <= max; i += 1){
        append(vec, i);
    }
    return vec;
};
};
var added = func(apt){
var added = func(num){
     print("Airport ", apt.id, " added");
     print(num, " added");
}
}
var removed = func(apt){
var removed = func(num){
     print("Airport ", apt.id, " removed");
     print(num, " removed");
}
}


var searcher = geo.PositionedSearch.new(searchCmd, added, removed);
var searcher = geo.PositionedSearch.new(searchCmd, added, removed);
searcher._equals = func(a, b){ return a == b; }
searcher.update();
searcher.update();
print("====");
searcher.update(); # run again to see differences
}}
}}


Navigation menu