Gazebo Math

API Reference

8.1.0
Helpers.hh File Reference
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdint>
#include <ostream>
#include <limits>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <gz/math/config.hh>
#include "gz/math/Export.hh"

Go to the source code of this file.

Namespaces

namespace  gz
 
namespace  gz::math
 

Macros

#define GZ_BOX_VOLUME(_x, _y, _z)   (_x *_y * _z)
 Compute box volume.
 
#define GZ_BOX_VOLUME_V(_v)   (_v.X() *_v.Y() * _v.Z())
 Compute box volume from a vector.
 
#define GZ_CONE_VOLUME(_r, _l)   (_l * GZ_PI * std::pow(_r, 2) / 3.0)
 Compute cone volume.
 
#define GZ_CYLINDER_VOLUME(_r, _l)   (_l * GZ_PI * std::pow(_r, 2))
 Compute cylinder volume.
 
#define GZ_FP_VOLATILE
 Define GZ_FP_VOLATILE for FP equality comparisons Use volatile parameters when checking floating point equality on the 387 math coprocessor to work around bugs from the 387 extra precision.
 
#define GZ_PI   3.14159265358979323846
 Define GZ_PI, GZ_PI_2, and GZ_PI_4. This was put here for Windows support.
 
#define GZ_PI_2   1.57079632679489661923
 
#define GZ_PI_4   0.78539816339744830962
 
#define GZ_SPHERE_VOLUME(_radius)   (4.0*GZ_PI*std::pow(_radius, 3)/3.0)
 Compute sphere volume.
 
#define GZ_SQRT2   1.41421356237309504880
 

Typedefs

typedef std::chrono::duration< uint64_t, std::ratio< 86400 > > days
 This will exist in C++-20.
 
using PairInput = uint32_t
 
using PairOutput = uint64_t
 

Functions

template<>
void appendToStream (std::ostream &_out, int _number)
 Append a number to a stream, specialized for int.
 
template<typename T >
void appendToStream (std::ostream &_out, T _number)
 Append a number to a stream. Makes sure "-0" is returned as "0".
 
template<class... Durations, class DurationIn >
std::tuple< Durations... > breakDownDurations (DurationIn d)
 break down durations NOTE: the template arguments must be properly ordered according to magnitude and there can be no duplicates. This function uses the braces initializer to split all the templated duration. The initializer will be called recursievely due the ...
 
template<typename T >
clamp (T _v, T _min, T _max)
 Simple clamping function that constrains a value to a range defined by a min and max value. This function is equivalent to std::max(std::min(value, max), min).
 
std::pair< int64_t, int64_t > durationToSecNsec (const std::chrono::steady_clock::duration &_dur)
 Convert a std::chrono::steady_clock::duration to a seconds and nanoseconds pair.
 
std::string durationToString (const std::chrono::steady_clock::duration &_duration)
 Convert a std::chrono::steady_clock::duration to a string.
 
template<typename T >
bool equal (const T &_a, const T &_b, const T &_epsilon=T(1e-6))
 Check if two values are equal, within a tolerance.
 
double fixnan (double _v)
 Fix a double NaN value.
 
float fixnan (float _v)
 Fix a float NaN value.
 
template<typename T >
bool greaterOrNearEqual (const T &_a, const T &_b, const T &_epsilon=1e-6)
 Greater than or near test, within a tolerance.
 
bool isEven (const int _v)
 Check if an int is even.
 
bool isEven (const unsigned int _v)
 Check if an unsigned int is even.
 
bool isnan (double _v)
 Check if a double is NaN.
 
bool isnan (float _v)
 Check if a float is NaN.
 
bool isOdd (const int _v)
 Check if an int is odd.
 
bool isOdd (const unsigned int _v)
 Check if an unsigned int is odd.
 
bool isPowerOfTwo (unsigned int _x)
 Is the parameter a power of 2?
 
bool isTimeString (const std::string &_timeString)
 Check if the given string represents a time. An example time string is "0 00:00:00.000", which has the format "DAYS HOURS:MINUTES:SECONDS.MILLISECONDS".
 
