FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
interp::InterpSetData Class Reference

Class for managing a set of data and performing interpolation. More...

#include "interpolation_set.h"

Public Member Functions

template<RealConcept T>
void insertSample (T x, T y) noexcept
 Inserts a sample point into the interpolation set.
 
template<RealConcept T>
std::optional< T > value (T x) const noexcept
 Retrieves the interpolated value at a given point.
 
double max () const noexcept
 Retrieves the maximum absolute value in the interpolation set.
 
template<RealConcept T>
void divide (T a)
 Divides all y-values in the dataset by a given number.
 

Detailed Description

Class for managing a set of data and performing interpolation.

Definition at line 30 of file interpolation_set.h.

Member Function Documentation

◆ divide()

template<RealConcept T>
template void interp::InterpSetData::divide< float > ( a)

Divides all y-values in the dataset by a given number.

Template Parameters
TThe type of the divisor (must be an arithmetic type).
Parameters
aThe divisor to divide all y-values by.
Exceptions
std::invalid_argumentThrown if the divisor is zero.

Definition at line 75 of file interpolation_set.cpp.

76 {
77 if (a == 0)
78 {
79 throw std::invalid_argument("Division by zero is not allowed.");
80 }
81
82 std::ranges::for_each(_data | std::views::values, [a](auto& value) { value /= static_cast<double>(a); });
83 }
std::optional< T > value(T x) const noexcept
Retrieves the interpolated value at a given point.

References value().

+ Here is the call graph for this function:

◆ insertSample()

template<RealConcept T>
void interp::InterpSetData::insertSample ( x,
y 
)
noexcept

Inserts a sample point into the interpolation set.

Template Parameters
TThe type of the x and y coordinates (must be an arithmetic type).
Parameters
xThe x-coordinate of the sample point.
yThe y-coordinate of the sample point.

Definition at line 41 of file interpolation_set.h.

42 {
43 _data.insert({x, y});
44 }

◆ max()

double interp::InterpSetData::max ( ) const
noexcept

Retrieves the maximum absolute value in the interpolation set.

Returns
The maximum absolute y-value in the dataset, or 0.0 if the set is empty.

Definition at line 64 of file interpolation_set.cpp.

65 {
66 auto values = _data | std::views::values;
67
68 const auto max_element =
69 std::ranges::max_element(values, [](const double a, const double b) { return std::abs(a) < std::abs(b); });
70
71 return max_element != values.end() ? std::abs(*max_element) : 0.0;
72 }

◆ value()

template<RealConcept T>
template std::optional< float > interp::InterpSetData::value< float > ( x) const
noexcept

Retrieves the interpolated value at a given point.

Template Parameters
TThe type of the x-coordinate (must be an arithmetic type).
Parameters
xThe x-coordinate at which to interpolate the value.
Returns
The interpolated value at the given x-coordinate, or std::nullopt if the dataset is empty.

Definition at line 25 of file interpolation_set.cpp.

26 {
27 if (_data.empty())
28 {
29 return std::nullopt;
30 }
31
32 // TODO: RealConcept is broader than the implementation really supports?
33 // std::is_arithmetic_v<T> admits integral types
34 // That may be intended, but for value(T x) it means interpolation with
35 // integer queries returns std::optional<int>, and the final interpolated
36 // double gets truncated by:
37 // return static_cast<T>(...)
38 // If the class is conceptually for real-valued interpolation,
39 // std::floating_point<T> would be a better constraint
40 const RealType x_value = static_cast<RealType>(x);
41 const auto iter = _data.lower_bound(x_value);
42
43 if (iter == _data.begin())
44 {
45 return static_cast<T>(iter->second);
46 }
47 if (iter == _data.end())
48 {
49 const auto prev = std::prev(iter);
50 return static_cast<T>(prev->second);
51 }
52 if (iter->first == x_value)
53 {
54 return static_cast<T>(iter->second);
55 }
56
57 auto prev = std::prev(iter);
58 const auto [x1, y1] = *prev;
59 const auto [x2, y2] = *iter;
60
61 return static_cast<T>(y2 * (x_value - x1) / (x2 - x1) + y1 * (x2 - x_value) / (x2 - x1));
62 }
double RealType
Type for real numbers.
Definition config.h:27

Referenced by divide().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: