noise: annotate generators with noexcept
This commit is contained in:
parent
f0f1522307
commit
e769b8f74a
|
@ -46,7 +46,7 @@ namespace util { namespace noise { namespace basis {
|
||||||
|
|
||||||
range<T> bounds (void) const;
|
range<T> bounds (void) const;
|
||||||
|
|
||||||
T operator() (point_t) const;
|
T operator() (point_t) const noexcept;
|
||||||
};
|
};
|
||||||
} } }
|
} } }
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace util { namespace noise { namespace basis {
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
template <size_t S, typename T, template <typename> class L, template <size_t,typename> class G>
|
template <size_t S, typename T, template <typename> class L, template <size_t,typename> class G>
|
||||||
T
|
T
|
||||||
perlin<S,T,L,G>::operator() (point_t p) const
|
perlin<S,T,L,G>::operator() (point_t p) const noexcept
|
||||||
{
|
{
|
||||||
// extract integer and fractional parts. be careful to always round down
|
// extract integer and fractional parts. be careful to always round down
|
||||||
auto p_int = floor (p).template cast<intmax_t> ();
|
auto p_int = floor (p).template cast<intmax_t> ();
|
||||||
|
|
|
@ -37,7 +37,7 @@ namespace util { namespace noise { namespace basis {
|
||||||
runtime& operator= (const runtime&) = delete;
|
runtime& operator= (const runtime&) = delete;
|
||||||
|
|
||||||
// basis functions
|
// basis functions
|
||||||
T operator () (util::point<S,T> p) const { return (*m_child) (p); }
|
T operator () (util::point<S,T> p) const noexcept { return (*m_child) (p); }
|
||||||
range<T> bounds (void) const { return m_child->bounds (); }
|
range<T> bounds (void) const { return m_child->bounds (); }
|
||||||
|
|
||||||
seed_t seed (void) const { return m_child->seed (); }
|
seed_t seed (void) const { return m_child->seed (); }
|
||||||
|
@ -46,7 +46,7 @@ namespace util { namespace noise { namespace basis {
|
||||||
private:
|
private:
|
||||||
struct base {
|
struct base {
|
||||||
virtual ~base () = default;
|
virtual ~base () = default;
|
||||||
virtual T operator() (util::point<S,T>) const = 0;
|
virtual T operator() (util::point<S,T>) const noexcept = 0;
|
||||||
virtual range<T> bounds (void) const = 0;
|
virtual range<T> bounds (void) const = 0;
|
||||||
virtual seed_t seed (void) const = 0;
|
virtual seed_t seed (void) const = 0;
|
||||||
virtual seed_t seed (seed_t) = 0;
|
virtual seed_t seed (seed_t) = 0;
|
||||||
|
@ -56,7 +56,7 @@ namespace util { namespace noise { namespace basis {
|
||||||
struct child : public base {
|
struct child : public base {
|
||||||
template <typename ...Args>
|
template <typename ...Args>
|
||||||
child (seed_t _seed, Args&& ...args): data (_seed, std::forward<Args> (args)...) { }
|
child (seed_t _seed, Args&& ...args): data (_seed, std::forward<Args> (args)...) { }
|
||||||
virtual T operator() (util::point<S,T> p) const override { return data (p); }
|
virtual T operator() (util::point<S,T> p) const noexcept override { return data (p); }
|
||||||
virtual range<T> bounds (void) const override { return data.bounds (); }
|
virtual range<T> bounds (void) const override { return data.bounds (); }
|
||||||
virtual seed_t seed (void) const override { return data.seed (); }
|
virtual seed_t seed (void) const override { return data.seed (); }
|
||||||
virtual seed_t seed (seed_t _seed) override { return data.seed (_seed); }
|
virtual seed_t seed (seed_t _seed) override { return data.seed (_seed); }
|
||||||
|
|
|
@ -54,7 +54,7 @@ namespace util { namespace noise { namespace fractal {
|
||||||
value_t gain);
|
value_t gain);
|
||||||
fbm (seed_t);
|
fbm (seed_t);
|
||||||
|
|
||||||
value_t operator() (point_t) const;
|
value_t operator() (point_t) const noexcept;
|
||||||
};
|
};
|
||||||
} } }
|
} } }
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace util { namespace noise { namespace fractal {
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
template <class B>
|
template <class B>
|
||||||
typename fbm<B>::value_t
|
typename fbm<B>::value_t
|
||||||
fbm<B>::operator() (point_t p) const
|
fbm<B>::operator() (point_t p) const noexcept
|
||||||
{
|
{
|
||||||
value_t total = 0;
|
value_t total = 0;
|
||||||
value_t scale = this->m_invAH;
|
value_t scale = this->m_invAH;
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace util { namespace noise { namespace fractal {
|
||||||
runtime& operator= (const runtime&) = delete;
|
runtime& operator= (const runtime&) = delete;
|
||||||
|
|
||||||
// basis functions
|
// basis functions
|
||||||
value_t operator () (point_t p) const { return (*m_child) (p); }
|
value_t operator () (point_t p) const noexcept { return (*m_child) (p); }
|
||||||
|
|
||||||
unsigned octaves (void) const { return m_child->octaves (); }
|
unsigned octaves (void) const { return m_child->octaves (); }
|
||||||
unsigned octaves (unsigned _octaves) { return m_child->octaves (_octaves); }
|
unsigned octaves (unsigned _octaves) { return m_child->octaves (_octaves); }
|
||||||
|
@ -66,7 +66,7 @@ namespace util { namespace noise { namespace fractal {
|
||||||
struct base {
|
struct base {
|
||||||
virtual ~base () = default;
|
virtual ~base () = default;
|
||||||
|
|
||||||
virtual value_t operator() (point_t) = 0;
|
virtual value_t operator() (point_t) const noexcept = 0;
|
||||||
|
|
||||||
virtual unsigned octaves (void) const = 0;
|
virtual unsigned octaves (void) const = 0;
|
||||||
virtual unsigned octaves (unsigned) = 0;
|
virtual unsigned octaves (unsigned) = 0;
|
||||||
|
@ -115,7 +115,7 @@ namespace util { namespace noise { namespace fractal {
|
||||||
_gain)
|
_gain)
|
||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
value_t operator() (point_t p) override { return data (p); }
|
value_t operator() (point_t p) const noexcept override { return data (p); }
|
||||||
|
|
||||||
unsigned octaves (void) const override { return data.octaves (); }
|
unsigned octaves (void) const override { return data.octaves (); }
|
||||||
unsigned octaves (unsigned _octaves) override { return data.octaves (_octaves); }
|
unsigned octaves (unsigned _octaves) override { return data.octaves (_octaves); }
|
||||||
|
|
|
@ -31,7 +31,7 @@ using util::lerp::truncate;
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T
|
T
|
||||||
truncate<T>::operator() (T a, T, T weight)
|
truncate<T>::operator() (T a, T, T weight) noexcept
|
||||||
{
|
{
|
||||||
static_assert (std::is_floating_point<T>::value,
|
static_assert (std::is_floating_point<T>::value,
|
||||||
"lerp is only defined for floating types");
|
"lerp is only defined for floating types");
|
||||||
|
@ -49,7 +49,7 @@ template struct util::lerp::truncate<double>;
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T
|
T
|
||||||
linear<T>::operator() (T a, T b, T weight)
|
linear<T>::operator() (T a, T b, T weight) noexcept
|
||||||
{
|
{
|
||||||
static_assert (std::is_floating_point<T>::value,
|
static_assert (std::is_floating_point<T>::value,
|
||||||
"lerp is only defined for floating types");
|
"lerp is only defined for floating types");
|
||||||
|
@ -65,7 +65,7 @@ template struct util::lerp::linear<double>;
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T
|
T
|
||||||
cosine<T>::operator() (T a, T b, T weight)
|
cosine<T>::operator() (T a, T b, T weight) noexcept
|
||||||
{
|
{
|
||||||
static_assert (std::is_floating_point<T>::value,
|
static_assert (std::is_floating_point<T>::value,
|
||||||
"lerp is only defined for floating types");
|
"lerp is only defined for floating types");
|
||||||
|
@ -82,7 +82,7 @@ template struct util::lerp::cosine<double>;
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T
|
T
|
||||||
cubic<T>::operator() (T a, T b, T weight)
|
cubic<T>::operator() (T a, T b, T weight) noexcept
|
||||||
{
|
{
|
||||||
static_assert (std::is_floating_point<T>::value,
|
static_assert (std::is_floating_point<T>::value,
|
||||||
"lerp is only defined for floating types");
|
"lerp is only defined for floating types");
|
||||||
|
@ -100,7 +100,7 @@ template struct util::lerp::cubic<double>;
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T
|
T
|
||||||
quintic<T>::operator() (T a, T b, T weight)
|
quintic<T>::operator() (T a, T b, T weight) noexcept
|
||||||
{
|
{
|
||||||
static_assert (std::is_floating_point<T>::value,
|
static_assert (std::is_floating_point<T>::value,
|
||||||
"lerp is only defined for floating types");
|
"lerp is only defined for floating types");
|
||||||
|
|
|
@ -18,11 +18,11 @@
|
||||||
#define __UTIL_NOISE_LERP_HPP
|
#define __UTIL_NOISE_LERP_HPP
|
||||||
|
|
||||||
namespace util { namespace lerp {
|
namespace util { namespace lerp {
|
||||||
template <typename T> struct linear { T operator() (T, T, T weight); };
|
template <typename T> struct linear { T operator() (T, T, T weight) noexcept; };
|
||||||
template <typename T> struct cosine { T operator() (T, T, T weight); };
|
template <typename T> struct cosine { T operator() (T, T, T weight) noexcept; };
|
||||||
template <typename T> struct cubic { T operator() (T, T, T weight); };
|
template <typename T> struct cubic { T operator() (T, T, T weight) noexcept; };
|
||||||
template <typename T> struct quintic { T operator() (T, T, T weight); };
|
template <typename T> struct quintic { T operator() (T, T, T weight) noexcept; };
|
||||||
template <typename T> struct truncate { T operator() (T, T, T weight); };
|
template <typename T> struct truncate { T operator() (T, T, T weight) noexcept; };
|
||||||
} }
|
} }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace util { namespace noise { namespace rand {
|
||||||
template <size_t,typename> class Q
|
template <size_t,typename> class Q
|
||||||
>
|
>
|
||||||
U
|
U
|
||||||
scalar (uint64_t seed, Q<S,T> value)
|
scalar (uint64_t seed, Q<S,T> value) noexcept
|
||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
return permute::scalar<U> (seed, value);
|
return permute::scalar<U> (seed, value);
|
||||||
|
@ -53,7 +53,7 @@ namespace util { namespace noise { namespace rand {
|
||||||
template <size_t,typename> class Q
|
template <size_t,typename> class Q
|
||||||
>
|
>
|
||||||
R<S,U>
|
R<S,U>
|
||||||
coord (uint64_t seed, Q<S,T> value)
|
coord (uint64_t seed, Q<S,T> value) noexcept
|
||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
return permute::coord<R,U,S,T,Q> (seed, value);
|
return permute::coord<R,U,S,T,Q> (seed, value);
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace util { namespace noise { namespace rand {
|
||||||
template <size_t,typename> class Q
|
template <size_t,typename> class Q
|
||||||
>
|
>
|
||||||
static U
|
static U
|
||||||
scalar (uint64_t seed, Q<S,T> value);
|
scalar (uint64_t seed, Q<S,T> value) noexcept;
|
||||||
|
|
||||||
/// generate a coordinate type with uniform random components in the range [0, 1]
|
/// generate a coordinate type with uniform random components in the range [0, 1]
|
||||||
template <
|
template <
|
||||||
|
@ -40,7 +40,7 @@ namespace util { namespace noise { namespace rand {
|
||||||
template <size_t,typename> class Q
|
template <size_t,typename> class Q
|
||||||
>
|
>
|
||||||
static R<S,U>
|
static R<S,U>
|
||||||
coord (uint64_t seed, Q<S,T> value);
|
coord (uint64_t seed, Q<S,T> value) noexcept;
|
||||||
};
|
};
|
||||||
} } }
|
} } }
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace util { namespace noise { namespace rand {
|
||||||
template <size_t,typename> class Q
|
template <size_t,typename> class Q
|
||||||
>
|
>
|
||||||
U
|
U
|
||||||
hash::scalar (uint64_t seed, Q<S,T> query)
|
hash::scalar (uint64_t seed, Q<S,T> query) noexcept
|
||||||
{
|
{
|
||||||
constexpr decltype(seed) BITS = 0xFFFF;
|
constexpr decltype(seed) BITS = 0xFFFF;
|
||||||
static_assert (std::is_integral<T>::value,
|
static_assert (std::is_integral<T>::value,
|
||||||
|
@ -53,7 +53,7 @@ namespace util { namespace noise { namespace rand {
|
||||||
template <size_t,typename> class Q
|
template <size_t,typename> class Q
|
||||||
>
|
>
|
||||||
R<S,U>
|
R<S,U>
|
||||||
hash::coord (uint64_t seed, Q<S,T> query)
|
hash::coord (uint64_t seed, Q<S,T> query) noexcept
|
||||||
{
|
{
|
||||||
constexpr decltype(seed) PERTURB = 0x96c39996c36c36c3;
|
constexpr decltype(seed) PERTURB = 0x96c39996c36c36c3;
|
||||||
constexpr decltype(seed) BITS = 0xFFFF;
|
constexpr decltype(seed) BITS = 0xFFFF;
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace util { namespace noise { namespace rand {
|
||||||
template <size_t,typename> class Q
|
template <size_t,typename> class Q
|
||||||
>
|
>
|
||||||
static U
|
static U
|
||||||
scalar (uint64_t seed, Q<S,T> value);
|
scalar (uint64_t seed, Q<S,T> value) noexcept;
|
||||||
|
|
||||||
/// generate a coordinate type with uniform random components in the range [0, 1]
|
/// generate a coordinate type with uniform random components in the range [0, 1]
|
||||||
template <
|
template <
|
||||||
|
@ -42,7 +42,7 @@ namespace util { namespace noise { namespace rand {
|
||||||
template <size_t,typename> class Q
|
template <size_t,typename> class Q
|
||||||
>
|
>
|
||||||
static R<S,U>
|
static R<S,U>
|
||||||
coord (uint64_t seed, Q<S,T> value);
|
coord (uint64_t seed, Q<S,T> value) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const std::array<uint8_t, 256> PERMUTE;
|
static const std::array<uint8_t, 256> PERMUTE;
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace util { namespace noise { namespace rand {
|
||||||
template <size_t,typename> class Q
|
template <size_t,typename> class Q
|
||||||
>
|
>
|
||||||
U
|
U
|
||||||
permute::scalar (uint64_t seed, Q<S,T> query)
|
permute::scalar (uint64_t seed, Q<S,T> query) noexcept
|
||||||
{
|
{
|
||||||
|
|
||||||
size_t idx = PERMUTE[seed&0xff];
|
size_t idx = PERMUTE[seed&0xff];
|
||||||
|
@ -26,7 +26,7 @@ namespace util { namespace noise { namespace rand {
|
||||||
template <size_t,typename> class Q
|
template <size_t,typename> class Q
|
||||||
>
|
>
|
||||||
R<S,U>
|
R<S,U>
|
||||||
permute::coord (uint64_t seed, Q<S,T> query)
|
permute::coord (uint64_t seed, Q<S,T> query) noexcept
|
||||||
{
|
{
|
||||||
auto accum = seed;
|
auto accum = seed;
|
||||||
for (auto q: query) {
|
for (auto q: query) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user