noise: convert eval method to function operator
This commit is contained in:
parent
9b0abd8f7a
commit
b082fd6a44
@ -49,7 +49,7 @@ util::noise::image2d (uint8_t *restrict pixels,
|
||||
const util::noise::fractal<float> &p) {
|
||||
for (size_t y = 0; y < height; ++y)
|
||||
for (size_t x = 0; x < width; ++x) {
|
||||
double v = p.eval (x, y);
|
||||
double v = p (x, y);
|
||||
pixels[x + y * width] = static_cast<uint8_t> (v * std::numeric_limits<uint8_t>::max ());
|
||||
}
|
||||
}
|
||||
|
@ -93,8 +93,10 @@ basis<T>::~basis ()
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T
|
||||
basis<T>::eval (T, T) const
|
||||
{ unreachable (); }
|
||||
basis<T>::operator() (T, T) const
|
||||
{
|
||||
unreachable ();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -121,13 +123,16 @@ value<T,L>::value ()
|
||||
template <typename T, util::noise::lerp_t<T> L>
|
||||
util::range<T>
|
||||
value<T,L>::bounds (void) const
|
||||
{ return { -1, 1 }; }
|
||||
{
|
||||
return { -1, 1 };
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T, util::noise::lerp_t<T> L>
|
||||
T
|
||||
value<T,L>::eval (T x, T y) const {
|
||||
value<T,L>::operator() (T x, T y) const
|
||||
{
|
||||
intmax_t x_int = static_cast<intmax_t> (x);
|
||||
intmax_t y_int = static_cast<intmax_t> (y);
|
||||
T x_fac = x - x_int;
|
||||
@ -187,7 +192,8 @@ gradient<T,L>::bounds (void) const
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T, util::noise::lerp_t<T> L>
|
||||
T
|
||||
gradient<T,L>::eval (T x, T y) const {
|
||||
gradient<T,L>::operator() (T x, T y) const
|
||||
{
|
||||
intmax_t x_int = static_cast<intmax_t> (x);
|
||||
intmax_t y_int = static_cast<intmax_t> (y);
|
||||
T x_fac = x - x_int;
|
||||
@ -255,7 +261,8 @@ cellular<T>::bounds (void) const
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T
|
||||
cellular<T>::eval (T x, T y) const {
|
||||
cellular<T>::operator() (T x, T y) const
|
||||
{
|
||||
intmax_t x_int = static_cast<intmax_t> (x);
|
||||
intmax_t y_int = static_cast<intmax_t> (y);
|
||||
T x_fac = x - x_int;
|
||||
|
@ -36,7 +36,7 @@ namespace util {
|
||||
seed_t seed;
|
||||
|
||||
virtual range<T> bounds (void) const = 0;
|
||||
virtual T eval (T x, T y) const = 0;
|
||||
virtual T operator() (T x, T y) const = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ namespace util {
|
||||
value ();
|
||||
|
||||
virtual range<T> bounds (void) const override;
|
||||
virtual T eval (T x, T y) const override;
|
||||
virtual T operator() (T x, T y) const override;
|
||||
};
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ namespace util {
|
||||
gradient ();
|
||||
|
||||
virtual range<T> bounds (void) const override;
|
||||
virtual T eval (T x, T y) const override;
|
||||
virtual T operator() (T x, T y) const override;
|
||||
};
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ namespace util {
|
||||
cellular ();
|
||||
|
||||
virtual range<T> bounds (void) const override;
|
||||
virtual T eval (T x, T y) const override;
|
||||
virtual T operator() (T x, T y) const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -55,8 +55,10 @@ fractal<T>::~fractal ()
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T
|
||||
fractal<T>::eval (T, T) const
|
||||
{ unreachable (); }
|
||||
fractal<T>::operator() (T, T) const
|
||||
{
|
||||
unreachable ();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -86,14 +88,14 @@ fbm<T,B>::fbm ()
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T, typename B>
|
||||
T
|
||||
fbm<T,B>::eval (T x, T y) const {
|
||||
fbm<T,B>::operator() (T x, T y) const {
|
||||
T total = 0;
|
||||
T f = this->frequency;
|
||||
T a = 1;
|
||||
T a_sum = 0;
|
||||
|
||||
for (size_t i = 0; i < this->octaves; ++i) {
|
||||
total += basis.eval (x * f, y * f) * a;
|
||||
total += basis (x * f, y * f) * a;
|
||||
|
||||
f *= 2;
|
||||
|
||||
@ -139,7 +141,7 @@ musgrave<T,B>::musgrave ()
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T, typename B>
|
||||
T
|
||||
musgrave<T,B>::eval (T x, T y) const {
|
||||
musgrave<T,B>::operator() (T x, T y) const {
|
||||
T total = 0;
|
||||
T f = this->frequency;
|
||||
T a = 1;
|
||||
@ -150,7 +152,7 @@ musgrave<T,B>::eval (T x, T y) const {
|
||||
|
||||
T signal;
|
||||
|
||||
signal = basis.eval (x * f, y * f);
|
||||
signal = basis (x * f, y * f);
|
||||
signal = std::fabs (signal);
|
||||
signal = offset - signal;
|
||||
signal *= signal;
|
||||
@ -163,7 +165,7 @@ musgrave<T,B>::eval (T x, T y) const {
|
||||
weight = signal * gain;
|
||||
weight = limit (weight, 0, 1);
|
||||
|
||||
signal = basis.eval (x * f, y * f);
|
||||
signal = basis (x * f, y * f);
|
||||
signal = std::fabs (signal);
|
||||
signal = offset - signal;
|
||||
signal *= signal;
|
||||
|
@ -34,8 +34,7 @@ namespace util {
|
||||
T frequency;
|
||||
T lacunarity;
|
||||
|
||||
T operator() (T x, T y) const { return eval (x, y); };
|
||||
virtual T eval (T x, T y) const = 0;
|
||||
virtual T operator() (T x, T y) const = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -51,7 +50,7 @@ namespace util {
|
||||
fbm ();
|
||||
|
||||
B basis;
|
||||
virtual T eval (T x, T y) const;
|
||||
virtual T operator() (T x, T y) const override;
|
||||
};
|
||||
|
||||
|
||||
@ -67,7 +66,7 @@ namespace util {
|
||||
musgrave ();
|
||||
|
||||
B basis;
|
||||
virtual T eval (T x, T y) const;
|
||||
virtual T operator() (T x, T y) const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user