DHART
Loading...
Searching...
No Matches
Constants.h
Go to the documentation of this file.
1
7
8#pragma once
9#include <cmath>
10
11namespace HF {
12
21 namespace SpatialStructures {
22
30 constexpr float ROUNDING_PRECISION = 0.0001f; // Used to convert back to original value
31 constexpr float FLOAT_PRECISION = 10000.0f;
32 constexpr float GROUND_OFFSET = 0.001f;
43 template<typename desired_type, typename numeric_type>
44 inline constexpr desired_type DivideBy1(numeric_type n) {
45 return static_cast<desired_type>(1) / static_cast<desired_type>(n);
46 }
47
55
65 float roundhf(float f, float p = FLOAT_PRECISION, float r = ROUNDING_PRECISION);
66
74 float trunchf(float f, float p = 1000.0, float r = 0.001);
75
88 template <typename numeric_type>
89 numeric_type roundhf_tail(numeric_type f, int precision)
90 {
91 numeric_type r = 0; // final rounded value
92 int precision_2 = precision * 10; // the precision one more than the one we are interested in
93 r = std::round(f * precision_2);
94 r = std::round(r * 0.1); // Move decimal one over and round again
95 r = r / precision;
96
97 return r;
98 }
99
113 template <typename numeric_type>
114 inline constexpr numeric_type roundhf_tmp(
115 numeric_type f,
116 numeric_type p,
117 numeric_type r
118 ) { return std::round(f * p) * r; }
119
132 template <typename desired_type, typename numeric_type>
133 inline constexpr desired_type roundhf_tmp(numeric_type f, numeric_type p) {
134 return roundhf_tmp(static_cast<desired_type>(f), DivideBy1<desired_type>(p), static_cast<desired_type>(p));
135 }
136 template <typename desired_type, typename numeric_type>
148 inline constexpr desired_type roundhf_tmp(numeric_type f) {
149 return roundhf_tmp(
150 static_cast<desired_type>(f),
151 DivideBy1<desired_type>(ROUNDING_PRECISION),
152 static_cast<desired_type>(ROUNDING_PRECISION)
153 );
154 }
155
169 template <typename numeric_type>
170 inline constexpr numeric_type trunchf_tmp(
171 numeric_type f,
172 numeric_type p,
173 numeric_type r
174 ) { return std::trunc(f * p) * r; }
175
188 template <typename desired_type, typename numeric_type>
189 inline constexpr desired_type trunchf_tmp(numeric_type f, numeric_type p) {
190 return trunchf_tmp(static_cast<desired_type>(f), DivideBy1<desired_type>(p), static_cast<desired_type>(p));
191 }
203 template <typename desired_type, typename numeric_type>
204 inline constexpr desired_type trunchf_tmp(numeric_type f) {
205 return trunchf_tmp(
206 static_cast<desired_type>(f),
207 DivideBy1<desired_type>(ROUNDING_PRECISION),
208 static_cast<desired_type>(ROUNDING_PRECISION)
209 );
210 }
211
212
213
214 }
215}
Perform human scale analysis on 3D environments.
constexpr float ROUNDING_PRECISION
Minimum value that can be represented in DHART_API.
Definition: Constants.h:30
constexpr desired_type DivideBy1(numeric_type n)
Cast a value to the specific type and divide 1 by it.
Definition: Constants.h:44
numeric_type roundhf_tail(numeric_type f, int precision)
round a number twice, once at the precision+1, and again at the precision This method is to fix cases...
Definition: Constants.h:89
constexpr numeric_type roundhf_tmp(numeric_type f, numeric_type p, numeric_type r)
round a number to the nearest precision defined globally. The global values can be overridden with op...
Definition: Constants.h:114
float roundhf(float f, float p=FLOAT_PRECISION, float r=ROUNDING_PRECISION)
Round a float to the nearest precision defined globally. The global values can be overridden with opt...
Definition: Constants.cpp:14
float trunchf(float f, float p=1000.0, float r=0.001)
Truncate a float to the nearest precision defined globally. The global values can be overridden with ...
Definition: Constants.cpp:20
constexpr float GROUND_OFFSET
Offset to be used for offsetting from a polygon when performing checks.
Definition: Constants.h:32
constexpr float FLOAT_PRECISION
Used to convert to a given precision (avoids division)
Definition: Constants.h:31
constexpr numeric_type trunchf_tmp(numeric_type f, numeric_type p, numeric_type r)
truncate a number to the nearest precision defined globally. The global values can be overridden with...
Definition: Constants.h:170