    

 ## On this page

  

 

 # simulation\_framework::evaluator::DistanceDrivenCalculator Class Reference

 Last update: 16.07.2025 

class [DistanceDrivenCalculator](classsimulation__framework_1_1evaluator_1_1DistanceDrivenCalculator.xhtml "class DistanceDrivenCalculator") [More...](classsimulation__framework_1_1evaluator_1_1DistanceDrivenCalculator.xhtml#details)

`#include <<a class="el" href="distance__calculator_8h_source.xhtml">distance_calculator.h</a>>`

## <a id="pub-methods" name="pub-methods"></a>Public Member Functions

double [Calculate](classsimulation__framework_1_1evaluator_1_1DistanceDrivenCalculator.xhtml#ab8226778bd055bda3a5b216f57289092) (const osi3::GroundTruth &amp;ground\_truth) <a id="details" name="details"></a>## Detailed Description

class [DistanceDrivenCalculator](classsimulation__framework_1_1evaluator_1_1DistanceDrivenCalculator.xhtml "class DistanceDrivenCalculator")

[DistanceDrivenCalculator](classsimulation__framework_1_1evaluator_1_1DistanceDrivenCalculator.xhtml "class DistanceDrivenCalculator") class to calculate the total distance covered/driven by an Ego car based on osi GroundTruth Algorithm explaination:

1. Find out the Ego vehicle index within MovingObject list from GroundTruth and compute the BoundingBox
2. Get the position of Ego vehicle at each time interval/step.
3. Calculate the Eucledian distance between two positions of Ego vehicle(at given time stamp)
4. Make the sum of all the distances calculated(For each time step)
5. One of the possible validation method could be to calculate distance from Formulas based on the Average car Velocity and total travel Time. And compare the result with distance calculated using Euclidean method.
6. For now, we have added a few tests based on hard-coded values of position, which helps to confirm/validate the basic logic of distance driven calculation.

Definition at line [38](distance__calculator_8h_source.xhtml#l00038) of file [distance\_calculator.h](distance__calculator_8h_source.xhtml).



## Member Function Documentation

<a id="ab8226778bd055bda3a5b216f57289092" name="ab8226778bd055bda3a5b216f57289092"></a>## [◆ ](#ab8226778bd055bda3a5b216f57289092)Calculate()

 double simulation\_framework::evaluator::DistanceDrivenCalculator::Calculate  ( const osi3::GroundTruth &amp;  *ground\_truth*) 

Definition at line [12](distance__calculator_8cpp_source.xhtml#l00012) of file [distance\_calculator.cpp](distance__calculator_8cpp_source.xhtml).

 13{

 14 double distance = 0.0;

 15 auto host_vehicle_index = std::make_optional&lt;int&gt;();

 16 

 17 const auto&amp; host_vehicle_id = ground_truth.host_vehicle_id();

 18 const auto moving_objects_count = ground_truth.moving_object_size();

 19 

 20 for (int i = 0; i &lt; moving_objects_count; ++i)

 21 {

 22 if (host_vehicle_id.value() == ground_truth.moving_object(i).id().value())

 23 {

 24 host_vehicle_index.value() = i;

 25 break;

 26 }

 27 }

 28 

 29 if (!host_vehicle_index.has_value())

 30 {

 31 return distance;

 32 }

 33 

 34 const auto&amp; host_vehicle_base = ground_truth.moving_object(host_vehicle_index.value()).base();

 35 

 36 if (!is_initialized_)

 37 {

 38 is_initialized_ = true;

 39 last_xpos_ = host_vehicle_base.position().x();

 40 last_ypos_ = host_vehicle_base.position().y();

 41 return 0;

 42 }

 43 

 44 double current_xpos = host_vehicle_base.position().x();

 45 double current_ypos = host_vehicle_base.position().y();

 46 

 47 // Values to be substituted in the standard Euclidean distance formula

 48 const auto delta_xpos = last_xpos_.value() - current_xpos;

 49 const auto delta_ypos = last_ypos_.value() - current_ypos;

 50 

 51 // Euclidean distance formula to calculate distance between two points/positions.

 52 distance = std::sqrt((delta_xpos * delta_xpos) + (delta_ypos * delta_ypos));

 53 

 54 // Update value of last position values with the recent current position value.

 55 last_xpos_ = current_xpos;

 56 last_ypos_ = current_ypos;

 57 

 58 return distance;

 59}







---

The documentation for this class was generated from the following files:- [distance\_calculator.h](distance__calculator_8h_source.xhtml)
- [distance\_calculator.cpp](distance__calculator_8cpp_source.xhtml)