template<typename T >
bool lessOrNearEqual (const T &_a, const T &_b, const T &_epsilon=1e-6)
 Less than or near test, within a tolerance.
 
template<typename T >
max (const std::vector< T > &_values)
 Get the maximum value of vector of values.
 
template<typename T >
mean (const std::vector< T > &_values)
 Get mean value in a vector of values.
 
template<typename T >
min (const std::vector< T > &_values)
 Get the minimum value of vector of values.
 
PairOutput Pair (const PairInput _a, const PairInput _b)
 A pairing function that maps two values to a unique third value. This is an implementation of Szudzik's function.
 
double parseFloat (const std::string &_input)
 parse string into float.
 
int parseInt (const std::string &_input)
 Parse string into an integer.
 
template<typename T >
precision (const T &_a, const unsigned int &_precision)
 Get the value at a specified precision.
 
int roundUpMultiple (int _num, int _multiple)
 Round a number up to the nearest multiple. For example, if the input number is 12 and the multiple is 10, the result is 20. If the input number is negative, then the nearest multiple will be greater than or equal to the input number. For example, if the input number is -9 and the multiple is 2 then the output is -8.
 
unsigned int roundUpPowerOfTwo (unsigned int _x)
 Get the smallest power of two that is greater than or equal to a given value.
 
std::chrono::steady_clock::duration secNsecToDuration (const uint64_t &_sec, const uint64_t &_nanosec)
 Convert seconds and nanoseconds to std::chrono::steady_clock::duration.
 
std::chrono::steady_clock::time_point secNsecToTimePoint (const uint64_t &_sec, const uint64_t &_nanosec)
 Convert seconds and nanoseconds to std::chrono::steady_clock::time_point.
 
template<typename T >
int sgn (T _value)
 The signum function.
 
template<typename T >
int signum (T _value)
 The signum function.
 
template<typename T >
void sort2 (T &_a, T &_b)
 Sort two numbers, such that _a <= _b.
 
template<typename T >
void sort3 (T &_a, T &_b, T &_c)
 Sort three numbers, such that _a <= _b <= _c.
 
bool splitTimeBasedOnTimeRegex (const std::string &_timeString, uint64_t &numberDays, uint64_t &numberHours, uint64_t &numberMinutes, uint64_t &numberSeconds, uint64_t &numberMilliseconds)
 Split a std::chrono::steady_clock::duration to a string.
 
std::chrono::steady_clock::duration stringToDuration (const std::string &_timeString)
 Convert a string to a std::chrono::steady_clock::duration.
 
std::chrono::steady_clock::time_point stringToTimePoint (const std::string &_timeString)
 Convert a string to a std::chrono::steady_clock::time_point.
 
std::pair< int64_t, int64_t > timePointToSecNsec (const std::chrono::steady_clock::time_point &_time)
 Convert a std::chrono::steady_clock::time_point to a seconds and nanoseconds pair.
 
std::string timePointToString (const std::chrono::steady_clock::time_point &_point)
 Convert a std::chrono::steady_clock::time_point to a string.
 
std::tuple< PairInput, PairInputUnpair (const PairOutput _key)
 The reverse of the Pair function. Accepts a key, produced from the Pair function, and returns a tuple consisting of the two non-negative integer values used to create the _key.
 
template<typename T >
variance (const std::vector< T > &_values)
 Get the variance of a vector of values.
 

Variables

static const size_t GZ_EIGHT_SIZE_T = 8u
 size_t type with a value of 8
 
static const size_t GZ_FIVE_SIZE_T = 5u
 size_t type with a value of 5
 
static const size_t GZ_FOUR_SIZE_T = 4u
 size_t type with a value of 4
 
template<typename T >
constexpr T GZ_MASSMATRIX3_DEFAULT_TOLERANCE = T(10)
 The default tolerance value used by MassMatrix3::IsValid(), MassMatrix3::IsPositive(), and MassMatrix3::ValidMoments()
 
