12#ifndef NUMBER_OPERATIONS_HPP
13#define NUMBER_OPERATIONS_HPP
81 inline constexpr T
Clamp(T tValue, T tMin, T tMax)
84 return std::max(std::min(tMax, tValue), tMin);
101 inline bool Bounded(T tValue, T tMin, T tMax,
const bool bInclusive =
true)
107 return (tValue >= tMin) && (tValue <= tMax);
112 return (tValue > tMin) && (tValue < tMax);
131 inline constexpr T
MapRange(
const T tValue,
const T tOldMinimum,
const T tOldMaximum,
const T tNewMinimum,
const T tNewMaximum)
134 if (tOldMinimum == tOldMaximum || tNewMinimum == tNewMaximum)
137 std::cerr <<
"MAPRANGE: The old/new range is not valid." << std::endl;
144 T tOldValueRange = tOldMaximum - tOldMinimum;
145 T tNewValueRange = tNewMaximum - tNewMinimum;
146 T tScaledValue = (tValue - tOldMinimum) / tOldValueRange;
149 return tNewMinimum + tScaledValue * tNewValueRange;
168 T tModulus = tMaxValue - tMinValue;
171 int nNumMax = (tValue - tMinValue) / tModulus;
172 tValue -= nNumMax * tModulus;
174 int nNumMin = (tValue - tMaxValue) / tModulus;
175 tValue -= nNumMin * tModulus;
178 if (tValue == tMaxValue)
207 if (!Bounded<T>(tFirstValue, 0, 360) && !Bounded<T>(tSecondValue, 0, 360))
210 std::cerr <<
"ANGULARDIFFERENCE: An input value is not valid must be between 0-360. The result difference will not be accurate!" << std::endl;
214 T tDifference = std::abs(tFirstValue - tSecondValue);
216 if (tDifference > 180)
222 if (tFirstValue > tSecondValue)
288 const double dXRotationDegrees,
289 const double dYRotationDegrees,
290 const double dZRotationDegrees)
293 double dXRotationRadians = (dXRotationDegrees * M_PI) / 180.0;
294 double dYRotationRadians = (dYRotationDegrees * M_PI) / 180.0;
295 double dZRotationRadians = (dZRotationDegrees * M_PI) / 180.0;
298 double dCosA =
cos(dXRotationRadians);
299 double dSinA =
sin(dXRotationRadians);
301 double dCosB =
cos(dYRotationRadians);
302 double dSinB =
sin(dYRotationRadians);
304 double dCosC =
cos(dZRotationRadians);
305 double dSinC =
sin(dZRotationRadians);
309 double dAXX = dCosC * dCosB;
310 double dAXY = dCosC * dSinB * dSinA - dSinC * dCosA;
311 double dAXZ = dCosC * dSinB * dCosA + dSinC * dSinA;
313 double dAYX = dSinC * dCosB;
314 double dAYY = dSinC * dSinB * dSinA + dCosC * dCosA;
315 double dAYZ = dSinC * dSinB * dCosA - dCosC * dSinA;
317 double dAZX = -dSinB;
318 double dAZY = dCosB * dSinA;
319 double dAZZ = dCosB * dCosA;
325 T tX =
static_cast<T
>((dAXX * stPoint.tX) + (dAXY * stPoint.tY) + (dAXZ * stPoint.tZ));
326 T tY =
static_cast<T
>((dAYX * stPoint.tX) + (dAYY * stPoint.tY) + (dAYZ * stPoint.tZ));
327 T tZ =
static_cast<T
>((dAZX * stPoint.tX) + (dAZY * stPoint.tY) + (dAZZ * stPoint.tZ));
__device__ __forceinline__ float1 cos(const uchar1 &a)
__device__ __forceinline__ float4 sin(const uchar4 &a)
Namespace containing functions related to operations on numbers and other datatypes.
Definition NumberOperations.hpp:31
constexpr T Clamp(T tValue, T tMin, T tMax)
Clamps a given value from going above or below a given threshold.
Definition NumberOperations.hpp:81
constexpr T InputAngleModulus(T tValue, T tMinValue, T tMaxValue)
Calculates the modulus of an input angle.
Definition NumberOperations.hpp:165
constexpr void CoordinateFrameRotate3D(std::vector< CoordinatePoint< T > > &vPointCloud, const double dXRotationDegrees, const double dYRotationDegrees, const double dZRotationDegrees)
This method will rotate a list of 3D coordinate points a variable amount of degrees around the X,...
Definition NumberOperations.hpp:287
constexpr T AngularDifference(T tFirstValue, T tSecondValue)
Calculates the distance in degrees between two angles. This function accounts for wrap around so that...
Definition NumberOperations.hpp:204
constexpr T MapRange(const T tValue, const T tOldMinimum, const T tOldMaximum, const T tNewMinimum, const T tNewMaximum)
Maps a value to a new range given the old range.
Definition NumberOperations.hpp:131
bool Bounded(T tValue, T tMin, T tMax, const bool bInclusive=true)
Checks if a given value is between the given maximum and minimum ranges.
Definition NumberOperations.hpp:101
This struct represents a point in a 3D coordinate system.
Definition NumberOperations.hpp:42
CoordinatePoint(const T tX=0.0, const T tY=0.0, const T tZ=0.0)
Construct a new Coordinate Point object.
Definition NumberOperations.hpp:59