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 66 of file interpolation_set.cpp.

67 {
68 if (a == 0)
69 {
70 throw std::invalid_argument("Division by zero is not allowed.");
71 }
72
73 std::ranges::for_each(_data | std::views::values, [a](auto& value) { value /= static_cast<double>(a); });
74 }
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 55 of file interpolation_set.cpp.

56 {
57 auto values = _data | std::views::values;
58
59 const auto max_element =
60 std::ranges::max_element(values, [](const double a, const double b) { return std::abs(a) < std::abs(b); });
61
62 return max_element != values.end() ? std::abs(*max_element) : 0.0;
63 }

◆ 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 const auto iter = _data.lower_bound(static_cast<double>(x));
33
34 if (iter == _data.begin())
35 {
36 return static_cast<T>(iter->second);
37 }
38 if (iter == _data.end())
39 {
40 const auto prev = std::prev(iter);
41 return static_cast<T>(prev->second);
42 }
43 if (iter->first == static_cast<double>(x))
44 {
45 return static_cast<T>(iter->second);
46 }
47
48 auto prev = std::prev(iter);
49 const auto [x1, y1] = *prev;
50 const auto [x2, y2] = *iter;
51
52 return static_cast<T>(y2 * (x - x1) / (x2 - x1) + y1 * (x2 - x) / (x2 - x1));
53 }

Referenced by divide().

+ Here is the caller graph for this function:

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