static const size_t GZ_NINE_SIZE_T = 9u
 size_t type with a value of 9
 
static const size_t GZ_ONE_SIZE_T = 1u
 size_t type with a value of 1
 
static const size_t GZ_SEVEN_SIZE_T = 7u
 size_t type with a value of 7
 
static const size_t GZ_SIX_SIZE_T = 6u
 size_t type with a value of 6
 
static const size_t GZ_THREE_SIZE_T = 3u
 size_t type with a value of 3
 
static const size_t GZ_TWO_SIZE_T = 2u
 size_t type with a value of 2
 
static const size_t GZ_ZERO_SIZE_T = 0u
 size_t type with a value of 0
 
static const double INF_D = std::numeric_limits<double>::infinity()
 Double positive infinite value.
 
static const float INF_F = std::numeric_limits<float>::infinity()
 float positive infinite value
 
static const int16_t INF_I16 = std::numeric_limits<int16_t>::infinity()
 16-bit unsigned integer positive infinite value
 
static const int32_t INF_I32 = std::numeric_limits<int32_t>::infinity()
 32-bit unsigned integer positive infinite value
 
static const int64_t INF_I64 = std::numeric_limits<int64_t>::infinity()
 64-bit unsigned integer positive infinite value
 
static const uint16_t INF_UI16 = std::numeric_limits<uint16_t>::infinity()
 16-bit unsigned integer positive infinite value
 
static const uint32_t INF_UI32 = std::numeric_limits<uint32_t>::infinity()
 32-bit unsigned integer positive infinite value
 
static const uint64_t INF_UI64 = std::numeric_limits<uint64_t>::infinity()
 64-bit unsigned integer positive infinite value
 
static const double LOW_D = std::numeric_limits<double>::lowest()
 Double low value, equivalent to -MAX_D.
 
static const float LOW_F = std::numeric_limits<float>::lowest()
 Float low value, equivalent to -MAX_F.
 
static const int16_t LOW_I16 = std::numeric_limits<int16_t>::lowest()
 16bit unsigned integer lowest value. This is equivalent to GZ_INT16_MIN, and is defined here for completeness.
 
static const int32_t LOW_I32 = std::numeric_limits<int32_t>::lowest()
 32bit unsigned integer lowest value. This is equivalent to GZ_INT32_MIN, and is defined here for completeness.
 
static const int64_t LOW_I64 = std::numeric_limits<int64_t>::lowest()
 64bit unsigned integer lowest value. This is equivalent to GZ_INT64_MIN, and is defined here for completeness.
 
static const uint16_t LOW_UI16 = std::numeric_limits<uint16_t>::lowest()
 16bit unsigned integer lowest value. This is equivalent to GZ_UINT16_MIN, and is defined here for completeness.
 
static const uint32_t LOW_UI32 = std::numeric_limits<uint32_t>::lowest()
 32bit unsigned integer lowest value. This is equivalent to GZ_UINT32_MIN, and is defined here for completeness.
 
static const uint64_t LOW_UI64 = std::numeric_limits<uint64_t>::lowest()
 64bit unsigned integer lowest value. This is equivalent to GZ_UINT64_MIN, and is defined here for completeness.
 
static const double MAX_D = std::numeric_limits<double>::max()
 Double maximum value. This value will be similar to 1.79769e+308.
 
static const float MAX_F = std::numeric_limits<float>::max()
 Float maximum value. This value will be similar to 3.40282e+38.
 
static const int16_t MAX_I16 = std::numeric_limits<int16_t>::max()
 16bit unsigned integer maximum value
 
static const int32_t MAX_I32 = std::numeric_limits<int32_t>::max()
 32bit unsigned integer maximum value
 
static const int64_t MAX_I64 = std::numeric_limits<int64_t>::max()
 64bit unsigned integer maximum value
 
static const uint16_t MAX_UI16 = std::numeric_limits<uint16_t>::max()
 16bit unsigned integer maximum value
 
