@@ -353,49 +353,21 @@ double getPathDistance(const DataFacade<Algorithm> &facade,
353
353
const PhantomNode &source_phantom,
354
354
const PhantomNode &target_phantom)
355
355
{
356
- using util::coordinate_calculation::detail::DEGREE_TO_RAD;
357
- using util::coordinate_calculation::detail::EARTH_RADIUS;
358
-
359
- double distance = 0 ;
360
- double prev_lat =
361
- static_cast <double >(util::toFloating (source_phantom.location .lat )) * DEGREE_TO_RAD;
362
- double prev_lon =
363
- static_cast <double >(util::toFloating (source_phantom.location .lon )) * DEGREE_TO_RAD;
364
- double prev_cos = std::cos (prev_lat);
356
+ double distance = 0.0 ;
357
+ auto prev_coordinate = source_phantom.location ;
358
+
365
359
for (const auto &p : unpacked_path)
366
360
{
367
361
const auto current_coordinate = facade.GetCoordinateOfNode (p.turn_via_node );
368
362
369
- const double current_lat =
370
- static_cast <double >(util::toFloating (current_coordinate.lat )) * DEGREE_TO_RAD;
371
- const double current_lon =
372
- static_cast <double >(util::toFloating (current_coordinate.lon )) * DEGREE_TO_RAD;
373
- const double current_cos = std::cos (current_lat);
374
-
375
- const double sin_dlon = std::sin ((prev_lon - current_lon) / 2.0 );
376
- const double sin_dlat = std::sin ((prev_lat - current_lat) / 2.0 );
377
-
378
- const double aharv = sin_dlat * sin_dlat + prev_cos * current_cos * sin_dlon * sin_dlon;
379
- const double charv = 2 . * std::atan2 (std::sqrt (aharv), std::sqrt (1.0 - aharv));
380
- distance += EARTH_RADIUS * charv;
363
+ distance +=
364
+ util::coordinate_calculation::greatCircleDistance (prev_coordinate, current_coordinate);
381
365
382
- prev_lat = current_lat;
383
- prev_lon = current_lon;
384
- prev_cos = current_cos;
366
+ prev_coordinate = current_coordinate;
385
367
}
386
368
387
- const double current_lat =
388
- static_cast <double >(util::toFloating (target_phantom.location .lat )) * DEGREE_TO_RAD;
389
- const double current_lon =
390
- static_cast <double >(util::toFloating (target_phantom.location .lon )) * DEGREE_TO_RAD;
391
- const double current_cos = std::cos (current_lat);
392
-
393
- const double sin_dlon = std::sin ((prev_lon - current_lon) / 2.0 );
394
- const double sin_dlat = std::sin ((prev_lat - current_lat) / 2.0 );
395
-
396
- const double aharv = sin_dlat * sin_dlat + prev_cos * current_cos * sin_dlon * sin_dlon;
397
- const double charv = 2 . * std::atan2 (std::sqrt (aharv), std::sqrt (1.0 - aharv));
398
- distance += EARTH_RADIUS * charv;
369
+ distance +=
370
+ util::coordinate_calculation::greatCircleDistance (prev_coordinate, target_phantom.location );
399
371
400
372
return distance;
401
373
}
0 commit comments