Commit d24632db authored by René Paris's avatar René Paris
Browse files

Merge branch 'feature/clang-format' into 'master'

.clang-format from simopenpass

See merge request !6
parents 4dd177ef 40e570a9
---
BasedOnStyle: Google
AccessModifierOffset: -2
AllowShortFunctionsOnASingleLine: Inline
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Allman
ColumnLimit: 0
......@@ -21,22 +21,21 @@
namespace mantle_api
{
/// Bounding box is defined in local entity coordinate system.
/// The origin of the entity coordinate system is defined in relation to the
/// geometric center.
struct BoundingBox
{
Vec3<units::length::meter_t> geometric_center{};
Dimension3 dimension{};
Vec3<units::length::meter_t> geometric_center{};
Dimension3 dimension{};
};
inline bool operator==(const BoundingBox& lhs, const BoundingBox& rhs) noexcept
{
return lhs.geometric_center == rhs.geometric_center &&
lhs.dimension == rhs.dimension;
return lhs.geometric_center == rhs.geometric_center &&
lhs.dimension == rhs.dimension;
}
} // namespace mantle_api
} // namespace mantle_api
#endif // MANTLEAPI_COMMON_BOUNDINGBOX_H
#endif // MANTLEAPI_COMMON_BOUNDINGBOX_H
......@@ -20,22 +20,21 @@
namespace mantle_api
{
struct Dimension3
{
units::length::meter_t length{0};
units::length::meter_t width{0};
units::length::meter_t height{0};
units::length::meter_t length{0};
units::length::meter_t width{0};
units::length::meter_t height{0};
};
inline bool operator==(const Dimension3& lhs, const Dimension3& rhs) noexcept
{
return IsEqual(lhs.length, rhs.length) && IsEqual(lhs.width, rhs.width) && IsEqual(lhs.height, rhs.height);
return IsEqual(lhs.length, rhs.length) && IsEqual(lhs.width, rhs.width) && IsEqual(lhs.height, rhs.height);
}
inline bool operator!=(const Dimension3& lhs, const Dimension3& rhs) noexcept
{
return !(lhs == rhs);
return !(lhs == rhs);
}
} // namespace mantle_api
......
......@@ -23,7 +23,6 @@
namespace mantle_api
{
/// @brief Compares two floating point numbers for equality.
///
/// **Attention** No approximation of the correct precision for the actual value is done!
......@@ -40,7 +39,7 @@ namespace mantle_api
/// @return True if both numbers are equal within the given precision.
inline bool IsEqual(double lhs, double rhs, double precision = std::numeric_limits<double>::epsilon())
{
return std::abs(lhs - rhs) < precision;
return std::abs(lhs - rhs) < precision;
}
/// @brief Compares two floating point numbers for equality.
......@@ -60,7 +59,7 @@ inline bool IsEqual(double lhs, double rhs, double precision = std::numeric_limi
template <typename T, class = typename std::enable_if_t<units::traits::is_unit_t<T>::value>>
bool IsEqual(T lhs, T rhs, double precision = std::numeric_limits<double>::epsilon())
{
return units::math::abs(lhs - rhs) < precision;
return units::math::abs(lhs - rhs) < precision;
}
/// @brief Compares two floating point numbers for equality.
......@@ -80,11 +79,11 @@ bool IsEqual(T lhs, T rhs, double precision = std::numeric_limits<double>::epsil
template <typename T, class = typename std::enable_if_t<units::traits::is_unit_t<T>::value>>
bool GreaterOrEqual(T lhs, T rhs, double precision = std::numeric_limits<double>::epsilon())
{
if (lhs > rhs)
{
return true;
}
return IsEqual(lhs, rhs, precision);
if (lhs > rhs)
{
return true;
}
return IsEqual(lhs, rhs, precision);
}
/// @brief Compares two floating point numbers for equality.
......@@ -104,11 +103,11 @@ bool GreaterOrEqual(T lhs, T rhs, double precision = std::numeric_limits<double>
template <typename T, class = typename std::enable_if_t<units::traits::is_unit_t<T>::value>>
bool LessOrEqual(T lhs, T rhs, double precision = std::numeric_limits<double>::epsilon())
{
if (lhs < rhs)
{
return true;
}
return IsEqual(lhs, rhs, precision);
if (lhs < rhs)
{
return true;
}
return IsEqual(lhs, rhs, precision);
}
} // namespace mantle_api
......
......@@ -26,16 +26,16 @@ constexpr UniqueId InvalidId{std::numeric_limits<UniqueId>::max()};
/// Common interface for all classes that can be referenced by an ID or name.
class IIdentifiable
{
public:
virtual ~IIdentifiable() = default;
/// The unique id is provided and maintained by the scenario simulator.
virtual UniqueId GetUniqueId() const = 0;
/// Scenario specific name of an object.
///
/// The scenario description is responsible for keeping the name unique.
virtual void SetName(const std::string& name) = 0;
virtual const std::string& GetName() const = 0;
public:
virtual ~IIdentifiable() = default;
/// The unique id is provided and maintained by the scenario simulator.
virtual UniqueId GetUniqueId() const = 0;
/// Scenario specific name of an object.
///
/// The scenario description is responsible for keeping the name unique.
virtual void SetName(const std::string& name) = 0;
virtual const std::string& GetName() const = 0;
};
} // namespace mantle_api
......
......@@ -20,7 +20,6 @@
namespace units
{
UNIT_ADD(angular_acceleration,
radians_per_second_squared,
radians_per_second_squared,
......@@ -38,40 +37,39 @@ UNIT_ADD_CATEGORY_TRAIT(angular_acceleration)
namespace mantle_api
{
template <typename T,
class = typename std::enable_if_t<units::traits::is_angle_unit<T>::value ||
units::traits::is_angular_velocity_unit<T>::value ||
units::traits::is_angular_acceleration_unit<T>::value>>
struct Orientation3
{
T yaw{};
T pitch{};
T roll{};
T yaw{};
T pitch{};
T roll{};
};
template <typename T>
inline bool operator==(const Orientation3<T>& lhs, const Orientation3<T>& rhs) noexcept
{
return IsEqual(lhs.yaw, rhs.yaw) && IsEqual(lhs.pitch, rhs.pitch) && IsEqual(lhs.roll, rhs.roll);
return IsEqual(lhs.yaw, rhs.yaw) && IsEqual(lhs.pitch, rhs.pitch) && IsEqual(lhs.roll, rhs.roll);
}
template <typename T>
inline bool operator!=(const Orientation3<T>& lhs, const Orientation3<T>& rhs) noexcept
{
return !(lhs == rhs);
return !(lhs == rhs);
}
template <typename T>
inline Orientation3<T> operator+(const Orientation3<T>& lhs, const Orientation3<T>& rhs) noexcept
{
return Orientation3<T>{lhs.yaw + rhs.yaw, lhs.pitch + rhs.pitch, lhs.roll + rhs.roll};
return Orientation3<T>{lhs.yaw + rhs.yaw, lhs.pitch + rhs.pitch, lhs.roll + rhs.roll};
}
template <typename T>
inline Orientation3<T> operator-(const Orientation3<T>& lhs, const Orientation3<T>& rhs) noexcept
{
return Orientation3<T>{lhs.yaw - rhs.yaw, lhs.pitch - rhs.pitch, lhs.roll - rhs.roll};
return Orientation3<T>{lhs.yaw - rhs.yaw, lhs.pitch - rhs.pitch, lhs.roll - rhs.roll};
}
} // namespace mantle_api
......
......@@ -23,35 +23,33 @@
namespace mantle_api
{
struct PolyLinePoint
{
Pose pose{};
std::optional<Time> time{};
Pose pose{};
std::optional<Time> time{};
bool operator== (const PolyLinePoint& other) const
{
return other.time == time
&& other.pose == pose;
}
bool operator==(const PolyLinePoint& other) const
{
return other.time == time && other.pose == pose;
}
friend std::ostream& operator<<(std::ostream& os, const PolyLinePoint& polyLinePoint);
friend std::ostream& operator<<(std::ostream& os, const PolyLinePoint& polyLinePoint);
};
inline std::ostream& operator<<(std::ostream& os, const PolyLinePoint& polyLinePoint)
{
os << polyLinePoint.pose;
os << polyLinePoint.pose;
if(polyLinePoint.time.has_value())
{
os << ", time in ms " << polyLinePoint.time.value().count();
}
if (polyLinePoint.time.has_value())
{
os << ", time in ms " << polyLinePoint.time.value().count();
}
return os;
return os;
}
using PolyLine = std::vector<PolyLinePoint>;
} // namespace mantle_api
} // namespace mantle_api
#endif // MANTLEAPI_COMMON_POLY_LINE_H
\ No newline at end of file
#endif // MANTLEAPI_COMMON_POLY_LINE_H
\ No newline at end of file
......@@ -17,41 +17,37 @@
#include <MantleAPI/Common/orientation.h>
#include <MantleAPI/Common/vector.h>
#include <units.h>
#include <iostream>
namespace mantle_api
{
struct Pose
{
Vec3<units::length::meter_t> position{};
Orientation3<units::angle::radian_t> orientation{};
Vec3<units::length::meter_t> position{};
Orientation3<units::angle::radian_t> orientation{};
bool operator== (const Pose& other) const
{
return other.position == position
&& other.orientation == orientation;
}
bool operator==(const Pose& other) const
{
return other.position == position && other.orientation == orientation;
}
friend inline std::ostream& operator<<(std::ostream& os, const Pose& pose);
friend inline std::ostream& operator<<(std::ostream& os, const Pose& pose);
};
std::ostream& operator<<(std::ostream& os, const Pose& pose)
{
os << "position ("
<< pose.position.x
<< ", " << pose.position.y
<< ", " << pose.position.z
<< "), orientation (" << pose.orientation.yaw
<< ", " << pose.orientation.pitch
<< ", " << pose.orientation.roll
<< ")";
return os;
os << "position ("
<< pose.position.x
<< ", " << pose.position.y
<< ", " << pose.position.z
<< "), orientation (" << pose.orientation.yaw
<< ", " << pose.orientation.pitch
<< ", " << pose.orientation.roll
<< ")";
return os;
}
} // namespace mantle_api
......
......@@ -25,29 +25,28 @@
namespace mantle_api
{
struct ReferencedObject
{
std::int32_t road{0};
std::int32_t lane{0};
std::int32_t road{0};
std::int32_t lane{0};
};
struct OpenDrivePosition
{
ReferencedObject referenced_object{};
ReferencedObject referenced_object{};
/// @brief Offset in s direction, unit: [m]
units::length::meter_t s_offset{0.0};
/// @brief Offset in t direction, unit: [m]
units::length::meter_t t_offset{0.0};
/// @brief Offset in s direction, unit: [m]
units::length::meter_t s_offset{0.0};
/// @brief Offset in t direction, unit: [m]
units::length::meter_t t_offset{0.0};
};
struct LatLonPosition
{
/// @brief GPS latitude, unit: [rad]
units::angle::radian_t latitude{0.0};
/// @brief GPS longitude, unit: [rad]
units::angle::radian_t longitude{0.0};
/// @brief GPS latitude, unit: [rad]
units::angle::radian_t latitude{0.0};
/// @brief GPS longitude, unit: [rad]
units::angle::radian_t longitude{0.0};
};
using Position = std::variant<OpenDrivePosition, LatLonPosition, Vec3<units::length::meter_t>>;
......@@ -57,14 +56,14 @@ using Position = std::variant<OpenDrivePosition, LatLonPosition, Vec3<units::len
/// **Attention** Floating-point comparision may require tweaks in precision.
inline bool operator==(const OpenDrivePosition& lhs, const OpenDrivePosition& rhs) noexcept
{
return lhs.referenced_object.road == rhs.referenced_object.road &&
lhs.referenced_object.lane == rhs.referenced_object.lane && IsEqual(lhs.s_offset, rhs.s_offset) &&
IsEqual(lhs.t_offset, rhs.t_offset);
return lhs.referenced_object.road == rhs.referenced_object.road &&
lhs.referenced_object.lane == rhs.referenced_object.lane && IsEqual(lhs.s_offset, rhs.s_offset) &&
IsEqual(lhs.t_offset, rhs.t_offset);
}
inline bool operator!=(const OpenDrivePosition& lhs, const OpenDrivePosition& rhs) noexcept
{
return !(lhs == rhs);
return !(lhs == rhs);
}
/// @brief Equality comparison for LatLonPosition.
......@@ -72,12 +71,12 @@ inline bool operator!=(const OpenDrivePosition& lhs, const OpenDrivePosition& rh
/// **Attention** Floating-point comparision may require tweaks in precision.
inline bool operator==(const LatLonPosition& lhs, const LatLonPosition& rhs) noexcept
{
return IsEqual(lhs.latitude, rhs.latitude) && IsEqual(lhs.longitude, rhs.longitude);
return IsEqual(lhs.latitude, rhs.latitude) && IsEqual(lhs.longitude, rhs.longitude);
}
inline bool operator!=(const LatLonPosition& lhs, const LatLonPosition& rhs) noexcept
{
return !(lhs == rhs);
return !(lhs == rhs);
}
} // namespace mantle_api
......
......@@ -19,11 +19,10 @@
namespace mantle_api
{
struct SimulationTime
{
Time current_sim_time{0};
Time last_delta_time{0};
Time current_sim_time{0};
Time last_delta_time{0};
};
} // namespace mantle_api
......
......@@ -25,39 +25,38 @@
namespace mantle_api
{
template <typename T>
struct SplineSegment
{
Vec3<T> a;
Vec3<T> b;
Vec3<T> c;
Vec3<T> d;
Vec3<T> a;
Vec3<T> b;
Vec3<T> c;
Vec3<T> d;
};
template <typename T, class = typename std::enable_if_t<units::traits::is_unit_t<T>::value>>
struct SplineSection
{
Time start_time{0};
Time end_time{0};
/// @brief Represents the polynomial.
///
/// The array stores in format \f$[a_3, a_2, a_1, a_0]\f$ for a polynomial in form
/// \f[
/// P(x) = \sum_{i=0}^{3} a_{i} x^{i} = a_3 x^3 + a_2 x^2 + a_1 x + a_0
/// \f]
std::array<T, 4> polynomial{0, 0, 0, 0};
Time start_time{0};
Time end_time{0};
/// @brief Represents the polynomial.
///
/// The array stores in format \f$[a_3, a_2, a_1, a_0]\f$ for a polynomial in form
/// \f[
/// P(x) = \sum_{i=0}^{3} a_{i} x^{i} = a_3 x^3 + a_2 x^2 + a_1 x + a_0
/// \f]
std::array<T, 4> polynomial{0, 0, 0, 0};
};
/// @brief Equality comparison for SplineSection.
template <typename T, class = typename std::enable_if_t<units::traits::is_unit_t<T>::value>>
inline bool operator==(const SplineSection<T>& lhs, const SplineSection<T>& rhs) noexcept
{
return lhs.start_time == rhs.start_time && lhs.end_time == rhs.end_time &&
std::equal(lhs.polynomial.begin(),
lhs.polynomial.end(),
rhs.polynomial.begin(),
[](const T& a, const T& b) { return IsEqual(a, b); });
return lhs.start_time == rhs.start_time && lhs.end_time == rhs.end_time &&
std::equal(lhs.polynomial.begin(),
lhs.polynomial.end(),
rhs.polynomial.begin(),
[](const T& a, const T& b) { return IsEqual(a, b); });
}
} // namespace mantle_api
......
......@@ -28,7 +28,7 @@ using Time = units::time::millisecond_t;
template <typename T>
inline Time SecondsToTime(T duration)
{
return units::convert<units::time::seconds, Time>(duration);
return units::convert<units::time::seconds, Time>(duration);
}
/// @brief Converts input @ref Time to [s].
......@@ -36,7 +36,7 @@ inline Time SecondsToTime(T duration)
/// @return Duration in seconds representing the passed in @ref Time.
inline double TimeToSeconds(const Time& time)
{
return units::time::second_t{time}.value();
return units::time::second_t{time}.value();
}
} // namespace mantle_api
......
......@@ -15,39 +15,39 @@
#ifndef MANTLEAPI_COMMON_TRAJECTORY_H
#define MANTLEAPI_COMMON_TRAJECTORY_H
#include <MantleAPI/Common/poly_line.h>
#include <string>
#include <variant>
#include <MantleAPI/Common/poly_line.h>
namespace mantle_api
{
struct Trajectory
{
std::string name;
std::variant<PolyLine> type;
std::string name;
std::variant<PolyLine> type;
friend std::ostream& operator<<(std::ostream& os, const Trajectory& trajectory);
friend std::ostream& operator<<(std::ostream& os, const Trajectory& trajectory);
};
inline std::ostream& operator<<(std::ostream& os, const Trajectory& trajectory)
{
os << "Trajectory \"" << trajectory.name;
if(std::holds_alternative<PolyLine>(trajectory.type))
os << "Trajectory \"" << trajectory.name;
if (std::holds_alternative<PolyLine>(trajectory.type))
{
const auto& polyLine = std::get<PolyLine>(trajectory.type);
for (const auto& polyLinePoint : polyLine)
{
const auto &polyLine = std::get<PolyLine>(trajectory.type);
for (const auto &polyLinePoint : polyLine)
{
os << polyLinePoint;
}
os << polyLinePoint;
}
os << "\"\n";
}
os << "\"\n";
return os;
return os;
}
} // namespace mantle_api
} // namespace mantle_api
#endif // MANTLEAPI_COMMON_TRAJECTORY_H
\ No newline at end of file
#endif // MANTLEAPI_COMMON_TRAJECTORY_H
\ No newline at end of file
......@@ -24,85 +24,85 @@ namespace mantle_api
template <typename T, class = typename std::enable_if_t<units::traits::is_unit_t<T>::value>>
struct Vec3
{
T x{0};
T y{0};
T z{0};
T x{0};
T y{0};
T z{0};
inline T Length() const { return sqrt((x * x) + (y * y) + (z * z)); }
inline T Length() const { return sqrt((x * x) + (y * y) + (z * z)); }
};
template <typename T>
inline bool operator==(const Vec3<T>& lhs, const Vec3<T>& rhs) noexcept
{
return IsEqual(lhs.x, rhs.x) && IsEqual(lhs.y, rhs.y) && IsEqual(lhs.z, rhs.z);
return IsEqual(lhs.x, rhs.x) && IsEqual(lhs.y, rhs.y) && IsEqual(lhs.z, rhs.z);
}
template <typename T>
inline bool operator!=(const Vec3<T>& lhs, const Vec3<T>& rhs) noexcept
{
return !(lhs == rhs);
return !(lhs == rhs);
}
template <typename T>
inline Vec3<T> operator-(const Vec3<T>& lhs, const Vec3<T>& rhs) noexcept
{
return {lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z};
return {lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z};
}
template <typename T>
inline Vec3<T> operator+(const Vec3<T>& lhs, const Vec3<T>& rhs) noexcept
{
return {lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z};
return {lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z};