static const uint32_t MAX_UI32 = std::numeric_limits<uint32_t>::max()
 32bit unsigned integer maximum value
 
static const uint64_t MAX_UI64 = std::numeric_limits<uint64_t>::max()
 64bit unsigned integer maximum value
 
static const double MIN_D = std::numeric_limits<double>::min()
 Double min value. This value will be similar to 2.22507e-308.
 
static const float MIN_F = std::numeric_limits<float>::min()
 Float minimum value. This value will be similar to 1.17549e-38.
 
static const int16_t MIN_I16 = std::numeric_limits<int16_t>::min()
 16bit unsigned integer minimum value
 
static const int32_t MIN_I32 = std::numeric_limits<int32_t>::min()
 32bit unsigned integer minimum value
 
static const int64_t MIN_I64 = std::numeric_limits<int64_t>::min()
 64bit unsigned integer minimum value
 
static const uint16_t MIN_UI16 = std::numeric_limits<uint16_t>::min()
 16bit unsigned integer minimum value
 
static const uint32_t MIN_UI32 = std::numeric_limits<uint32_t>::min()
 32bit unsigned integer minimum value
 
static const uint64_t MIN_UI64 = std::numeric_limits<uint64_t>::min()
 64bit unsigned integer minimum value
 
static const double NAN_D = std::numeric_limits<double>::quiet_NaN()
 Returns the representation of a quiet not a number (NAN)
 
static const float NAN_F = std::numeric_limits<float>::quiet_NaN()
 Returns the representation of a quiet not a number (NAN)
 
static const int NAN_I = std::numeric_limits<int>::quiet_NaN()
 Returns the representation of a quiet not a number (NAN)
 

Macro Definition Documentation

◆ GZ_BOX_VOLUME

#define GZ_BOX_VOLUME (   _x,
  _y,
  _z 
)    (_x *_y * _z)

Compute box volume.

Parameters
[in]_xX length
[in]_yY length
[in]_zZ length

◆ GZ_BOX_VOLUME_V

#define GZ_BOX_VOLUME_V (   _v)    (_v.X() *_v.Y() * _v.Z())

Compute box volume from a vector.

Parameters
[in]_vVector3d that contains the box's dimensions.

◆ GZ_CONE_VOLUME

#define GZ_CONE_VOLUME (   _r,
  _l 
)    (_l * GZ_PI * std::pow(_r, 2) / 3.0)

Compute cone volume.

Parameters
[in]_rCone base radius
[in]_lCone length

◆ GZ_CYLINDER_VOLUME

#define GZ_CYLINDER_VOLUME (   _r,
  _l 
)    (_l * GZ_PI * std::pow(_r, 2))

Compute cylinder volume.

Parameters
[in]_rCylinder base radius
[in]_lCylinder length

◆ GZ_FP_VOLATILE

#define GZ_FP_VOLATILE

Define GZ_FP_VOLATILE for FP equality comparisons Use volatile parameters when checking floating point equality on the 387 math coprocessor to work around bugs from the 387 extra precision.

◆ GZ_PI

#define GZ_PI   3.14159265358979323846

Define GZ_PI, GZ_PI_2, and GZ_PI_4. This was put here for Windows support.

◆ GZ_PI_2

#define GZ_PI_2   1.57079632679489661923

◆ GZ_PI_4

#define GZ_PI_4   0.78539816339744830962

◆ GZ_SPHERE_VOLUME

#define GZ_SPHERE_VOLUME (   _radius)    (4.0*GZ_PI*std::pow(_radius, 3)/3.0)

Compute sphere volume.

Parameters
[in]_radiusSphere radius

◆ GZ_SQRT2

#define GZ_SQRT2   1.41421356237309504880

Variable Documentation

◆ GZ_MASSMATRIX3_DEFAULT_TOLERANCE

template<typename T >
constexpr T GZ_MASSMATRIX3_DEFAULT_TOLERANCE = T(10)
constexpr

The default tolerance value used by MassMatrix3::IsValid(), MassMatrix3::IsPositive(), and MassMatrix3::ValidMoments()