FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
interpolation_set.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2007-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file interpolation_set.h
10 * @brief Header file for the interpolation of sets of data.
11 */
12
13#pragma once
14
15#include <map>
16#include <memory>
17#include <optional>
18
19#include "core/config.h"
20
21namespace interp
22{
23 /// Concept constraining interpolation inputs to arithmetic values.
24 template <typename T>
25 concept RealConcept = std::is_arithmetic_v<T>;
26
27 /**
28 * @class InterpSetData
29 * @brief Class for managing a set of data and performing interpolation.
30 */
32 {
33 public:
34 /**
35 * @brief Inserts a sample point into the interpolation set.
36 *
37 * @tparam T The type of the x and y coordinates (must be an arithmetic type).
38 * @param x The x-coordinate of the sample point.
39 * @param y The y-coordinate of the sample point.
40 */
41 template <RealConcept T>
42 void insertSample(T x, T y) noexcept
43 {
44 _data.insert({x, y});
45 }
46
47 /**
48 * @brief Retrieves the interpolated value at a given point.
49 *
50 * @tparam T The type of the x-coordinate (must be an arithmetic type).
51 * @param x The x-coordinate at which to interpolate the value.
52 * @return The interpolated value at the given x-coordinate, or std::nullopt if the dataset is empty.
53 */
54 template <RealConcept T>
55 [[nodiscard]] std::optional<T> value(T x) const noexcept;
56
57 /**
58 * @brief Retrieves the maximum absolute value in the interpolation set.
59 *
60 * @return The maximum absolute y-value in the dataset, or 0.0 if the set is empty.
61 */
62 [[nodiscard]] double max() const noexcept;
63
64 /**
65 * @brief Divides all y-values in the dataset by a given number.
66 *
67 * @tparam T The type of the divisor (must be an arithmetic type).
68 * @param a The divisor to divide all y-values by.
69 * @throws std::invalid_argument Thrown if the divisor is zero.
70 */
72 void divide(T a);
73
74 private:
75 std::map<RealType, RealType> _data; ///< The set of data points
76 };
77
78 /**
79 * @class InterpSet
80 * @brief Wrapper class for managing interpolation sets using smart pointers.
81 */
83 {
84 public:
85 /**
86 * @brief Constructs a new InterpSet object.
87 */
88 constexpr InterpSet() : _data(std::make_unique<InterpSetData>()) {}
89
90 constexpr ~InterpSet() = default;
91
92 InterpSet(const InterpSet&) = delete;
93 InterpSet& operator=(const InterpSet&) = delete;
94 InterpSet(InterpSet&&) = delete;
96
97 /**
98 * @brief Inserts a sample point into the interpolation set.
99 *
100 * @tparam T The type of the x and y coordinates (must be an arithmetic type).
101 * @param x The x-coordinate of the sample point.
102 * @param y The y-coordinate of the sample point.
103 */
104 template <RealConcept T>
105 void insertSample(T x, T y) const noexcept
106 {
107 _data->insertSample(x, y);
108 }
109
110 /**
111 * @brief Retrieves the interpolated value at a given point.
112 *
113 * @tparam T The type of the x-coordinate (must be an arithmetic type).
114 * @param x The x-coordinate at which to interpolate the value.
115 * @return The interpolated value at the given x-coordinate, or std::nullopt if the dataset is empty.
116 */
117 template <RealConcept T>
118 [[nodiscard]] std::optional<T> getValueAt(T x) const noexcept
119 {
120 return _data->value(x);
121 }
122
123 /**
124 * @brief Retrieves the maximum absolute value in the interpolation set.
125 *
126 * @return The maximum absolute y-value in the dataset, or 0.0 if the set is empty.
127 */
128 [[nodiscard]] double getMax() const noexcept { return _data->max(); }
129
130 /**
131 * @brief Divides all y-values in the dataset by a given number.
132 *
133 * @tparam T The type of the divisor (must be an arithmetic type).
134 * @param a The divisor to divide all y-values by.
135 * @throws std::invalid_argument Thrown if the divisor is zero.
136 */
137 template <RealConcept T>
138 void divide(T a) const
139 {
140 _data->divide(a);
141 }
142
143 private:
144 std::unique_ptr<InterpSetData> _data; ///< The internal InterpSetData object
145 };
146}
Class for managing a set of data and performing interpolation.
double max() const noexcept
Retrieves the maximum absolute value in the interpolation set.
void divide(T a)
Divides all y-values in the dataset by a given number.
void insertSample(T x, T y) noexcept
Inserts a sample point into the interpolation set.
std::optional< T > value(T x) const noexcept
Retrieves the interpolated value at a given point.
Wrapper class for managing interpolation sets using smart pointers.
constexpr InterpSet()
Constructs a new InterpSet object.
void divide(T a) const
Divides all y-values in the dataset by a given number.
constexpr ~InterpSet()=default
std::optional< T > getValueAt(T x) const noexcept
Retrieves the interpolated value at a given point.
double getMax() const noexcept
Retrieves the maximum absolute value in the interpolation set.
InterpSet & operator=(const InterpSet &)=delete
InterpSet(const InterpSet &)=delete
InterpSet & operator=(InterpSet &&)=delete
void insertSample(T x, T y) const noexcept
Inserts a sample point into the interpolation set.
InterpSet(InterpSet &&)=delete
Concept constraining interpolation inputs to arithmetic values.
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
RealType a