1
0
Fork 0

Reduce technical debt

This commit is contained in:
Scott Giese 2019-01-29 23:07:35 -06:00
parent ca98d2ef5d
commit 9a5eac3c59
24 changed files with 111 additions and 178 deletions

View file

@ -93,60 +93,17 @@ Airport::Airport( int c, char* def)
Airport::~Airport()
{
for (auto feature : features)
{
feature = nullptr;
}
for (auto helipad : helipads)
{
helipad = nullptr;
}
for (auto runway : runways)
{
runway = nullptr;
}
for (auto waterrunway : waterrunways)
{
waterrunway = nullptr;
}
for (auto pavement : pavements)
{
pavement = nullptr;
}
for (auto taxiway : taxiways)
{
taxiway = nullptr;
}
for (auto lightobject : lightobjects)
{
lightobject = nullptr;
}
for (auto windsock : windsocks)
{
windsock = nullptr;
}
for (auto beacon : beacons)
{
beacon = nullptr;
}
for (auto sign : signs)
{
sign = nullptr;
}
for (auto boundaryItem : boundary)
{
boundaryItem = nullptr;
}
std::fill(features.begin(), features.end(), nullptr);
std::fill(helipads.begin(), helipads.end(), nullptr);
std::fill(runways.begin(), runways.end(), nullptr);
std::fill(waterrunways.begin(), waterrunways.end(), nullptr);
std::fill(pavements.begin(), pavements.end(), nullptr);
std::fill(taxiways.begin(), taxiways.end(), nullptr);
std::fill(lightobjects.begin(), lightobjects.end(), nullptr);
std::fill(windsocks.begin(), windsocks.end(), nullptr);
std::fill(beacons.begin(), beacons.end(), nullptr);
std::fill(signs.begin(), signs.end(), nullptr);
std::fill(boundary.begin(), boundary.end(), nullptr);
}
bool Airport::isDebugRunway( int rwy )
@ -813,7 +770,6 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
group_list strips_tc; strips_tc.clear();
string_list strip_materials; strip_materials.clear();
int index;
int_list pt_v, tri_v, strip_v;
int_list pt_n, tri_n, strip_n;
int_list tri_tc, strip_tc;
@ -837,9 +793,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
sgboTri.material = material;
for (int l = 0; l < 3; ++l) {
int index;
index = nodes.add( poly.GetTriNode( i, l ) );
int index = nodes.add( poly.GetTriNode( i, l ) );
sgboTri.v_list.push_back( index );
// use 'the' normal
@ -868,9 +822,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
sgboTri.material = material;
for (int l = 0; l < 3; ++l) {
int index;
index = nodes.add( poly.GetTriNode( i, l ) );
int index = nodes.add( poly.GetTriNode( i, l ) );
sgboTri.v_list.push_back( index );
// use 'the' normal
@ -899,9 +851,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
sgboTri.material = material;
for (int l = 0; l < 3; ++l) {
int index;
index = nodes.add( poly.GetTriNode( i, l ) );
int index = nodes.add( poly.GetTriNode( i, l ) );
sgboTri.v_list.push_back( index );
// use 'the' normal
@ -924,9 +874,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
sgboTri.material = material;
for (int l = 0; l < 3; ++l) {
int index;
index = nodes.add( base_poly.GetTriNode( k, l ) );
int index = nodes.add( base_poly.GetTriNode( k, l ) );
sgboTri.v_list.push_back( index );
// use 'the' normal
@ -947,7 +895,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
{
for ( unsigned int j = 0; j < divided_base.ContourSize( i ); ++j )
{
index = nodes.add( divided_base.GetNode(i, j) );
int index = nodes.add( divided_base.GetNode(i, j) );
TG_LOG(SG_GENERAL, SG_DEBUG, "added base point " << divided_base.GetNode(i, j) << " at " << index );
}
}
@ -1080,9 +1028,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
for ( unsigned int j = 0; j < rwy_lights[i].ContourSize(); ++j )
{
int index;
index = nodes.add( rwy_lights[i].GetPosition(j) );
int index = nodes.add( rwy_lights[i].GetPosition(j) );
sgboPt.v_list.push_back( index );
index = normals.add( rwy_lights[i].GetNormal(j) );
@ -1157,7 +1103,6 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
}
#endif
SGGeod ref_geod;
// calc elevations and write out windsock references
TG_LOG(SG_GENERAL, SG_DEBUG, "Computing windsock node elevations");
@ -1181,7 +1126,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
// write out beacon references
for ( unsigned int i = 0; i < beacons.size(); ++i )
{
ref_geod = beacons[i]->GetLoc();
SGGeod ref_geod = beacons[i]->GetLoc();
ref_geod.setElevationM( apt_surf.calc_elevation( ref_geod, 0.0 ) );
write_index_object_shared( objpath, b, ref_geod,
@ -1192,7 +1137,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
// write out taxiway signs references
for ( unsigned int i = 0; i < signs.size(); ++i )
{
ref_geod = signs[i]->GetLoc();
SGGeod ref_geod = signs[i]->GetLoc();
ref_geod.setElevationM( apt_surf.calc_elevation( ref_geod, 0.0 ) );
write_index_object_sign( objpath, b, ref_geod,
signs[i]->GetDefinition(),
@ -1207,7 +1152,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
for ( unsigned int j = 0; j < buoys.GetSize(); ++j )
{
ref_geod = buoys.GetNode(j);
SGGeod ref_geod = buoys.GetNode(j);
ref_geod.setElevationM( apt_surf.calc_elevation( ref_geod, 0.0 ) );
write_index_object_shared( objpath, b, ref_geod,
"Models/Airport/water_rw_buoy.xml",

View file

@ -59,10 +59,7 @@ public:
void AddFeatures( FeatureList feature_list )
{
for (auto feature : feature_list)
{
features.push_back( feature );
}
std::copy( feature_list.begin(), feature_list.end(), features.begin() );
}
int NumFeatures( void )

View file

@ -120,10 +120,9 @@ inline double CalculateTheta( const SGVec3d& dirCur, const SGVec3d& dirNext, con
class BezNode
{
public:
explicit BezNode( SGGeod l )
explicit BezNode( SGGeod l ) :
loc(l)
{
loc = l;
has_prev_cp = false;
has_next_cp = false;
@ -133,28 +132,18 @@ public:
close = false;
}
BezNode( double lat, double lon )
BezNode( double lat, double lon ) :
BezNode(SGGeod::fromDeg(lon, lat))
{
loc = SGGeod::fromDeg( lon, lat );
has_prev_cp = false;
has_next_cp = false;
mark = 0;
light = 0;
term = false;
close = false;
}
BezNode( SGGeod l, SGGeod cp )
BezNode( SGGeod l, SGGeod cp ) :
loc(l),
prev_cp(Mirror(cp)),
next_cp(cp)
{
loc = l;
next_cp = cp;
has_next_cp = true;
prev_cp = Mirror(cp);
has_prev_cp = true;
has_next_cp = true;
mark = 0;
light = 0;
@ -162,20 +151,9 @@ public:
close = false;
}
BezNode( double lat, double lon, double cp_lat, double cp_lon )
BezNode( double lat, double lon, double cp_lat, double cp_lon ) :
BezNode(SGGeod::fromDeg(lon, lat), SGGeod::fromDeg(cp_lon, cp_lat))
{
loc = SGGeod::fromDeg( lon, lat );
next_cp = SGGeod::fromDeg( cp_lon, cp_lat );
has_next_cp = true;
prev_cp = Mirror( next_cp );
has_prev_cp = true;
mark = 0;
light = 0;
term = false;
close = false;
}
SGGeod Mirror( const SGGeod& pt )

View file

@ -136,7 +136,7 @@ void ClosedPoly::ConvertContour( const BezContour& src, tgContour& dst )
dst.Erase();
// iterate through each bezier node in the contour
for (unsigned int i = 0; i <= src.size()-1; i++)
for (unsigned int i = 0; i < src.size(); ++i)
{
TG_LOG(SG_GENERAL, SG_DEBUG, "\nHandling Node " << i << "\n\n");
@ -147,7 +147,7 @@ void ClosedPoly::ConvertContour( const BezContour& src, tgContour& dst )
}
else
{
// for the last node, next is the first. as all contours are closed
// for the last node, next is the first node, as all contours are closed
nextNode = src.at(0);
}

View file

@ -402,7 +402,6 @@ tglightcontour_list Runway::gen_calvert( const string &kind, bool recip )
{
tgLightContour w_lights;
tgLightContour r_lights;
int i, j;
string flag;
SGVec3f normal = gen_runway_light_vector( 3.0, recip );
@ -438,9 +437,7 @@ tglightcontour_list Runway::gen_calvert( const string &kind, bool recip )
// first set of single lights
pt = ref;
for ( i = 0; i < count; ++i ) {
for ( int i = 0; i < count; ++i ) {
// centre lights
pt = SGGeodesy::direct(pt, length_hdg, -vert_space);
@ -529,7 +526,7 @@ tglightcontour_list Runway::gen_calvert( const string &kind, bool recip )
int num_lights = 0;
// draw nice crossbars
for ( i = 0; i < 5; i++ ) {
for ( int i = 0; i < 5; ++i ) {
switch ( i ) {
case 0:
num_lights = 4;
@ -549,14 +546,14 @@ tglightcontour_list Runway::gen_calvert( const string &kind, bool recip )
}
pt = crossbar[i];
for ( j = 0 ; j < num_lights; j++ ) {
for ( int j = 0 ; j < num_lights; ++j ) {
// left side lights
pt = SGGeodesy::direct(pt, left_hdg, horiz_space);
w_lights.AddLight(pt, normal);
}
pt = crossbar[i];
for ( j = 0; j < num_lights; j++ ) {
for ( int j = 0; j < num_lights; ++j ) {
// right side lights
pt = SGGeodesy::direct(pt, left_hdg, -horiz_space);
w_lights.AddLight(pt, normal);

View file

@ -28,17 +28,17 @@ void LinearFeature::ConvertContour( const BezContour& src, bool closed )
points.Erase();
// iterate through each bezier node in the contour
for (unsigned int i = 0; i <= src.size() - 1; ++i)
for (unsigned int i = 0; i < src.size(); ++i)
{
curNode = src.at(i);
if (i < src.size() - 1)
{
nextNode = src.at(i+1);
nextNode = src.at(i + 1);
}
else
{
// for the last node, next is the first. as all contours are closed
// for the last node, next is the first node, as all contours are closed
nextNode = src.at(0);
}

View file

@ -78,12 +78,12 @@ public:
}
LinearFeature( const std::string& desc, double o ) :
offset(o),
width(0),
cur_mark(nullptr),
cur_light(nullptr),
description(desc)
{
offset = o;
width = 0;
}
~LinearFeature();

View file

@ -38,19 +38,33 @@ using std::string;
TGDem::TGDem() :
z_units(2) // meters
in(nullptr),
dem_data(new float[DEM_SIZE_1][DEM_SIZE_1]),
output_data(new float[DEM_SIZE_1][DEM_SIZE_1]),
dem_description(""),
dem_quadrangle(""),
option_name("")
{
// cout << "class TGDem CONstructor called." << endl;
dem_data = new float[DEM_SIZE_1][DEM_SIZE_1];
output_data = new float[DEM_SIZE_1][DEM_SIZE_1];
originx = originy = 0.0;
cols =rows = 0;
col_step = row_step = 0.0;
dem_x1 = dem_x2 = dem_x3 = dem_x4 = 0.0;
dem_y1 = dem_y2 = dem_y3 = dem_y4 = 0.0;
dem_z1 = dem_z2 = 0.0;
dem_resolution = dem_num_profiles = 0;
prof_col = prof_row = 0;
prof_num_cols = prof_num_rows = 0;
prof_x1 = prof_y1 = 0.0;
prof_data = 0.0;
do_data = 0;
cur_col = cur_row = 0;
z_units = 2; // meters
}
TGDem::TGDem( const string &file ) {
// cout << "class TGDem CONstructor called." << endl;
dem_data = new float[DEM_SIZE_1][DEM_SIZE_1];
output_data = new float[DEM_SIZE_1][DEM_SIZE_1];
TGDem::TGDem( const string &file ) :
TGDem::TGDem()
{
TGDem::open(file);
}
@ -150,7 +164,6 @@ TGDem::next_exp() {
bool
TGDem::read_a_record() {
int i, inum;
double dnum;
string name, token, buf;
char c;
@ -187,7 +200,7 @@ TGDem::read_a_record() {
// Map projection parameters (ignored)
for ( i = 0; i < 15; i++ ) {
dnum = next_exp();
double dnum = next_exp();
SG_LOG(SG_GENERAL, SG_DEBUG, i << ": " << dnum);
}

View file

@ -95,7 +95,7 @@ public:
// Constructor
TGDem();
TGDem( const std::string& file );
explicit TGDem( const std::string& file );
// Destructor
~TGDem();

View file

@ -47,7 +47,6 @@
#include <simgear/misc/sg_dir.hxx>
#include <simgear/debug/logstream.hxx>
#include "dted.hxx"
using std::cout;
@ -64,9 +63,9 @@ TGDted::TGDted( int _res )
}
TGDted::TGDted( int _res, const SGPath &file ):TGDted(_res)
TGDted::TGDted( int _res, const SGPath &file ) :
TGDted(_res)
{
TGDted::open( file );
}
@ -224,7 +223,6 @@ TGDted::load( ) {
}
TGDted::~TGDted() {
// printf("class TGSrtmBase DEstructor called.\n");
delete [] data;

View file

@ -60,7 +60,7 @@ public:
// Constructor, _res must be either "1" for the 1arcsec data or
// "3" for the 3arcsec data.
TGDted( int _res );
explicit TGDted( int _res );
TGDted( int _res, const SGPath &file );
// Destructor

View file

@ -62,7 +62,8 @@ TGHgt::TGHgt( int _res )
}
TGHgt::TGHgt( int _res, const SGPath &file ) : TGHgt( _res )
TGHgt::TGHgt( int _res, const SGPath &file ) :
TGHgt( _res )
{
TGHgt::open( file );
}

View file

@ -59,7 +59,7 @@ public:
// Constructor, _res must be either "1" for the 1arcsec data or
// "3" for the 3arcsec data.
TGHgt( int _res );
explicit TGHgt( int _res );
TGHgt( int _res, const SGPath &file );
// Destructor

View file

@ -21,10 +21,6 @@
// $Id: hgt.cxx,v 1.7 2005-12-19 16:06:45 curt Exp $
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <iostream>
#include <stdlib.h>
#include <zlib.h>

View file

@ -24,10 +24,6 @@
#ifndef _SRTMBASE_HXX
#define _SRTMBASE_HXX
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <simgear/compiler.h>
#include <simgear/bucket/newbucket.hxx>
@ -36,8 +32,13 @@
class TGSrtmBase {
protected:
TGSrtmBase() : remove_tmp_file(false)
{}
TGSrtmBase() :
remove_tmp_file(false)
{
originx = originy = 0.0;
cols = rows = 0;
col_step = row_step = 0.0;
}
~TGSrtmBase();
@ -83,5 +84,3 @@ public:
#endif // _SRTMBASE_HXX

View file

@ -61,7 +61,7 @@ class LandCover {
public:
LandCover( const std::string &filename );
explicit LandCover( const std::string &filename );
virtual ~LandCover ();
virtual int getValue (long x, long y) const;

View file

@ -40,7 +40,7 @@ main (int ac, const char * av[])
int value = lu.getValue(lon, lat);
cout << "Value is " << value
<< " \"" << lu.getDescUSGS(value) << '"' << endl;
} catch (string e) {
} catch (const string& e) {
cerr << "Died with exception: " << e << endl;
return 1;
}

View file

@ -181,6 +181,8 @@ int PolyTree::Total() const
PolyNode::PolyNode(): Parent(0), Index(0), m_IsOpen(false)
{
m_jointype = JoinType::Square;
m_endtype = EndType::ClosedPolygon;
}
//------------------------------------------------------------------------------
@ -718,7 +720,10 @@ void DisposeOutPts(OutPt*& pp)
inline void InitEdge(TEdge* e, TEdge* eNext, TEdge* ePrev, const IntPoint& Pt)
{
// Dx is explicitly being set due to memset not being portable for floating-point values
std::memset(e, 0, sizeof(TEdge));
e->Dx = 0.0;
e->Next = eNext;
e->Prev = ePrev;
e->Curr = Pt;
@ -880,10 +885,13 @@ bool HorzSegmentsOverlap(cInt seg1a, cInt seg1b, cInt seg2a, cInt seg2b)
// ClipperBase class methods ...
//------------------------------------------------------------------------------
ClipperBase::ClipperBase() //constructor
ClipperBase::ClipperBase() :
m_ActiveEdges(nullptr)
{
m_CurrentLM = m_MinimaList.begin(); //begin() == end() here
m_UseFullRange = false;
m_PreserveCollinear = false;
m_HasOpenPaths = false;
}
//------------------------------------------------------------------------------
@ -4199,13 +4207,13 @@ void ClipperOffset::DoRound(int j, int k)
m_normals[k].X * m_normals[j].X + m_normals[k].Y * m_normals[j].Y);
int steps = std::max((int)Round(m_StepsPerRad * std::fabs(a)), 1);
double X = m_normals[k].X, Y = m_normals[k].Y, X2;
double X = m_normals[k].X, Y = m_normals[k].Y;
for (int i = 0; i < steps; ++i)
{
m_destPoly.push_back(IntPoint(
Round(m_srcPoly[j].X + X * m_delta),
Round(m_srcPoly[j].Y + Y * m_delta)));
X2 = X;
double X2 = X;
X = X * m_cos - m_sin * Y;
Y = X2 * m_sin + Y * m_cos;
}

View file

@ -118,7 +118,7 @@ struct DoublePoint
double X;
double Y;
DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {}
DoublePoint(IntPoint ip) : X((double)ip.X), Y((double)ip.Y) {}
explicit DoublePoint(const IntPoint& ip) : X(ip.X), Y(ip.Y) {}
};
//------------------------------------------------------------------------------
@ -263,7 +263,7 @@ protected:
class Clipper : public virtual ClipperBase
{
public:
Clipper(int initOptions = 0);
explicit Clipper(int initOptions = 0);
bool Execute(ClipType clipType,
Paths &solution,
PolyFillType fillType = PolyFillType::EvenOdd);
@ -391,7 +391,7 @@ private:
class clipperException : public std::exception
{
public:
clipperException(const char* description): m_descr(description) {}
explicit clipperException(const char* description): m_descr(description) {}
virtual ~clipperException() throw() {}
virtual const char* what() const throw() {return m_descr.c_str();}
private:

View file

@ -53,10 +53,11 @@ public:
//int index = ( row * _cols ) + col;
if ( col < 0 || col >= _cols ) {
SG_LOG(SG_GENERAL, SG_WARN, "column out of bounds on read (" << col << " >= " << _cols << ")");
int *p = 0; *p = 1; // force crash
} else if ( row < 0 || row >= _rows ) {
col = col < 0 ? 0 : _cols - 1;
}
else if ( row < 0 || row >= _rows ) {
SG_LOG(SG_GENERAL, SG_WARN, "row out of bounds on read (" << row << " >= " << _rows << ")");
int *p = 0; *p = 1; // force crash
row = row < 0 ? 0 : _rows - 1;
}
return m[row][col];
@ -66,10 +67,11 @@ public:
//int index = ( row * _cols ) + col;
if ( col < 0 || col >= _cols ) {
SG_LOG(SG_GENERAL, SG_WARN,"column out of bounds on set (" << col << " >= " << _cols << ")");
int *p = 0; *p = 1; // force crash
} else if ( row < 0 || row >= _rows ) {
col = col < 0 ? 0 : _cols - 1;
}
else if ( row < 0 || row >= _rows ) {
SG_LOG(SG_GENERAL, SG_WARN,"row out of bounds on set (" << row << " >= " << _rows << ")");
int *p = 0; *p = 1; // force crash
row = row < 0 ? 0 : _rows - 1;
}
m[row][col] = p;
}

View file

@ -27,7 +27,7 @@
class SGGeodIndex {
public:
SGGeodIndex( SGGeod g ) {
explicit SGGeodIndex( SGGeod g ) {
geod = g;
std::size_t FNV_prime;

View file

@ -163,7 +163,7 @@ inline std::ostream& operator<<(std::ostream& out, const Vec2& v)
inline std::istream& operator>>(std::istream& in, Vec2& v)
{
char c;
char c = '\0';
return in >> c >> v[0] >> v[1] >> c;
}

View file

@ -174,7 +174,7 @@ inline std::ostream& operator<<(std::ostream& out, const Vec3& v)
inline std::istream& operator>>(std::istream& in, Vec3& v)
{
char c;
char c = '\0';
return in >> c >> v[0] >> v[1] >> v[2] >> c;
}

View file

@ -4,15 +4,14 @@
#include "gui.h"
main(int argc, char **argv)
int main(int argc, char **argv)
{
glutInit(&argc, argv);
Terra::process_cmdline(argc, argv);
Terra::gui_init();
Terra::gui_interact();
return 0;
}