1
0
Fork 0

[Genapts] Reduce technical debt. Migrate away from usage of <cstdio>.

This commit is contained in:
Scott Giese 2019-01-27 18:59:01 -06:00
parent a8677d4f16
commit fb50bb4681
18 changed files with 168 additions and 122 deletions

View file

@ -243,7 +243,6 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
// runway lights
tglightcontour_list rwy_lights;
bool make_shapefiles = false;
char debug_root[32];
sprintf(debug_root, "./airport_dbg/%s/", icao.c_str() );
@ -305,6 +304,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
{
TG_LOG(SG_GENERAL, SG_DEBUG, "Build Feature Poly " << i + 1 << " of " << features.size() << " : " << features[i]->GetDescription() );
bool make_shapefiles = false;
features[i]->BuildBtg( line_polys, rwy_lights, lf_accum, make_shapefiles );
}
@ -327,7 +327,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
//slivers.clear();
if ( isDebugRunway(i) ) {
sprintf( shapefile_name, "runway_%d", i );
sprintf( shapefile_name, "runway_%u", i );
} else {
strcpy( shapefile_name, "" );
}
@ -393,7 +393,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
//slivers.clear();
if ( isDebugPavement(i) ) {
sprintf( shapefile_name, "pvmnt_%d", i );
sprintf( shapefile_name, "pvmnt_%u", i );
} else {
strcpy( shapefile_name, "" );
}
@ -427,7 +427,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
//slivers.clear();
if ( isDebugTaxiway(i) ) {
sprintf( shapefile_name, "taxiway_%d", i );
sprintf( shapefile_name, "taxiway_%u", i );
} else {
strcpy( shapefile_name, "" );
}
@ -1106,10 +1106,10 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
}
SGVec3d gbs_center = SGVec3d::fromGeod( b.get_center() );
double dist_squared, radius_squared = 0;
double radius_squared = 0;
for ( unsigned int i = 0; i < wgs84_nodes.size(); ++i )
{
dist_squared = distSqr(gbs_center, wgs84_nodes[i]);
double dist_squared = distSqr(gbs_center, wgs84_nodes[i]);
if ( dist_squared > radius_squared ) {
radius_squared = dist_squared;
}
@ -1258,7 +1258,7 @@ bool Airport::CheckZFightingTriangles( const char* prefix, const char* debug_roo
tgContour intContour = intersection.GetContour( m );
if ( (intContour.GetSize() > 2) && (intContour.GetArea() > min_area_thresh) ) {
TG_LOG( SG_GENERAL, SG_ALERT, prefix << "Z-FIGHTING between runway poly " << i << " and pavement poly " << k << " contour has " << intContour.GetSize() << " nodes " << " area is " << intContour.GetArea() );
sprintf( desc, "rwy_%06d_pvmt_%06d", i, j );
sprintf( desc, "rwy_%06u_pvmt_%06u", i, j );
tgShapefile::FromContour( intContour, debug_root, layer, desc );
zfighting = true;
}
@ -1292,7 +1292,7 @@ bool Airport::CheckZFightingTriangles( const char* prefix, const char* debug_roo
tgContour intContour = intersection.GetContour( m );
if ( (intContour.GetSize() > 2) && (intContour.GetArea() > min_area_thresh) ) {
TG_LOG( SG_GENERAL, SG_ALERT, prefix << "Z-FIGHTING between pavement poly " << i << " and runway poly " << k << " contour has " << intContour.GetSize() << " nodes " << " area is " << intContour.GetArea() );
sprintf( desc, "pvmt_%06d_rwy_%06d", i, j );
sprintf( desc, "pvmt_%06u_rwy_%06u", i, j );
tgShapefile::FromContour( intContour, debug_root, layer, desc );
zfighting = true;
}
@ -1325,7 +1325,7 @@ bool Airport::CheckZFightingTriangles( const char* prefix, const char* debug_roo
tgContour intContour = intersection.GetContour( m );
if ( (intContour.GetSize() > 2) && (intContour.GetArea() > min_area_thresh) ) {
TG_LOG( SG_GENERAL, SG_ALERT, prefix << "Z-FIGHTING between base poly and runway poly " << j << " contour has " << intContour.GetSize() << " nodes " << " area is " << intContour.GetArea() );
sprintf( desc, "base_rwy_%06d", j );
sprintf( desc, "base_rwy_%06u", j );
tgShapefile::FromContour( intContour, debug_root, layer, desc );
zfighting = true;
}
@ -1353,7 +1353,7 @@ bool Airport::CheckZFightingTriangles( const char* prefix, const char* debug_roo
tgContour intContour = intersection.GetContour( m );
if ( (intContour.GetSize() > 2) && (intContour.GetArea() > min_area_thresh) ) {
TG_LOG( SG_GENERAL, SG_ALERT, prefix << "Z-FIGHTING between base poly and pavement poly " << j << " contour has " << intContour.GetSize() << " nodes " << " area is " << intContour.GetArea() );
sprintf( desc, "base_pvmt_%06d", j );
sprintf( desc, "base_pvmt_%06u", j );
tgShapefile::FromContour( intContour, debug_root, layer, desc );
zfighting = true;
}

View file

@ -120,7 +120,7 @@ inline double CalculateTheta( const SGVec3d& dirCur, const SGVec3d& dirNext, con
class BezNode
{
public:
BezNode( SGGeod l )
explicit BezNode( SGGeod l )
{
loc = l;

View file

@ -21,48 +21,33 @@ static void stringPurifier( std::string& s )
}
}
ClosedPoly::ClosedPoly( char* desc )
ClosedPoly::ClosedPoly( char* desc ) :
is_pavement(false),
is_border(false),
has_feature(false),
surface_type(0),
smoothness(0.0),
texture_heading(0.0),
description(std::string(desc ? desc : "none"))
{
is_pavement = false;
is_border = true;
has_feature = false;
if ( desc )
{
description = desc;
stringPurifier(description);
}
else
{
description = "none";
}
is_border = true;
stringPurifier(description);
boundary.clear();
cur_contour.clear();
}
ClosedPoly::ClosedPoly( int st, float s, float th, char* desc )
ClosedPoly::ClosedPoly( int st, float s, float th, char* desc ) :
ClosedPoly( desc )
{
surface_type = st;
smoothness = s;
texture_heading = th;
is_pavement = (surface_type != 15) ? true : false; // wrong??
is_border = false;
is_border = false;
has_feature = true;
if ( desc )
{
description = desc;
stringPurifier(description);
}
else
{
description = "none";
}
boundary.clear();
cur_contour.clear();
}
ClosedPoly::~ClosedPoly()
@ -438,10 +423,10 @@ int ClosedPoly::BuildBtg( tgpolygon_list& rwy_polys, tgcontour_list& slivers, tg
int ClosedPoly::BuildBtg( tgpolygon_list& rwy_polys, tgcontour_list& slivers, tgAccumulator& accum, std::string& shapefile_name )
{
char layer[128];
if ( is_pavement && pre_tess.Contours() )
{
char layer[128];
if( shapefile_name.size() ) {
sprintf( layer, "%s_preclip", shapefile_name.c_str() );
tgShapefile::FromPolygon( pre_tess, "./airport_dbg", layer, std::string("preclip") );

View file

@ -11,7 +11,7 @@
class ClosedPoly
{
public:
ClosedPoly( char* desc );
explicit ClosedPoly( char* desc );
ClosedPoly( int st, float s, float th, char* desc );
~ClosedPoly();

View file

@ -37,7 +37,7 @@
// lookup node elevations for each point in the SGGeod list. Returns
// average of all points. Doesn't modify the original list.
double tgAverageElevation( const std::string &root, const string_list elev_src,
const std::vector<SGGeod> points_source )
const std::vector<SGGeod>& points_source )
{
bool done = false;
unsigned int i;

View file

@ -25,7 +25,7 @@
// lookup node elevations for each point in the SGGeod list. Returns
// average of all points. Doesn't modify the original list.
double tgAverageElevation( const std::string &root, const string_list elev_src,
const std::vector<SGGeod> points_source );
const std::vector<SGGeod>& points_source );
// lookup node elevations for each point in the specified nurbs++
// matrix.

View file

@ -23,19 +23,26 @@
#include "runway.hxx"
#include "debug.hxx"
#include <cstdio>
#include <stdlib.h>
Helipad::Helipad(char* definition)
{
// helipad format:
// designator lat lon heading length width surface markings shoulder smoothness edge-lighting
// example:
// "H1 21.30433555 -157.85586778 0.00 10.70 10.70 2 0 0 0.25 0\r"
// format:
// helipad designator lat lon heading length width surface markings shoulder smoothness edge lighting
// int fscanf(FILE *stream, const char *format, ...);
sscanf(definition, "%s %lf %lf %lf %lf %lf %d %d %d %lf %d",
heli.designator, &heli.lat, &heli.lon, &heli.heading, &heli.length, &heli.width, &heli.surface,
&heli.marking, &heli.shoulder, &heli.smoothness, &heli.edge_lights);
std::istringstream ss(definition);
ss >> heli.designator
>> heli.lat
>> heli.lon
>> heli.heading
>> heli.length
>> heli.width
>> heli.surface
>> heli.marking
>> heli.shoulder
>> heli.smoothness
>> heli.edge_lights;
TG_LOG(SG_GENERAL, SG_DEBUG, "Read helipad: (" << heli.lon << "," << heli.lat << ") heading: " << heli.heading << " length: " << heli.length << " width: " << heli.width );
}

View file

@ -25,7 +25,7 @@
class Helipad
{
public:
Helipad(char* def);
explicit Helipad(char* def);
void BuildBtg( tgpolygon_list& heli_polys,
tglightcontour_list& heli_lights,

View file

@ -72,23 +72,18 @@ typedef std::vector<Lighting*> LightingList;
class LinearFeature
{
public:
LinearFeature( char* desc, double o )
LinearFeature( char* desc, double o ) :
LinearFeature(std::string(desc ? desc : "none"), o)
{
if ( desc )
{
description = desc;
}
else
{
description = "none";
}
offset = o;
}
LinearFeature( std::string desc, double o )
LinearFeature( const std::string& desc, double o ) :
offset(o),
width(0),
cur_mark(nullptr),
cur_light(nullptr),
description(desc)
{
description = desc;
offset = o;
}
~LinearFeature();

View file

@ -1,35 +1,50 @@
#include <simgear/debug/logstream.hxx>
#include "linked_objects.hxx"
#include "debug.hxx"
#include <cstdio>
Windsock::Windsock( char* definition )
Windsock::Windsock(char* definition)
{
sscanf(definition, "%lf %lf %d", &lat, &lon, &lit);
std::istringstream ss(definition);
ss >> lat
>> lon
>> lit;
TG_LOG(SG_GENERAL, SG_DEBUG, "Read Windsock: (" << lon << "," << lat << ") lit: " << lit );
}
Beacon::Beacon( char* definition )
Beacon::Beacon(char* definition)
{
sscanf(definition, "%lf %lf %d", &lat, &lon, &code);
std::istringstream ss(definition);
ss >> lat
>> lon
>> code;
TG_LOG(SG_GENERAL, SG_DEBUG, "Read Beacon: (" << lon << "," << lat << ") code: " << code );
}
Sign::Sign( char* definition )
Sign::Sign(char* definition)
{
char sgdef[256];
double def_heading;
sscanf(definition, "%lf %lf %lf %d %d %s", &lat, &lon, &def_heading, &reserved, &size, sgdef );
std::istringstream ss(definition);
ss >> lat
>> lon
>> def_heading
>> reserved
>> size
>> sgdef;
// 850 format sign heading is the heading which points away from the visible numbers
// Flightgear wants the heading to be the heading in which the sign is read
heading = -def_heading + 360.0;
TG_LOG(SG_GENERAL, SG_DEBUG, "Read Sign: (" << lon << "," << lat << ") heading " << def_heading << " size " << size << " definition: " << sgdef << " calc view heading: " << heading );
TG_LOG(SG_GENERAL, SG_DEBUG, "Read Sign: (" << lon << "," << lat <<
") heading " << def_heading <<
" size " << size <<
" definition: " << sgdef <<
" calc view heading: " << heading );
sgn_def = sgdef;
}

View file

@ -8,7 +8,7 @@
class Windsock
{
public:
Windsock(char* def);
explicit Windsock(char* def);
double lat;
double lon;
@ -31,7 +31,7 @@ typedef std::vector<std::shared_ptr<Windsock>> WindsockList;
class Beacon
{
public:
Beacon(char* def);
explicit Beacon(char* def);
double lat;
double lon;
@ -53,7 +53,7 @@ typedef std::vector<std::shared_ptr<Beacon>> BeaconList;
class Sign
{
public:
Sign(char* def);
explicit Sign(char* def);
double lat;
double lon;

View file

@ -1,12 +1,18 @@
#include <simgear/math/SGMathFwd.hxx>
#include <simgear/debug/logstream.hxx>
#include "object.hxx"
#include "debug.hxx"
#include <cstdio>
LightingObj::LightingObj( char* definition )
{
sscanf(definition, "%lf %lf %d %lf %lf %s", &lat, &lon, &type, &heading, &glideslope, &assoc_rw);
std::istringstream ss(definition);
ss >> lat
>> lon
>> type
>> heading
>> glideslope
>> assoc_rw;
TG_LOG(SG_GENERAL, SG_DEBUG, "Read lighting object: (" << lon << "," << lat << ") heading: " << heading << " type: " << type );
}

View file

@ -9,7 +9,7 @@
class LightingObj
{
public:
LightingObj(char* def);
explicit LightingObj(char* def);
double lat;
double lon;

View file

@ -24,7 +24,6 @@
#include <config.h>
#endif
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <set>

View file

@ -7,8 +7,6 @@
#include <terragear/tg_polygon.hxx>
#include <cstdio>
#include "global.hxx"
#include "apt_math.hxx"
#include "beznode.hxx"
@ -20,43 +18,74 @@ Runway::Runway(char* definition)
{
double az2;
// format:
// runway width surface shoulder smoothness centerline lights edge lighting distance remaining signs
// 100 46.02 2 1 0.00 1 2 1
// runway format:
// width surface shoulder smoothness centerline lights edge lighting distance remaining signs
// 46.02 2 1 0.00 1 2 1
//
// runway number runway end lat runway end long threshold overrun markings approach lighting
// 09L 33.63470475 -084.44798671 0.00 120.09 3 7
// runway number runway end lat runway end long threshold overrun markings approach lighting
// 09L 33.63470475 -084.44798671 0.00 120.09 3 7
//
// touchdown zone lighting runway end identifier lights
// 0 1
// touchdown zone lighting runway end identifier lights
// 0 1
//
// runway number runway end lat runway end long threshold overrun markings approach lighting
// 27R 33.63469907 -084.40893004 0.00 120.09 3 6
// runway number runway end lat runway end long threshold overrun markings approach lighting
// 27R 33.63469907 -084.40893004 0.00 120.09 3 6
//
// touchdown zone lighting runway end identifier lights
// 0 1
// touchdown zone lighting runway end identifier lights
// 0 1
// Parse the line
// 46.02 2 1 0.00 1 2 1 09L 33.63470475 -084.44798671 0.00 120.09 3 7 0 1 27R 33.63469907 -084.40893004 0.00 120.09 3 6 0 1
// 46.02 2 1 0.00 1 2 1 09L 33.63470475 -084.44798671 0.00 120.09 3 7 0 1 27R 33.63469907 -084.40893004 0.00 120.09 3 6 0 1
// int fscanf(FILE *stream, const char *format, ...);
sscanf(definition, "%lf %d %d %lf %d %d %d %s %lf %lf %lf %lf %d %d %d %d %s %lf %lf %lf %lf %d %d %d %d",
&rwy.width, &rwy.surface, &rwy.shoulder, &rwy.smoothness, &rwy.centerline_lights, &rwy.edge_lights, &rwy.dist_remain_signs,
rwy.rwnum[0], &rwy.lat[0], &rwy.lon[0], &rwy.threshold[0], &rwy.overrun[0], &rwy.marking[0], &rwy.approach_lights[0], &rwy.tz_lights[0], &rwy.reil[0],
rwy.rwnum[1], &rwy.lat[1], &rwy.lon[1], &rwy.threshold[1], &rwy.overrun[1], &rwy.marking[1], &rwy.approach_lights[1], &rwy.tz_lights[1], &rwy.reil[1]
);
std::istringstream ss(definition);
ss >> rwy.width
>> rwy.surface
>> rwy.shoulder
>> rwy.smoothness
>> rwy.centerline_lights
>> rwy.edge_lights
>> rwy.dist_remain_signs
>> rwy.rwnum[0]
>> rwy.lat[0]
>> rwy.lon[0]
>> rwy.threshold[0]
>> rwy.overrun[0]
>> rwy.marking[0]
>> rwy.approach_lights[0]
>> rwy.tz_lights[0]
>> rwy.reil[0]
>> rwy.rwnum[1]
>> rwy.lat[1]
>> rwy.lon[1]
>> rwy.threshold[1]
>> rwy.overrun[1]
>> rwy.marking[1]
>> rwy.approach_lights[1]
>> rwy.tz_lights[1]
>> rwy.reil[1];
// calculate runway heading and length (used a lot)
SGGeodesy::inverse( GetStart(), GetEnd(), rwy.heading, az2, rwy.length );
TG_LOG(SG_GENERAL, SG_DEBUG, "Read runway: (" << rwy.lon[0] << "," << rwy.lat[0] << ") to (" << rwy.lon[1] << "," << rwy.lat[1] << ") heading: " << rwy.heading << " length: " << rwy.length << " width: " << rwy.width );
TG_LOG(SG_GENERAL, SG_DEBUG, "Read runway: (" << rwy.lon[0] << "," << rwy.lat[0] <<
") to (" << rwy.lon[1] << "," << rwy.lat[1] <<
") heading: " << rwy.heading <<
" length: " << rwy.length <<
" width: " << rwy.width );
}
WaterRunway::WaterRunway(char* definition)
{
sscanf(definition, "%lf %d %s %lf %lf %s %lf %lf", &width, &buoys, rwnum[0], &lat[0], &lon[0], rwnum[1], &lat[1], &lon[1]);
std::istringstream ss(definition);
ss >> width
>> buoys
>> rwnum[0]
>> lat[0]
>> lon[0]
>> rwnum[1]
>> lat[1]
>> lon[1];
TG_LOG(SG_GENERAL, SG_DEBUG, "Read water runway: (" << lon[0] << "," << lat[0] << ") to (" << lon[1] << "," << lat[1] << ") width: " << width << " buoys = " << buoys );
}
@ -85,6 +114,7 @@ tgContour WaterRunway::GetBuoys()
}
}
}
return buoys_nodes;
}

View file

@ -13,7 +13,7 @@ class Runway
{
public:
Runway(char* def);
explicit Runway(char* def);
SGGeod GetStart()
{
@ -184,7 +184,7 @@ typedef std::vector <std::shared_ptr<Runway>> RunwayList;
class WaterRunway
{
public:
WaterRunway(char* def);
explicit WaterRunway(char* def);
tgContour GetBuoys();

View file

@ -6,8 +6,6 @@
#include <terragear/tg_shapefile.hxx>
#include <cstdio>
#include "global.hxx"
#include "apt_math.hxx"
#include "beznode.hxx"
@ -29,20 +27,31 @@ Taxiway::Taxiway(char* definition)
double smoothness;
int signs;
// format:
// taxiway lat lon designation heading length threshold overrun
// 10 44.38085600 -074.20606200 xxx 79.29 3384 0.0 0.0
// taxiway format:
// lat lon designation heading length threshold overrun
// 44.38085600 -074.20606200 xxx 79.29 3384 0.0 0.0
//
// width lighting surface shoulder markings smoothness dist remain
// 60 161161 1 0 0 0.35 0
// width lighting surface shoulder markings smoothness dist remain
// 60 161161 1 0 0 0.35 0
// Parse the line
// 44.38085600 -074.20606200 xxx 79.29 3384 0.0 0.0 60 161161 1 0 0 0.35 0
// 44.38085600 -074.20606200 xxx 79.29 3384 0.0 0.0 60 161161 1 0 0 0.35 0
// int fscanf(FILE *stream, const char *format, ...);
sscanf(definition, "%lf %lf %s %lf %lf %lf %lf %lf %s %d %d %d %lf %d",
&lat, &lon, designation, &heading, &length, &threshold, &overrun,
&width, lighting, &surface, &shoulder, &markings, &smoothness, &signs);
std::istringstream ss(definition);
ss >> lat
>> lon
>> designation
>> heading
>> length
>> threshold
>> overrun
>> width
>> lighting
>> surface
>> shoulder
>> markings
>> smoothness
>> signs;
TG_LOG(SG_GENERAL, SG_DEBUG, "Read taxiway: (" << lon << "," << lat << ") heading: " << heading << " length: " << length << " width: " << width );

View file

@ -13,7 +13,7 @@ class Taxiway
{
public:
Taxiway(char* def);
explicit Taxiway(char* def);
int BuildBtg( tgpolygon_list& taxi_polys,
tglightcontour_list& taxi_lights,