pcod-common v1.0.0
Shared preprocessing and postprocessing for point-cloud object detection
Loading...
Searching...
No Matches
math.hpp
Go to the documentation of this file.
1// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include <cmath>
7
8namespace pcod_common {
9
11template <typename T>
12constexpr const inline T& clamp(const T& value, const T& low, const T& high) {
13 return (value < low) ? low : (high < value) ? high : value;
14}
15
22template <typename T>
23T scale_score(T score, T old_thresh, T new_thresh) {
24 const T one = static_cast<T>(1);
25 if (score <= old_thresh) {
26 return score * new_thresh / old_thresh;
27 }
28 return one - (one - score) * (one - new_thresh) / (one - old_thresh);
29}
30
32inline float wrap_to_range(float val, float min_val, float max_val) {
33 float range = max_val - min_val;
34 return val - range * std::floor((val - min_val) / range);
35}
36
37} // namespace pcod_common
constexpr const T & clamp(const T &value, const T &low, const T &high)
Definition math.hpp:12
T scale_score(T score, T old_thresh, T new_thresh)
Definition math.hpp:23
float wrap_to_range(float val, float min_val, float max_val)
Definition math.hpp:32