FERS 1.0.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 template <typename T>
24 concept RealConcept = std::is_arithmetic_v<T>;
25
26 /**
27 * @class InterpSetData
28 * @brief Class for managing a set of data and performing interpolation.
29 */
31 {
32 public:
33 /**
34 * @brief Inserts a sample point into the interpolation set.
35 *
36 * @tparam T The type of the x and y coordinates (must be an arithmetic type).
37 * @param x The x-coordinate of the sample point.
38 * @param y The y-coordinate of the sample point.
39 */
40 template <RealConcept T>
41 void insertSample(T x, T y) noexcept
42 {
43 _data.insert({x, y});
44 }
45
46 /**
47 * @brief Retrieves the interpolated value at a given point.
48 *
49 * @tparam T The type of the x-coordinate (must be an arithmetic type).
50 * @param x The x-coordinate at which to interpolate the value.
51 * @return The interpolated value at the given x-coordinate, or std::nullopt if the dataset is empty.
52 */
53 template <RealConcept T>
54 [[nodiscard]] std::optional<T> value(T x) const noexcept;
55
56 /**
57 * @brief Retrieves the maximum absolute value in the interpolation set.
58 *
59 * @return The maximum absolute y-value in the dataset, or 0.0 if the set is empty.
60 */
61 [[nodiscard]] double max() const noexcept;
62
63 /**
64 * @brief Divides all y-values in the dataset by a given number.
65 *
66 * @tparam T The type of the divisor (must be an arithmetic type).
67 * @param a The divisor to divide all y-values by.
68 * @throws std::invalid_argument Thrown if the divisor is zero.
69 */
70 template <RealConcept T>
71 void divide(T a);
72
73 private:
74 std::map<RealType, RealType> _data; ///< The set of data points
75 };
76
77 /**
78 * @class InterpSet
79 * @brief Wrapper class for managing interpolation sets using smart pointers.
80 */
82 {
83 public:
84 /**
85 * @brief Constructs a new InterpSet object.
86 */
87 constexpr InterpSet() : _data(std::make_unique<InterpSetData>()) {}
88
89 constexpr ~InterpSet() = default;
90
91 InterpSet(const InterpSet&) = delete;
92 InterpSet& operator=(const InterpSet&) = delete;
93 InterpSet(InterpSet&&) = delete;
95
96 /**
97 * @brief Inserts a sample point into the interpolation set.
98 *
99 * @tparam T The type of the x and y coordinates (must be an arithmetic type).
100 * @param x The x-coordinate of the sample point.
101 * @param y The y-coordinate of the sample point.
102 */
103 template <RealConcept T>
104 void insertSample(T x, T y) const noexcept
105 {
106 _data->insertSample(x, y);
107 }
108
109 /**
110 * @brief Retrieves the interpolated value at a given point.
111 *
112 * @tparam T The type of the x-coordinate (must be an arithmetic type).
113 * @param x The x-coordinate at which to interpolate the value.
114 * @return The interpolated value at the given x-coordinate, or std::nullopt if the dataset is empty.
115 */
116 template <RealConcept T>
117 [[nodiscard]] std::optional<T> getValueAt(T x) const noexcept
118 {
119 return _data->value(x);
120 }
121
122 /**
123 * @brief Retrieves the maximum absolute value in the interpolation set.
124 *
125 * @return The maximum absolute y-value in the dataset, or 0.0 if the set is empty.
126 */
127 [[nodiscard]] double getMax() const noexcept { return _data->max(); }
128
129 /**
130 * @brief Divides all y-values in the dataset by a given number.
131 *
132 * @tparam T The type of the divisor (must be an arithmetic type).
133 * @param a The divisor to divide all y-values by.
134 * @throws std::invalid_argument Thrown if the divisor is zero.
135 */
136 template <RealConcept T>
137 void divide(T a) const
138 {
139 _data->divide(a);
140 }
141
142 private:
143 std::unique_ptr<InterpSetData> _data; ///< The internal InterpSetData object
144 };
145}
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
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27