-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProjUnitTests.cpp
147 lines (124 loc) · 4.89 KB
/
ProjUnitTests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// DFLib: A library of Bearings Only Target Localization algorithms
// Copyright (C) 2009-2015 Thomas V. Russo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// Filename : $RCSfile$
//
// Purpose : set of tests to verify that the Proj classes do what
// is expected of them.
//
// Special Notes :
//
// Creator :
//
// Creation Date :
//
// Revision Information:
// ---------------------
//
// Revision Number: $Revision$
//
// Revision Date : $Date$
//
// Current Owner : $Author$
//-------------------------------------------------------------------------
#include <iostream>
#include <vector>
#include <limits>
#include "Util_Misc.hpp"
#include "DF_Proj_Point.hpp"
main(int argc, char **argv)
{
double dtol=10*sqrt(numeric_limits<double>::epsilon());
std::vector<double> xyVals(2);
xyVals[0]=-106.482;
xyVals[1]=35.0913;
std::cout << " Creating a point using values lon="<<xyVals[0]<<",lat= " <<xyVals[1]<< std::endl;
std::vector<std::string> projArgs;
projArgs.push_back("proj=latlong");
projArgs.push_back("datum=WGS84");
std::cout << " pushed projArgs into std::vector " << std::endl;
try
{
DFLib::Proj::Point myFirstPoint(xyVals,projArgs);
std::cout << " Point created. " << std::endl;
std::vector<double> xyStored = myFirstPoint.getUserCoords();
std::cout << " Retrieved XY from stored point. Lon = " << xyStored[0]
<< " Lat = " << xyStored[1];
if (xyStored[0] == xyVals[0] && xyStored[1] == xyVals[1])
std::cout << " PASSED " << std::endl;
else
std::cout << " FAILED " << std::endl;
xyVals = myFirstPoint.getXY();
xyVals[0] += 200;
xyVals[1] += 200;
std::cout << " Resetting XY in stored point to X=" << xyVals[0] << ",Y= "
<< xyVals[1] << std::endl;
myFirstPoint.setXY(xyVals);
xyStored = myFirstPoint.getXY();
std::cout << " Retrieved XY from stored point. X = " << xyStored[0]
<< " Y = " << xyStored[1];
if (xyStored[0] == xyVals[0] && xyStored[1] == xyVals[1])
std::cout << " PASSED " << std::endl;
else
{
std::cout << " FAILED " << std::endl;
std::cout << " storedX=" << xyStored[0] << " Should be " << xyVals[0]
<< std::endl;
std::cout << " storedY=" << xyStored[1] << " Should be " << xyVals[1]
<< std::endl;
}
xyStored = myFirstPoint.getUserCoords();
std::cout << " Lat Lon values of stored, modified point are "
<< " Lon=" << xyStored[0]
<< " Lat=" << xyStored[1] << std::endl;
std::cout << " Cloning point. " << std::endl;
DFLib::Proj::Point *mySecondPointPtr = myFirstPoint.Clone();
xyStored = mySecondPointPtr->getXY();
std::cout << " Retrieved XY from cloned point. X = " << xyStored[0]
<< " Y = " << xyStored[1];
if (fabs(xyStored[0]-xyVals[0])< dtol && fabs(xyStored[1]-xyVals[1])<dtol)
std::cout << " PASSED " << std::endl;
else
{
std::cout << " FAILED " << std::endl;
std::cout << " storedX=" << xyStored[0] << " Should be " << xyVals[0]
<< " difference " << xyStored[0]-xyVals[0] << std::endl;
std::cout << " storedY=" << xyStored[1] << " Should be " << xyVals[1]
<< " difference " << xyStored[1]-xyVals[1] << std::endl;
std::cout << " Tolerance is " << dtol << std::endl;
}
std::cout << " Resetting XY in cloned point to X=0,Y=1 " << std::endl;
xyVals[0]=0;
xyVals[1]=1;
mySecondPointPtr->setXY(xyVals);
xyStored = mySecondPointPtr->getXY();
std::cout << " Retrieved XY from cloned point. X = " << xyStored[0]
<< " Y = " << xyStored[1];
if (xyStored[0] == xyVals[0] && xyStored[1] == xyVals[1])
std::cout << " PASSED " << std::endl;
else
std::cout << " FAILED " << std::endl;
xyStored = mySecondPointPtr->getUserCoords();
std::cout << " Retrieved LL from modified, cloned point. Lon = " << xyStored[0]
<< " Lat = " << xyStored[1] << std::endl;
}
catch (DFLib::Util::Exception x)
{
std::cerr << "Ooops... got exception creating myFirstPoint"
<< x.getEmsg() << std::endl;
}
}