@@ -18,6 +18,16 @@ void assertLocalizationAccuracy(
1818 ASSERT_NEAR (expectedCoord.longitude (), predictedCoord.longitude (), longitudeDegThreshold);
1919}
2020
21+ void assertDistanceAccuracy (
22+ double distancePredicted,
23+ double distanceExpected,
24+ double distanceThreshold = 0.03 ) {
25+
26+ SCOPED_TRACE (::testing::Message () << " \n Expected Distance, Long: " << distancePredicted << " , "
27+ << " \n Predicted Distance, Long: " << distanceExpected );
28+
29+ ASSERT_NEAR (distancePredicted, distanceExpected, distanceExpected * distanceThreshold);
30+ }
2131
2232TEST (CVLocalization, LocalizationAccuracy) {
2333 struct TestCase {
@@ -132,3 +142,158 @@ TEST(CVLocalization, LocalizationAccuracy) {
132142 assertLocalizationAccuracy (testCase.expectedTargetCoord , gsdTargetCoord);
133143 };
134144}
145+
146+ TEST (CVLocalization, DistanceAccuracy) {
147+ struct DistanceTestCase {
148+ std::string name;
149+
150+ double lat1;
151+ double lon1;
152+ double lat2;
153+ double lon2;
154+
155+ double expectedDistance;
156+ };
157+
158+ const std::vector<DistanceTestCase> distanceTestCases{{
159+ {
160+ // coordinate 1 (0N, 0W)
161+ // coordinate 2 (20S, 0W)
162+ // esitmitated distance from https://www.omnicalculator.com/other/latitude-longitude-distance is 2223 km
163+
164+ " Coordinates of Distance 1" ,
165+ 0 ,
166+ 0 ,
167+ -20 ,
168+ 0 ,
169+
170+ 2223899 ,
171+ },
172+
173+ {
174+ // coordinate 3 (20N, 0W)
175+ // coordinate 4 (53N, 109W)
176+ // esitmitated distance from https://www.omnicalculator.com/other/latitude-longitude-distance is 9439557 m
177+
178+ " Coordinates of Distance 2" ,
179+ 20 ,
180+ 0 ,
181+ 53 ,
182+ -109 ,
183+
184+ 9439557 ,
185+ },
186+
187+ {
188+ // coordinate 5 (20N, 35W)
189+ // coordinate 6 (20S, 0W)
190+ // esitmitated distance from https://www.omnicalculator.com/other/latitude-longitude-distance is 5857063 m
191+
192+ " Coordinates of Distance 3" ,
193+ 20 ,
194+ -35 ,
195+ -20 ,
196+ 0 ,
197+
198+ 5857063 ,
199+ },
200+
201+ {
202+ // coordinate 7 (20N, 40E)
203+ // coordinate 8 (50N, 65W)
204+ // esitmitated distance from https://www.omnicalculator.com/other/latitude-longitude-distance is 9333060 m
205+
206+ " Coordinates of Distance 4" ,
207+ 20 ,
208+ 40 ,
209+ 50 ,
210+ -65 ,
211+
212+ 9333060 ,
213+ },
214+
215+ {
216+ // coordinate 9 (40.459N, 50.459E)
217+ // coordinate 10 (40.46N, 50.46E)
218+ // esitmitated distance from https://www.omnicalculator.com/other/latitude-longitude-distance is 139.72 m
219+
220+ " Coordinates of Distance 5" ,
221+ 40.459 ,
222+ 50.459 ,
223+ 40.46 ,
224+ 50.46 ,
225+
226+ 139.72 ,
227+ },
228+
229+ {
230+ // coordinate 11 (50.1123N, 45.1234E)
231+ // coordinate 12 (50.11235N, 45.1234E)
232+ // esitmitated distance from https://www.omnicalculator.com/other/latitude-longitude-distance is 5.56 m
233+
234+ " Coordinates of Distance 6" ,
235+ 50.1123 ,
236+ 45.1234 ,
237+ 50.11235 ,
238+ 45.1234 ,
239+
240+ 5.56 ,
241+ },
242+
243+ {
244+ // coordinate 13 (5.123N, 2.345E)
245+ // coordinate 14 (5.122N, 2.345E)
246+ // esitmitated distance from https://www.omnicalculator.com/other/latitude-longitude-distance is 111.2 m
247+
248+ " Coordinates of Distance 7" ,
249+ 5.123 ,
250+ 2.345 ,
251+ 5.122 ,
252+ 2.345 ,
253+
254+ 111.2 ,
255+ },
256+
257+ {
258+ // coordinate 15 (5.123N, 2.345E)
259+ // coordinate 16 (5.1231N, 2.3452E)
260+ // esitmitated distance from https://www.omnicalculator.com/other/latitude-longitude-distance is 24.785 m
261+
262+ " Coordinates of Distance 8" ,
263+ 5.123 ,
264+ 2.345 ,
265+ 5.1231 ,
266+ 2.3452 ,
267+
268+ 24.785 ,
269+ },
270+
271+ {
272+ // DUMMY TEST (the same coordinate)
273+ " DUMMY TEST" ,
274+ 20 ,
275+ 109 ,
276+ 20 ,
277+ 109 ,
278+
279+ 0 ,
280+ },
281+
282+ }};
283+
284+ for (const auto &distanceTestCase : distanceTestCases) {
285+ GSDLocalization gsdLocalization;
286+ std::cout << " Test case: " << distanceTestCase.name << std::endl;
287+
288+ // GPSCoord ecefTargetCoord = ecefLocalizer.localize(testCase.inputImageTelemetry, testCase.inputTargetBbox);
289+ // assertLocalizationAccuracy(testCase.expectedTargetCoord, ecefTargetCoord);
290+
291+ double distanceTargeted = gsdLocalization.distanceInMetersBetweenCords (distanceTestCase.lat1 , distanceTestCase.lon1 ,
292+ distanceTestCase.lat2 , distanceTestCase.lon2 );
293+
294+ std::cout << " Estimated Distance " << distanceTargeted << std::endl << " Expected Distance" << distanceTestCase.expectedDistance << std::endl;
295+
296+ assertDistanceAccuracy (distanceTestCase.expectedDistance , distanceTargeted);
297+ };
298+ }
299+
0 commit comments