13 template <
typename TValue,
typename TScalar = Float>
16 template <
typename TValue,
typename TScalar = Float>
46 return x == other.
x &&
y == other.
y;
55 return iter != other.iter;
60 template <
typename TValue,
typename TScalar>
70 : data(
std::move(data))
73 template <
typename TFunction>
77 for (
Size i = 0; i < resolution; ++i) {
84 const TScalar fidx = TScalar((x - range.
lower()) / range.
size() * (data.
size() - 1));
85 const int idx1 = int(
floor(fidx));
86 const int idx2 = idx1 + 1;
87 if (idx2 >=
int(data.
size() - 1)) {
90 }
else if (idx1 <= 0) {
93 const TScalar ratio = fidx - idx1;
94 SPH_ASSERT(ratio >= TScalar(0) && ratio < TScalar(1));
95 return lerp(data[idx1], data[idx2], ratio);
123 for (
Size i = 0; i < data.
size() - 1; ++i) {
124 deriv[i] = (data[i + 1] - data[i]) / dx;
126 deriv[data.
size() - 1] = deriv[data.
size() - 2];
127 return Lut(range, std::move(deriv));
138 for (
Size i = 1; i < data.
size(); ++i) {
139 integ[i] = integ[i - 1] + data[i] * dx;
141 const Lut lut(range, std::move(integ));
142 return lut + (y0 - lut(x0));
150 template <
typename TValue,
typename TScalar,
typename TBinaryOp>
153 const TBinaryOp& op) {
160 auto func = [&lut1, &lut2, &op](
const Float x) {
return op(lut1(x), lut2(x)); };
165 template <
typename TValue,
typename TScalar,
typename TBinaryOp>
167 const TScalar& value,
168 const TBinaryOp& op) {
169 auto func = [&lut, &value, &op](
const Float x) {
return op(lut(x), value); };
173 template <
typename TValue,
typename TScalar>
178 template <
typename TValue,
typename TScalar>
183 template <
typename TValue,
typename TScalar>
188 template <
typename TValue,
typename TScalar>
193 template <
typename TValue,
typename TScalar>
198 template <
typename TValue,
typename TScalar>
203 template <
typename TValue,
typename TScalar>
208 template <
typename TValue,
typename TScalar>
Generic dynamically allocated resizable storage.
#define SPH_ASSERT(x,...)
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Object representing interval of real values.
Lut< TValue, TScalar > operator-(const Lut< TValue, TScalar > &lut1, const Lut< TValue, TScalar > &lut2)
Lut< TValue, TScalar > operator+(const Lut< TValue, TScalar > &lut1, const Lut< TValue, TScalar > &lut2)
Lut< TValue, TScalar > operator/(const Lut< TValue, TScalar > &lut1, const Lut< TValue, TScalar > &lut2)
Lut< TValue, TScalar > lutOperation(const Lut< TValue, TScalar > &lut1, const Lut< TValue, TScalar > &lut2, const TBinaryOp &op)
Returns a LUT given by a generic binary operator.
Lut< TValue, TScalar > operator*(const Lut< TValue, TScalar > &lut1, const Lut< TValue, TScalar > &lut2)
NAMESPACE_SPH_BEGIN constexpr INLINE T min(const T &f1, const T &f2)
Minimum & Maximum value.
INLINE T lerp(const T v1, const T v2, const TAmount amount)
INLINE auto floor(const T &f)
INLINE auto round(const T &f)
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
INLINE Iterator< StorageType > end() noexcept
INLINE T & back() noexcept
INLINE TCounter size() const noexcept
INLINE T & front() noexcept
INLINE Iterator< StorageType > begin() noexcept
Helper class used to allow calling a function only from within T.
Object representing a 1D interval of real numbers.
INLINE Float lower() const
Returns lower bound of the interval.
INLINE Float size() const
Returns the size of the interval.
INLINE bool contains(const Float &value) const
Checks whether value is inside the interval.
INLINE Interval intersect(const Interval &other) const
Computes the intersection with another interval.
bool operator!=(const LutIterator &other) const
LutIterator & operator++()
LutIterator(Iterator< const TValue > iter, const Size index, const Size size, const Interval &range, Badge< Lut< TValue, TScalar >>)
Callable representing a generic R->T function, approximated using look-up table.
LutIterator< TValue, TScalar > begin() const
Returns an iterator accessing tabulated values.
Lut(const Interval range, Array< TValue > &&data)
LutIterator< TValue, TScalar > end() const
Returns an iterator accessing tabulated values.
Lut(const Interval range, const Size resolution, TFunction &&func)
Lut derivative() const
Computes the derivative of the function.
INLINE TValue operator()(const TScalar x) const
Interval getRange() const
Returns the definition interval of the function.
Size size() const
Returns the number of tabulated value.
Lut integral(const Float x0, const Float y0) const
Computes the indefinite integral of the function.
Overload of std::swap for Sph::Array.
bool operator==(const Value &other) const
Object with deleted copy constructor and copy operator.