diff --git a/udemy-cpp/exc01/AdFunctions.cc b/udemy-cpp/exc01/AdFunctions.cc index 6bf3576..53f2ef1 100644 --- a/udemy-cpp/exc01/AdFunctions.cc +++ b/udemy-cpp/exc01/AdFunctions.cc @@ -4,3 +4,45 @@ #include "AdConstants.h" #include "AdFunctions.h" + +namespace Ad +{ +namespace Utils +{ + +constexpr float kph_to_mps(const float kph) +{ + return 0.2778 * kph; +} + +} // namespace Ad::Utils + +namespace Data +{ + +Types::Vehicle init_ego_vehicle() +{ + Types::Vehicle ev = + {.id = Constants::EGO_VEHICLE_ID, + .lane = Types::Lane::Center, + .speed_mps = Utils::kph_to_mps(135), + .rel_distance_m = 0, + }; + return ev; +} + +} // namespace Ad::Data + +namespace Visualize +{ + +void print_vehicle(const Types::Vehicle vehicle) +{ + std::cout << "Vehicle " << vehicle.id << '\n'; + std::cout << "speed : " << vehicle.speed_mps << " m/s\n"; + std::cout << "distance : " << vehicle.rel_distance_m << " m\n"; +} + +} // namespace Ad::Visualize + +} // namespace Ad diff --git a/udemy-cpp/exc01/AdFunctions.h b/udemy-cpp/exc01/AdFunctions.h index e1ff169..9859ebe 100644 --- a/udemy-cpp/exc01/AdFunctions.h +++ b/udemy-cpp/exc01/AdFunctions.h @@ -1,3 +1,22 @@ #pragma once #include "AdTypes.h" + +namespace Ad +{ +namespace Utils +{ + constexpr float kph_to_mps(const float kph); +} // namespace Ad::Utils + +namespace Data +{ + Types::Vehicle init_ego_vehicle(); +} // namespace Ad::Data + +namespace Visualize +{ + void print_vehicle(const Types::Vehicle vehicle); +} // namespace Ad::Visualize + +} // namespace Ad diff --git a/udemy-cpp/exc01/AdTypes.h b/udemy-cpp/exc01/AdTypes.h index 7c13713..4a1dad4 100644 --- a/udemy-cpp/exc01/AdTypes.h +++ b/udemy-cpp/exc01/AdTypes.h @@ -3,3 +3,27 @@ #include #include "AdConstants.h" + +namespace Ad +{ +namespace Types +{ + +enum class Lane +{ + Unknown, + Left, + Center, + Right, +}; + +struct Vehicle +{ + std::int32_t id; + Lane lane; + double speed_mps; + double rel_distance_m; +}; + +} // namespace Types +} // namespace Ad