1
0
Fork 0

[Genapts] Reduce technical debt.

This commit is contained in:
Scott Giese 2019-01-29 14:02:18 -06:00
parent 279868b782
commit 911f7f9d27
11 changed files with 352 additions and 394 deletions

View file

@ -370,10 +370,8 @@ int LinearFeature::Finish( bool closed, unsigned int idx )
double heading;
double dist;
double az2;
double last_end_v;
double width = 0;
std::string material;
double cur_light_dist = 0.0f;
double light_delta = 0;
bool markStarted;
@ -386,7 +384,7 @@ int LinearFeature::Finish( bool closed, unsigned int idx )
for (unsigned int i=0; i<marks.size(); i++)
{
markStarted = false;
last_end_v = 0.0f;
double last_end_v = 0.0;
// which material for this mark?
switch( marks[i]->type )
@ -568,7 +566,7 @@ int LinearFeature::Finish( bool closed, unsigned int idx )
for (unsigned int i=0; i<lights.size(); i++)
{
markStarted = false;
cur_light_dist = 0.0f;
double cur_light_dist = 0.0;
int light_direction = lights[i]->LightDirection();
bool alternate = false;
@ -637,7 +635,7 @@ int LinearFeature::Finish( bool closed, unsigned int idx )
while (cur_light_dist < dist)
{
if (cur_light_dist == 0.0f)
if (cur_light_dist == 0.0)
{
tmp = prev_outer;
}

View file

@ -41,8 +41,8 @@ static void usage( int argc, char **argv ) {
TG_LOG(SG_GENERAL, SG_ALERT, "Usage: " << argv[0] << "\n--input=<apt_file>"
<< "\n--work=<work_dir>\n[ --start-id=abcd ] [ --nudge=n ] "
<< "[--min-lon=<deg>] [--max-lon=<deg>] [--min-lat=<deg>] [--max-lat=<deg>] "
<< "[ --airport=abcd ] [--max-slope=<decimal>] [--tile=<tile>] [--threads] [--threads=x]"
<< "[--chunk=<chunk>] [--clear-dem-path] [--dem-path=<path>] [--verbose] [--help] [--log-level=bulk|info|debug|warn|alert]");
<< "[ --airport=abcd ] [--max-slope=<decimal>] [--threads] [--threads=x]"
<< "[--clear-dem-path] [--dem-path=<path>] [--verbose] [--help] [--log-level=bulk|info|debug|warn|alert]");
}
@ -82,8 +82,6 @@ static void help( int argc, char **argv, const string_list& elev_src ) {
cout << "where once again abcd is a valid airport code. In this case, all airports in the file subsequent to the \n";
cout << "start-id are done. This is convenient when re-starting after a previous error. \n";
cout << "\nAn input area may be specified by lat and lon extent using min and max lat and lon. \n";
//cout << "Alternatively, you may specify a chunk (10 x 10 degrees) or tile (1 x 1 degree) using a string \n";
//cout << "such as eg. w080n40, e000s27. \n";
cout << "\nAn input file containing only a subset of the world's \n";
cout << "airports may of course be used.\n";
cout << "\n\n";
@ -92,7 +90,7 @@ static void help( int argc, char **argv, const string_list& elev_src ) {
cout << "The following subdirectories of the work-dir will be searched for elevation files:\n\n";
string_list::const_iterator elev_src_it;
for (elev_src_it = elev_src.begin(); elev_src_it != elev_src.end(); elev_src_it++) {
for (elev_src_it = elev_src.begin(); elev_src_it != elev_src.end(); ++elev_src_it) {
cout << *elev_src_it << "\n";
}
cout << "\n";
@ -159,110 +157,96 @@ int main(int argc, char **argv)
for (arg_pos = 1; arg_pos < argc; arg_pos++)
{
string arg = argv[arg_pos];
if ( arg.find("--log-level=") == 0 )
if (arg.compare(0, 12, "--log-level=") == 0)
{
setLoggingPriority(arg.substr(12));
}
else if ( arg.find("--work=") == 0 )
else if (arg.compare(0, 7, "--work=") == 0)
{
work_dir = arg.substr(7);
}
else if ( arg.find("--input=") == 0 )
else if (arg.compare(0, 8, "--input=") == 0)
{
input_file = arg.substr(8);
}
else if ( arg.find("--start-id=") == 0 )
else if (arg.compare(0, 11, "--start-id=") == 0)
{
start_id = arg.substr(11);
}
else if ( arg.find("--nudge=") == 0 )
else if (arg.compare(0, 8, "--nudge=") == 0)
{
nudge = atoi( arg.substr(8).c_str() );
}
else if ( arg.find("--snap=") == 0 )
else if (arg.compare(0, 7, "--snap=") == 0)
{
gSnap = atof( arg.substr(7).c_str() );
}
else if ( arg.find("--min-lon=") == 0 )
else if (arg.compare(0, 10, "--min-lon=") == 0)
{
min.setLongitudeDeg(atof( arg.substr(10).c_str() ));
}
else if ( arg.find("--max-lon=") == 0 )
else if (arg.compare(0, 10, "--max-lon=") == 0)
{
max.setLongitudeDeg(atof( arg.substr(10).c_str() ));
}
else if ( arg.find("--min-lat=") == 0 )
else if (arg.compare(0, 10, "--min-lat=") == 0)
{
min.setLatitudeDeg(atof( arg.substr(10).c_str() ));
}
else if ( arg.find("--max-lat=") == 0 )
else if (arg.compare(0, 10, "--max-lat=") == 0)
{
max.setLatitudeDeg(atof( arg.substr(10).c_str() ));
}
#if 0 // relly? - do we need this?
else if ( arg.find("--chunk=") == 0 )
{
tg::Rectangle rectangle = tg::parseChunk(arg.substr(8).c_str(), 10.0);
min = rectangle.getMin();
max = rectangle.getMax();
}
else if ( arg.find("--tile=") == 0 )
{
tg::Rectangle rectangle = tg::parseTile(arg.substr(7).c_str());
min = rectangle.getMin();
max = rectangle.getMax();
}
#endif
else if ( arg.find("--airport=") == 0 )
else if (arg.compare(0, 10, "--airport=") == 0)
{
airport_id = simgear::strutils::uppercase( arg.substr(10).c_str() );
}
else if ( arg == "--clear-dem-path" )
else if (arg.compare(0, 16, "--clear-dem-path") == 0)
{
elev_src.clear();
}
else if ( arg.find("--dem-path=") == 0 )
else if (arg.compare(0, 11, "--dem-path=") == 0)
{
elev_src.push_back( arg.substr(11) );
}
else if ( (arg.find("--verbose") == 0) || (arg.find("-v") == 0) )
else if (arg.compare(0, 9, "--verbose") == 0 || arg.compare(0, 2, "-v") == 0)
{
sglog().setLogLevels( SG_GENERAL, SG_BULK );
}
else if ( (arg.find("--max-slope=") == 0) )
else if (arg.compare(0, 12, "--max-slope=") == 0)
{
slope_max = atof( arg.substr(12).c_str() );
}
else if ( (arg.find("--threads=") == 0) )
else if (arg.compare(0, 10, "--threads=") == 0)
{
num_threads = atoi( arg.substr(10).c_str() );
}
else if ( (arg.find("--threads") == 0) )
else if (arg.compare(0, 9, "--threads") == 0)
{
num_threads = boost::thread::hardware_concurrency();
}
else if (arg.find("--debug-dir=") == 0)
else if (arg.compare(0, 12, "--debug-dir=") == 0)
{
debug_dir = arg.substr(12);
}
else if (arg.find("--debug-runways=") == 0)
else if (arg.compare(0, 16, "--debug-runways=") == 0)
{
debug_runway_defs.push_back( arg.substr(16) );
}
else if (arg.find("--debug-pavements=") == 0)
else if (arg.compare(0, 18, "--debug-pavements=") == 0)
{
debug_pavement_defs.push_back( arg.substr(18) );
}
else if (arg.find("--debug-taxiways=") == 0)
else if (arg.compare(0, 17, "--debug-taxiways=") == 0)
{
TG_LOG(SG_GENERAL, SG_INFO, "add debug taxiway " << arg.substr(17) );
debug_taxiway_defs.push_back( arg.substr(17) );
}
else if (arg.find("--debug-features=") == 0)
else if (arg.compare(0, 17, "--debug-features=") == 0)
{
debug_feature_defs.push_back( arg.substr(17) );
}
else if ( (arg.find("--help") == 0) || (arg.find("-h") == 0) )
else if (arg.compare(0, 6, "--help") == 0 || arg.compare(0, 2, "-h") == 0)
{
help( argc, argv, elev_src );
exit(-1);

View file

@ -101,7 +101,7 @@ void write_index_object_sign( const string &base, const SGBucket &b,
exit(-1);
}
fprintf( fp, "OBJECT_SIGN %s %.6f %.6f %.1f %.2f %u\n", sign.c_str(),
fprintf( fp, "OBJECT_SIGN %s %.6f %.6f %.1f %.2f %d\n", sign.c_str(),
p.getLongitudeDeg(), p.getLatitudeDeg(), p.getElevationM(), heading, size );
fclose( fp );
}

View file

@ -8,17 +8,15 @@
bool Parser::GetAirportDefinition( char* line, std::string& icao )
{
char* tok;
int code;
bool match = false;
// Get the number code
tok = strtok(line, " \t\r\n");
char* tok = strtok(line, " \t\r\n");
if (tok)
{
line += strlen(tok)+1;
code = atoi(tok);
int code = atoi(tok);
switch(code)
{
@ -40,7 +38,7 @@ bool Parser::GetAirportDefinition( char* line, std::string& icao )
return match;
}
void Parser::set_debug( std::string path, std::vector<std::string> runway_defs,
void Parser::set_debug( const std::string& path, std::vector<std::string> runway_defs,
std::vector<std::string> pavement_defs,
std::vector<std::string> taxiway_defs,
std::vector<std::string> feature_defs )
@ -416,7 +414,7 @@ std::shared_ptr<ClosedPoly> Parser::ParsePavement( char* line )
char *d = nullptr;
int numParams;
numParams = sscanf(line, "%d %f %f %s", &st, &s, &th, desc);
numParams = sscanf(line, "%d %f %f %255s", &st, &s, &th, desc);
if (numParams == 4)
{
@ -440,7 +438,7 @@ std::shared_ptr<ClosedPoly> Parser::ParseBoundary( char* line )
char *d = nullptr;
int numParams;
numParams = sscanf(line, "%s", desc);
numParams = sscanf(line, "%255s", desc);
if (numParams == 1)
{
@ -485,20 +483,18 @@ int Parser::SetState( int state )
// TODO: This should be a loop here, and main should just pass the file name and airport code...
int Parser::ParseLine(char* line)
{
char* tok;
int code;
std::shared_ptr<BezNode> cur_node = nullptr;
if (*line != '#')
{
if (*line == '#')
return cur_state;
// Get the number code
tok = strtok(line, " \t\r\n");
char* tok = strtok(line, " \t\r\n");
if (tok)
{
line += strlen(tok)+1;
code = atoi(tok);
int code = atoi(tok);
switch(code)
{
@ -770,7 +766,6 @@ int Parser::ParseLine(char* line)
break;
}
}
}
return cur_state;
}

View file

@ -89,30 +89,29 @@
class Parser : public SGThread
{
public:
Parser(const std::string& datafile, const std::string& root, const string_list& elev_src )
Parser(const std::string& datafile, const std::string& root, const string_list& elev_src ) :
prev_node(nullptr),
filename(datafile),
elevation(elev_src),
work_dir(root),
cur_airport(nullptr),
cur_taxiway(nullptr),
cur_runway(nullptr),
cur_waterrunway(nullptr),
cur_helipad(nullptr),
cur_pavement(nullptr),
cur_boundary(nullptr),
cur_feat(nullptr),
cur_object(nullptr),
cur_windsock(nullptr),
cur_beacon(nullptr),
cur_sign(nullptr)
{
filename = datafile;
work_dir = root;
elevation = elev_src;
cur_airport = nullptr;
cur_runway = nullptr;
cur_waterrunway = nullptr;
cur_helipad = nullptr;
cur_taxiway = nullptr;
cur_pavement = nullptr;
cur_boundary = nullptr;
cur_feat = nullptr;
cur_object = nullptr;
cur_windsock = nullptr;
cur_beacon = nullptr;
cur_sign = nullptr;
prev_node = nullptr;
cur_state = STATE_NONE;
}
// Debug
void set_debug( std::string path, std::vector<std::string> runway_defs,
void set_debug( const std::string& path, std::vector<std::string> runway_defs,
std::vector<std::string> pavement_defs,
std::vector<std::string> taxiway_defs,
std::vector<std::string> feature_defs );

View file

@ -832,18 +832,15 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
start1_pct = 0.0;
end1_pct = 0.0;
double part_len = 0.0;
int count=0;
if (rwy.overrun[rwhalf] > 0.0) {
/* Generate approach end overrun */
count = (int) (rwy.overrun[rwhalf] * 2.0/ rwy.width);
int count = (int) (rwy.overrun[rwhalf] * 2.0/ rwy.width);
if (count < 1) {
count = 1;
}
part_len = rwy.overrun[rwhalf] / (double)count;
for(int i=0; i<count; i++) {
double part_len = rwy.overrun[rwhalf] / (double)count;
for (int i = 0; i < count; ++i) {
start1_pct = end1_pct;
end1_pct = start1_pct + ( part_len / length );
if ( debug ) { section_name = shapefile_name + "stopway"; }

View file

@ -22,6 +22,7 @@
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
#include "runway.hxx"
#include "debug.hxx"
@ -37,9 +38,7 @@ void Runway::gen_simple_rwy( tgpolygon_list& rwy_polys,
std::string empty = "";
for ( int rwhalf=0; rwhalf<2; ++rwhalf ) {
double length = rwy.length / 2.0;
double start_pct = 0.0;
double end_pct = 0.0;
double heading = 0.0;
@ -53,7 +52,6 @@ void Runway::gen_simple_rwy( tgpolygon_list& rwy_polys,
runway_half.AddNode( 0, runway.GetNode(5) );
runway_half.AddNode( 0, runway.GetNode(2) );
}
else {
heading = rwy.heading;
@ -71,7 +69,7 @@ void Runway::gen_simple_rwy( tgpolygon_list& rwy_polys,
if ( rwy.threshold[rwhalf] > 0.0 ) {
TG_LOG( SG_GENERAL, SG_DEBUG, "Displaced threshold for RW side " << rwhalf << " is " << rwy.threshold[rwhalf] );
start_pct = end_pct;
double start_pct = end_pct;
end_pct = start_pct + ( rwy.threshold[rwhalf] / length );
Runway::gen_runway_section( runway_half,
start_pct, end_pct,

View file

@ -49,7 +49,7 @@ std::ostream& operator<< (std::ostream &out, const AirportInfo &ai)
return out; // MSVC
}
void Scheduler::set_debug( std::string path, std::vector<std::string> runway_defs,
void Scheduler::set_debug( const std::string& path, std::vector<std::string> runway_defs,
std::vector<std::string> pavement_defs,
std::vector<std::string> taxiway_defs,
std::vector<std::string> feature_defs )
@ -176,19 +176,17 @@ void Scheduler::set_debug( std::string path, std::vector<std::string> runway_def
}
}
bool Scheduler::IsAirportDefinition( char* line, std::string icao )
bool Scheduler::IsAirportDefinition( char* line, const std::string& icao )
{
char* tok;
int code;
bool match = false;
// Get the number code
tok = strtok(line, " \t\r\n");
char* tok = strtok(line, " \t\r\n");
if (tok)
{
line += strlen(tok)+1;
code = atoi(tok);
int code = atoi(tok);
switch(code)
{
@ -197,6 +195,7 @@ bool Scheduler::IsAirportDefinition( char* line, std::string icao )
case HELIPORT_CODE:
{
Airport ap( code, line );
if ( ap.GetIcao() == icao )
{
match = true;
@ -240,7 +239,6 @@ bool Scheduler::IsAirportDefinition( char* line, std::string icao )
void Scheduler::AddAirport( std::string icao )
{
char line[2048];
long cur_pos;
bool found = false;
AirportInfo ai;
@ -255,7 +253,7 @@ void Scheduler::AddAirport( std::string icao )
while ( !in.eof() && !found )
{
// remember the position of this line
cur_pos = in.tellg();
long cur_pos = in.tellg();
// get a line
in.getline(line, 2048);
@ -273,7 +271,7 @@ void Scheduler::AddAirport( std::string icao )
}
}
long Scheduler::FindAirport( std::string icao )
long Scheduler::FindAirport( const std::string& icao )
{
char line[2048];
long cur_pos = 0;
@ -321,11 +319,8 @@ void Scheduler::RetryAirport( AirportInfo* pai )
bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox )
{
char line[2048];
char* def;
long cur_pos;
long cur_apt_pos = 0;
std::string cur_apt_name;
char* tok;
int code;
bool match;
bool done;
@ -351,14 +346,14 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox )
while (!done)
{
// remember the position of this line
cur_pos = in.tellg();
long cur_pos = in.tellg();
// get a line
in.getline(line, 2048);
def = &line[0];
char* def = &line[0];
// Get the number code
tok = strtok(def, " \t\r\n");
char* tok = strtok(def, " \t\r\n");
if (tok)
{
@ -471,12 +466,11 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox )
}
}
Scheduler::Scheduler(std::string& datafile, const std::string& root, const string_list& elev_src)
Scheduler::Scheduler(std::string& datafile, const std::string& root, const string_list& elev_src) :
filename(datafile),
elevation(elev_src),
work_dir(root)
{
filename = datafile;
work_dir = root;
elevation = elev_src;
std::ifstream in( filename.c_str() );
if ( !in.is_open() )
{
@ -487,16 +481,9 @@ Scheduler::Scheduler(std::string& datafile, const std::string& root, const strin
void Scheduler::Schedule( int num_threads, std::string& summaryfile )
{
// std::ofstream csvfile;
// open and truncate the summary file : monitor only appends
// csvfile.open( summaryfile.c_str(), std::ios_base::out | std::ios_base::trunc );
// csvfile.close();
std::vector<std::shared_ptr<Parser>> parsers;
for (int i=0; i<num_threads; i++) {
auto parser = std::make_shared<Parser>( filename, work_dir, elevation );
// parser->set_debug();
parser->start();
parsers.push_back( parser );
}

View file

@ -44,9 +44,9 @@ public:
{
}
AirportInfo( std::string id, long p, double s )
AirportInfo( const std::string& id, long p, double s ) :
icao(id)
{
icao = id;
pos = p;
snap = s;
@ -99,7 +99,7 @@ class Scheduler
public:
Scheduler(std::string& datafile, const std::string& root, const string_list& elev_src);
long FindAirport( std::string icao );
long FindAirport( const std::string& icao );
void AddAirport( std::string icao );
bool AddAirports( long start_pos, tgRectangle* boundingBox );
void RetryAirport( AirportInfo* pInfo );
@ -107,13 +107,13 @@ public:
void Schedule( int num_threads, std::string& summaryfile );
// Debug
void set_debug( std::string path, std::vector<std::string> runway_defs,
void set_debug( const std::string& path, std::vector<std::string> runway_defs,
std::vector<std::string> pavement_defs,
std::vector<std::string> taxiway_defs,
std::vector<std::string> feature_defs );
private:
bool IsAirportDefinition( char* line, std::string icao );
bool IsAirportDefinition( char* line, const std::string& icao );
std::string filename;
string_list elevation;