From 46e1ac8e68657363a2cec0082efe068fd214c0de Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 24 Feb 2016 15:07:03 +1100 Subject: [PATCH] noise: move into seperate repository --- Makefile.am | 53 +------- noise.cpp | 55 --------- noise.hpp | 32 ----- noise.ipp | 35 ------ noise/basis/constant.cpp | 35 ------ noise/basis/constant.hpp | 43 ------- noise/basis/constant.ipp | 29 ----- noise/basis/gradient/exp.hpp | 57 --------- noise/basis/gradient/exp.ipp | 45 ------- noise/basis/gradient/uniform.hpp | 46 ------- noise/basis/gradient/uniform.ipp | 57 --------- noise/basis/patch.hpp | 51 -------- noise/basis/patch.ipp | 153 ----------------------- noise/basis/perlin.hpp | 55 --------- noise/basis/perlin.ipp | 80 ------------ noise/basis/runtime.cpp | 20 --- noise/basis/runtime.hpp | 84 ------------- noise/basis/type/distance.cpp | 51 -------- noise/basis/type/distance.hpp | 22 ---- noise/basis/type/gradient.cpp | 44 ------- noise/basis/type/gradient.hpp | 36 ------ noise/basis/value.hpp | 56 --------- noise/basis/value.ipp | 91 -------------- noise/basis/worley.hpp | 51 -------- noise/basis/worley.ipp | 96 --------------- noise/fractal/base.hpp | 95 --------------- noise/fractal/base.ipp | 202 ------------------------------- noise/fractal/fbm.hpp | 63 ---------- noise/fractal/fbm.ipp | 77 ------------ noise/fractal/hetero.hpp | 74 ----------- noise/fractal/hetero.ipp | 124 ------------------- noise/fractal/hmf.hpp | 62 ---------- noise/fractal/hmf.ipp | 86 ------------- noise/fractal/rmf.hpp | 71 ----------- noise/fractal/rmf.ipp | 119 ------------------ noise/fractal/runtime.cpp | 22 ---- noise/fractal/runtime.hpp | 164 ------------------------- noise/fwd.hpp | 27 ----- noise/lerp.cpp | 114 ----------------- noise/lerp.hpp | 28 ----- noise/lut.cpp | 120 ------------------ noise/lut.hpp | 45 ------- noise/midpoint.cpp | 121 ------------------ noise/midpoint.hpp | 28 ----- noise/rand.hpp | 66 ---------- noise/rand/hash.hpp | 49 -------- noise/rand/hash.ipp | 74 ----------- noise/rand/permute.cpp | 25 ---- noise/rand/permute.hpp | 55 --------- noise/rand/permute.ipp | 47 ------- noise/turbulence.hpp | 68 ----------- noise/turbulence.ipp | 73 ----------- 52 files changed, 1 insertion(+), 3475 deletions(-) delete mode 100644 noise.cpp delete mode 100644 noise.hpp delete mode 100644 noise.ipp delete mode 100644 noise/basis/constant.cpp delete mode 100644 noise/basis/constant.hpp delete mode 100644 noise/basis/constant.ipp delete mode 100644 noise/basis/gradient/exp.hpp delete mode 100644 noise/basis/gradient/exp.ipp delete mode 100644 noise/basis/gradient/uniform.hpp delete mode 100644 noise/basis/gradient/uniform.ipp delete mode 100644 noise/basis/patch.hpp delete mode 100644 noise/basis/patch.ipp delete mode 100644 noise/basis/perlin.hpp delete mode 100644 noise/basis/perlin.ipp delete mode 100644 noise/basis/runtime.cpp delete mode 100644 noise/basis/runtime.hpp delete mode 100644 noise/basis/type/distance.cpp delete mode 100644 noise/basis/type/distance.hpp delete mode 100644 noise/basis/type/gradient.cpp delete mode 100644 noise/basis/type/gradient.hpp delete mode 100644 noise/basis/value.hpp delete mode 100644 noise/basis/value.ipp delete mode 100644 noise/basis/worley.hpp delete mode 100644 noise/basis/worley.ipp delete mode 100644 noise/fractal/base.hpp delete mode 100644 noise/fractal/base.ipp delete mode 100644 noise/fractal/fbm.hpp delete mode 100644 noise/fractal/fbm.ipp delete mode 100644 noise/fractal/hetero.hpp delete mode 100644 noise/fractal/hetero.ipp delete mode 100644 noise/fractal/hmf.hpp delete mode 100644 noise/fractal/hmf.ipp delete mode 100644 noise/fractal/rmf.hpp delete mode 100644 noise/fractal/rmf.ipp delete mode 100644 noise/fractal/runtime.cpp delete mode 100644 noise/fractal/runtime.hpp delete mode 100644 noise/fwd.hpp delete mode 100644 noise/lerp.cpp delete mode 100644 noise/lerp.hpp delete mode 100644 noise/lut.cpp delete mode 100644 noise/lut.hpp delete mode 100644 noise/midpoint.cpp delete mode 100644 noise/midpoint.hpp delete mode 100644 noise/rand.hpp delete mode 100644 noise/rand/hash.hpp delete mode 100644 noise/rand/hash.ipp delete mode 100644 noise/rand/permute.cpp delete mode 100644 noise/rand/permute.hpp delete mode 100644 noise/rand/permute.ipp delete mode 100644 noise/turbulence.hpp delete mode 100644 noise/turbulence.ipp diff --git a/Makefile.am b/Makefile.am index 03d7a670..88a9c5e9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -197,56 +197,6 @@ UTIL_FILES = \ net/types.cpp \ net/types.hpp \ nocopy.hpp \ - noise.hpp \ - noise.ipp \ - noise/fwd.hpp \ - noise/basis/constant.cpp \ - noise/basis/constant.hpp \ - noise/basis/constant.ipp \ - noise/basis/gradient/uniform.hpp \ - noise/basis/gradient/uniform.ipp \ - noise/basis/gradient/exp.hpp \ - noise/basis/gradient/exp.ipp \ - noise/basis/patch.hpp \ - noise/basis/patch.ipp \ - noise/basis/perlin.hpp \ - noise/basis/perlin.ipp \ - noise/basis/runtime.cpp \ - noise/basis/runtime.hpp \ - noise/basis/type/distance.cpp \ - noise/basis/type/distance.hpp \ - noise/basis/type/gradient.hpp \ - noise/basis/type/gradient.cpp \ - noise/basis/value.hpp \ - noise/basis/value.ipp \ - noise/basis/worley.hpp \ - noise/basis/worley.ipp \ - noise/fractal/base.hpp \ - noise/fractal/base.ipp \ - noise/fractal/fbm.hpp \ - noise/fractal/fbm.ipp \ - noise/fractal/hetero.hpp \ - noise/fractal/hetero.ipp \ - noise/fractal/hmf.hpp \ - noise/fractal/hmf.ipp \ - noise/fractal/rmf.hpp \ - noise/fractal/rmf.ipp \ - noise/fractal/runtime.cpp \ - noise/fractal/runtime.hpp \ - noise/lerp.cpp \ - noise/lerp.hpp \ - noise/lut.cpp \ - noise/lut.hpp \ - noise/midpoint.cpp \ - noise/midpoint.hpp \ - noise/rand.hpp \ - noise/rand/hash.hpp \ - noise/rand/hash.ipp \ - noise/rand/permute.cpp \ - noise/rand/permute.hpp \ - noise/rand/permute.ipp \ - noise/turbulence.hpp \ - noise/turbulence.ipp \ pascal.cpp \ pascal.hpp \ platform.hpp \ @@ -379,8 +329,7 @@ bin_PROGRAMS = \ tools/json-clean \ tools/json-validate \ tools/json-schema \ - tools/hash \ - tools/noise + tools/hash noinst_PROGRAMS = tools/scratch diff --git a/noise.cpp b/noise.cpp deleted file mode 100644 index fc1d32a7..00000000 --- a/noise.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2011-2015 Danny Robson - */ - - -#include "noise.hpp" - -#include "range.hpp" - -#include -#include - - -//----------------------------------------------------------------------------- -template -void -util::noise::fill (image::buffer<1,T> &pixels, - const util::noise::fractal &gen) -{ - size_t h = pixels.h, s = pixels.s, w = pixels.w; - T *data = pixels.data (); - - for (size_t y = 0; y < h; ++y) - for (size_t x = 0; x < w; ++x) - data[y * s + x] = gen ({T(x), T(y)}); -} - -template void util::noise::fill (image::buffer<1,float>&, const util::noise::fractal&); -template void util::noise::fill (image::buffer<1,double>&, const util::noise::fractal&); - - -//----------------------------------------------------------------------------- -void -util::noise::image2d (uint8_t *restrict pixels, - size_t width, - size_t height, - const util::noise::fractal &p) { - for (size_t y = 0; y < height; ++y) - for (size_t x = 0; x < width; ++x) { - float v = p ({float(x), float(y)}); - pixels[x + y * width] = static_cast (v * std::numeric_limits::max ()); - } -} diff --git a/noise.hpp b/noise.hpp deleted file mode 100644 index b7791df6..00000000 --- a/noise.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2011-2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_HPP -#define __UTIL_NOISE_HPP - -#include -#include - -#include "image/buffer.hpp" - -namespace util { namespace noise { - template - void fill (image::buffer<1,T>&, const G&); -} } - -#include "noise.ipp" - -#endif diff --git a/noise.ipp b/noise.ipp deleted file mode 100644 index bc851f36..00000000 --- a/noise.ipp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2011-2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_IPP -#error -#endif -#define __UTIL_NOISE_IPP - -namespace util { namespace noise { - //------------------------------------------------------------------------- - template - void - fill (image::buffer<1,T> &pixels, const G& gen) - { - size_t h = pixels.h, s = pixels.s, w = pixels.w; - T *data = pixels.data (); - - for (size_t y = 0; y < h; ++y) - for (size_t x = 0; x < w; ++x) - data[y * s + x] = gen ({T(x), T(y)}); - } -} } diff --git a/noise/basis/constant.cpp b/noise/basis/constant.cpp deleted file mode 100644 index 4cce04a5..00000000 --- a/noise/basis/constant.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#include "constant.hpp" - -using util::noise::basis::constant; - - -/////////////////////////////////////////////////////////////////////////////// -template -constant::constant (seed_t _seed): - seed (_seed), - value (42) -{ ; } - - -/////////////////////////////////////////////////////////////////////////////// -template struct util::noise::basis::constant<2,float>; -template struct util::noise::basis::constant<2,double>; - -template struct util::noise::basis::constant<3,float>; -template struct util::noise::basis::constant<3,double>; diff --git a/noise/basis/constant.hpp b/noise/basis/constant.hpp deleted file mode 100644 index 18ff6b44..00000000 --- a/noise/basis/constant.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_BASIS_CONSTANT_HPP -#define __UTIL_NOISE_BASIS_CONSTANT_HPP - -#include "../rand.hpp" -#include "../../point.hpp" - -#include - -namespace util { namespace noise { namespace basis { - template - struct constant { - using value_t = T; - using point_t = point; - - constant (seed_t); - - T operator() (point_t) const noexcept; - - seed_t seed; - T value; - }; -} } } - - -#include "constant.ipp" - -#endif diff --git a/noise/basis/constant.ipp b/noise/basis/constant.ipp deleted file mode 100644 index 725a3c75..00000000 --- a/noise/basis/constant.ipp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_BASIS_CONSTANT_IPP -#error -#endif -#define __UTIL_NOISE_BASIS_CONSTANT_IPP - -namespace util { namespace noise { namespace basis { - template - T - constant::operator() (point_t) const noexcept - { - return value; - } -} } } diff --git a/noise/basis/gradient/exp.hpp b/noise/basis/gradient/exp.hpp deleted file mode 100644 index 84dcdbc4..00000000 --- a/noise/basis/gradient/exp.hpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - - -#ifndef __UTIL_NOISE_BASIS_GRADIENT_EXP_HPP -#define __UTIL_NOISE_BASIS_GRADIENT_EXP_HPP - -#include "./uniform.hpp" - -#include "../../fwd.hpp" -#include "../../../point.hpp" - -/////////////////////////////////////////////////////////////////////////////// -// modifies a standard uniforma gradient generator to follow an exponential -// distribution, base^(-t*exp) -// -// -namespace util { namespace noise { namespace basis { namespace gradient { - template < - size_t S, // probe point dimensionality - typename T // probe point value_type - > - struct exp : public uniform { - explicit exp (seed_t seed, - T base = (T)1.02, - T exponent = T{256}); - - T base (void) const; - T base (T); - - T exponent (void) const; - T exponent (T); - - protected: - vector generate (pointi) const; - - T m_base; - T m_exponent; - }; -} } } } - -#include "exp.ipp" - -#endif diff --git a/noise/basis/gradient/exp.ipp b/noise/basis/gradient/exp.ipp deleted file mode 100644 index b7b3e526..00000000 --- a/noise/basis/gradient/exp.ipp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_BASIS_EXP_IPP -#error -#endif -#define __UTIL_NOISE_BASIS_EXP_IPP - -#include "../../rand.hpp" - -#include - -namespace util { namespace noise { namespace basis { namespace gradient { - /////////////////////////////////////////////////////////////////////////// - template - exp::exp (seed_t _seed, T _base, T _exponent): - uniform (_seed), - m_base (_base), - m_exponent (_exponent) - { ; } - - - /////////////////////////////////////////////////////////////////////////// - template - vector - exp::generate (pointi p) const - { - auto t = rand::scalar (this->seed (), p); - auto factor = std::pow (m_base, -t * m_exponent); - return factor * uniform::generate (p); - } -} } } } diff --git a/noise/basis/gradient/uniform.hpp b/noise/basis/gradient/uniform.hpp deleted file mode 100644 index 8513df6b..00000000 --- a/noise/basis/gradient/uniform.hpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - - -#ifndef __UTIL_NOISE_BASIS_GRADIENT_UNIFORM_HPP -#define __UTIL_NOISE_BASIS_GRADIENT_UNIFORM_HPP - -#include "../../fwd.hpp" -#include "../../../point.hpp" - -namespace util { namespace noise { namespace basis { namespace gradient { - /// Perlin: interpolated value across each grid space - template < - size_t S, // probe point dimensionality - typename T // probe point value_type - > - struct uniform { - uniform (seed_t); - - seed_t seed (void) const; - seed_t seed (seed_t); - - protected: - vector generate (pointi) const; - - seed_t m_seed; - }; -} } } } - -#include "uniform.ipp" - -#endif - diff --git a/noise/basis/gradient/uniform.ipp b/noise/basis/gradient/uniform.ipp deleted file mode 100644 index 73fa798a..00000000 --- a/noise/basis/gradient/uniform.ipp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_BASIS_GRADIENT_UNIFORM_IPP -#error -#endif -#define __UTIL_NOISE_BASIS_GRADIENT_UNIFORM_IPP - -#include "../../rand.hpp" - -namespace util { namespace noise { namespace basis { namespace gradient { - /////////////////////////////////////////////////////////////////////////// - template - uniform::uniform (seed_t _seed): - m_seed (_seed) - { ; } - - - //------------------------------------------------------------------------- - template - seed_t - uniform::seed (void) const - { - return m_seed; - } - - - //------------------------------------------------------------------------- - template - seed_t - uniform::seed (seed_t _seed) - { - return m_seed = _seed; - } - - - //------------------------------------------------------------------------- - template - vector - uniform::generate (pointi p) const - { - return rand::coord (m_seed, p) * 2 - 1; - } -} } } } diff --git a/noise/basis/patch.hpp b/noise/basis/patch.hpp deleted file mode 100644 index e6c8a987..00000000 --- a/noise/basis/patch.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_BASIS_PATCH_HPP -#define __UTIL_NOISE_BASIS_PATCH_HPP - -#include "./type/distance.hpp" - -#include "../fwd.hpp" -#include "../../point.hpp" - -namespace util { namespace noise { namespace basis { - template - struct patch : public type::distance { - patch (seed_t, T width = 0); - - range bounds (void) const; - - T operator() (point) const noexcept; - - seed_t seed (void) const; - seed_t seed (seed_t); - - T width (void) const; - T width (T); - - private: - static constexpr T THRESHOLD = 1 - T(0.999); - - T m_width; - T m_power; - seed_t m_seed; - }; -} } } - -#include "patch.ipp" - -#endif diff --git a/noise/basis/patch.ipp b/noise/basis/patch.ipp deleted file mode 100644 index 7109a6f5..00000000 --- a/noise/basis/patch.ipp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - -#if defined(__UTIL_NOISE_BASIS_PATCH_IPP) -#error -#endif -#define __UTIL_NOISE_BASIS_PATCH_IPP - -#include "../../types.hpp" -#include "../../vector.hpp" - - -namespace util { namespace noise { namespace basis { - /////////////////////////////////////////////////////////////////////////// - template - patch::patch (seed_t _seed, T _width): - m_width (_width), - m_power (exactly_zero (_width) - ? std::numeric_limits::infinity () - : std::log (THRESHOLD) / std::log (1 - _width)), - m_seed (_seed) - { ; } - - - /////////////////////////////////////////////////////////////////////////// - template - range - patch::bounds (void) const - { - return { T{0}, T{1} }; - } - - - /////////////////////////////////////////////////////////////////////////// - template - T - patch::operator () (point p) const noexcept - { - static const size_t COUNT = type::distance::OFFSET_SIZE; - - // extract integer and fractional parts. be careful to always round down - auto p_int = floor (p).template cast (); - auto p_rem = (p - p_int).template as (); - - // find the distances to each neighbour's centroid. - util::point centres[COUNT]; - std::transform (std::begin (this->OFFSETS), - std::end (this->OFFSETS), - std::begin (centres), - [this,p_int] (auto i) { return rand::coord (m_seed, p_int + i) + i; }); - - T distances[COUNT]; - std::transform (std::begin (centres), - std::end (centres), - std::begin (distances), - [p_rem] (auto i) { return util::distance (p_rem, i); }); - - // sort the distances using indices so we can reuse indices into - // 'OFFSETS' to generate the random patch values - unsigned indices[COUNT]; - std::iota (std::begin (indices), std::end (indices), 0); - - std::sort (std::begin (indices), - std::end (indices), - [&] (auto a, auto b) { - return distances[a] < distances[b]; - }); - - // setup normalisation for the distances to the nearest points. the - // neighbourhood size is implicitly specified by the 1.5 unit maximum - // distance. - const size_t hi_off = pow(3,S); - - const auto lo = distances[indices[0 ]]; - const auto hi = distances[indices[hi_off]]; - - T out = 0.f; - T sumw = 0.f; - - // sum the weight values of each neighbour. weight by a function of - // the distance. we use an power function which allows a known width - // to blend. - for (size_t i = 0; i < hi_off; ++i) - { - auto v = rand::scalar ( - m_seed, - p_int + this->OFFSETS[indices[i]] - ); - - auto d = (distances[indices[i]] - lo) / (hi - lo); - auto w = std::pow (1 - d, m_power); - - sumw += w; - out += v * w; - } - - return out / sumw; - } - - - /////////////////////////////////////////////////////////////////////////// - template - seed_t - patch::seed (void) const - { - return m_seed; - } - - - //------------------------------------------------------------------------- - template - seed_t - patch::seed (util::noise::seed_t _seed) - { - return m_seed = _seed; - } - - - /////////////////////////////////////////////////////////////////////////// - template - T - patch::width (void) const - { - return m_width; - } - - - //------------------------------------------------------------------------- - template - T - patch::width (T _width) - { - m_width = _width; - m_power = exactly_zero (_width) - ? std::numeric_limits::infinity () - : std::log (THRESHOLD) / std::log (1 - _width); - - return m_width; - } -} } } diff --git a/noise/basis/perlin.hpp b/noise/basis/perlin.hpp deleted file mode 100644 index c95c1d84..00000000 --- a/noise/basis/perlin.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - - -#ifndef __UTIL_NOISE_BASIS_PERLIN_HPP -#define __UTIL_NOISE_BASIS_PERLIN_HPP - -#include "./gradient/uniform.hpp" -#include "./type/gradient.hpp" - -#include "../fwd.hpp" -#include "../../point.hpp" -#include "../../range.hpp" - -namespace util { namespace noise { namespace basis { - /// Perlin: interpolated value across each grid space - template < - size_t S, // point point dimensionality - typename T, // arithmetic and result value_type, must be floating point - template < // gradient interpolation function - typename - > class L, - template < // gradient provider class, must provide generate(point_t) - size_t, - typename - > class G = gradient::uniform - > - struct perlin : public G, public type::gradient { - using value_t = T; - using point_t = point; - - perlin (seed_t); - - range bounds (void) const; - - T operator() (point_t) const noexcept; - }; -} } } - -#include "perlin.ipp" - -#endif diff --git a/noise/basis/perlin.ipp b/noise/basis/perlin.ipp deleted file mode 100644 index 6ca50e95..00000000 --- a/noise/basis/perlin.ipp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_BASIS_PERLIN_IPP -#error -#endif -#define __UTIL_NOISE_BASIS_PERLIN_IPP - -#include "../../types.hpp" - - -namespace util { namespace noise { namespace basis { - /////////////////////////////////////////////////////////////////////////// - template class L, template class G> - perlin::perlin (seed_t _seed): - G (_seed) - { ; } - - - //------------------------------------------------------------------------- - template class L, template class G> - util::range - perlin::bounds (void) const - { - return { - -std::sqrt (T{2}) / 2, - std::sqrt (T{2}) / 2 - }; - } - - - //------------------------------------------------------------------------- - template class L, template class G> - T - perlin::operator() (point_t p) const noexcept - { - // extract integer and fractional parts. be careful to always round down - auto p_int = floor (p).template cast (); - auto p_rem = p - p_int; - - // generate the corner positions - pointi p_[pow(2,S)]; - std::transform (std::begin (this->CORNERS), std::end (this->CORNERS), - std::begin (p_), - [p_int] (auto i) { return i + p_int; }); - - // generate the corner gradients - vector g_[pow(2,S)]; - std::transform (std::begin (p_), std::end (p_), - std::begin (g_), - [this] (auto i) { return this->generate (i); }); - - // compute the dot products - T v_[pow(2,S)]; - for (size_t i = 0; i < elems (v_); ++i) - v_[i] = dot (g_[i], p - p_[i]); - - // interpolate the results - T l_[pow(2,S)]; - std::copy (std::begin (v_), std::end (v_), std::begin (l_)); - - for (size_t i = S; i; --i) - for (size_t j = 0; j < std::pow(2,i); j += 2) - l_[j / 2] = L() (l_[j], l_[j+1], p_rem[S-i]); - return l_[0]; - } -} } } diff --git a/noise/basis/runtime.cpp b/noise/basis/runtime.cpp deleted file mode 100644 index c2fab601..00000000 --- a/noise/basis/runtime.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#include "runtime.hpp" - - -template struct util::noise::basis::runtime<2,float>; diff --git a/noise/basis/runtime.hpp b/noise/basis/runtime.hpp deleted file mode 100644 index 386c79f4..00000000 --- a/noise/basis/runtime.hpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - - -#ifndef __UTIL_NOISE_BASIS_RUNTIME_HPP -#define __UTIL_NOISE_BASIS_RUNTIME_HPP - -#include "../fwd.hpp" -#include "../../point.hpp" -#include "../../range.hpp" - -#include - -namespace util { namespace noise { namespace basis { - template - struct runtime { - public: - using value_t = T; - using point_t = point; - - runtime (seed_t) {} - runtime (runtime&&) = default; - runtime (const runtime&) = delete; - runtime& operator= (const runtime&) = delete; - - // basis functions - T operator () (util::point p) const noexcept { return (*m_child) (p); } - range bounds (void) const { return m_child->bounds (); } - - seed_t seed (void) const { return m_child->seed (); } - seed_t seed (seed_t) { return m_child->seed (); } - - private: - struct base { - virtual ~base () = default; - virtual T operator() (util::point) const noexcept = 0; - virtual range bounds (void) const = 0; - virtual seed_t seed (void) const = 0; - virtual seed_t seed (seed_t) = 0; - }; - - template - struct child : public base { - template - child (seed_t _seed, Args&& ...args): data (_seed, std::forward (args)...) { } - virtual T operator() (util::point p) const noexcept override { return data (p); } - virtual range bounds (void) const override { return data.bounds (); } - virtual seed_t seed (void) const override { return data.seed (); } - virtual seed_t seed (seed_t _seed) override { return data.seed (_seed); } - - private: - B data; - }; - - std::unique_ptr m_child; - - public: - template - void - reset (seed_t _seed, Args&& ...args) - { - using basis_t = B; - using child_t = child; - - m_child.reset (new child_t (_seed, std::forward (args)...)); - } - }; -} } } - -#endif - diff --git a/noise/basis/type/distance.cpp b/noise/basis/type/distance.cpp deleted file mode 100644 index 9fe655cc..00000000 --- a/noise/basis/type/distance.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "./distance.hpp" -#include "../../../extent.hpp" -#include "../../../cast.hpp" - - -/////////////////////////////////////////////////////////////////////////////// -template -static const std::array< - util::vectori, - util::pow(R*2+1,S) -> -generate (void) -{ - using value_type = typename util::vectori::value_type; - - static const util::extent_range< - S,typename util::vectori::value_type - > area (util::extent {R*2+1}); - - std::array< - util::vectori, - util::pow(R*2+1,S) - > out; - - std::transform (area.begin (), area.end (), - out.begin (), - [] (auto i) { - return i.template as () - sign_cast (R); - }); - - return out; -} - - -/////////////////////////////////////////////////////////////////////////////// -template -const std::array< - util::vectori, - util::pow(R*2+1,S) -> -util::noise::basis::type::distance::OFFSETS = generate (); - - -//----------------------------------------------------------------------------- -template struct util::noise::basis::type::distance<1,1>; -template struct util::noise::basis::type::distance<2,1>; -template struct util::noise::basis::type::distance<3,1>; - -template struct util::noise::basis::type::distance<1,2>; -template struct util::noise::basis::type::distance<2,2>; -template struct util::noise::basis::type::distance<3,2>; diff --git a/noise/basis/type/distance.hpp b/noise/basis/type/distance.hpp deleted file mode 100644 index 7111d745..00000000 --- a/noise/basis/type/distance.hpp +++ /dev/null @@ -1,22 +0,0 @@ - -#ifndef __UTIL_NOISE_BASIS_TYPE_HPP -#define __UTIL_NOISE_BASIS_TYPE_HPP - -#include "../../../vector.hpp" -#include "../../../maths.hpp" - -#include - -namespace util { namespace noise { namespace basis { namespace type { - template - struct distance { - protected: - static constexpr size_t OFFSET_SIZE = util::pow(R*2+1,S); - - static const std::array< - vectori, util::pow(R*2+1,S) - > OFFSETS; - }; -} } } } - -#endif diff --git a/noise/basis/type/gradient.cpp b/noise/basis/type/gradient.cpp deleted file mode 100644 index c8f1eb05..00000000 --- a/noise/basis/type/gradient.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - -#include "./gradient.hpp" - - -/////////////////////////////////////////////////////////////////////////////// -template -static std::array,util::pow(2,S)> -generate (void) -{ - std::array,util::pow(2,S)> out; - - for (size_t i = 0; i < util::pow(2,S); ++i) - for (size_t s = 0; s < S; ++s) - out[i][s] = (i >> s) & 1; - - return out; -} - - -/////////////////////////////////////////////////////////////////////////////// -template -const std::array,util::pow(2,S)> -util::noise::basis::type::gradient::CORNERS = generate (); - -//----------------------------------------------------------------------------- -template struct util::noise::basis::type::gradient<1>; -template struct util::noise::basis::type::gradient<2>; -template struct util::noise::basis::type::gradient<3>; -template struct util::noise::basis::type::gradient<4>; diff --git a/noise/basis/type/gradient.hpp b/noise/basis/type/gradient.hpp deleted file mode 100644 index 36582a93..00000000 --- a/noise/basis/type/gradient.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_BASIS_TYPE_GRADIENT_HPP -#define __UTIL_NOISE_BASIS_TYPE_GRADIENT_HPP - -#include "../../../point.hpp" -#include "../../../maths.hpp" - -#include - - -/////////////////////////////////////////////////////////////////////////////// -namespace util { namespace noise { namespace basis { namespace type { - template - struct gradient { - - protected: - static const std::array,util::pow(2,S)> CORNERS; - }; -} } } } - -#endif diff --git a/noise/basis/value.hpp b/noise/basis/value.hpp deleted file mode 100644 index 882d961b..00000000 --- a/noise/basis/value.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - - -#ifndef __UTIL_NOISE_BASIS_VALUE_HPP -#define __UTIL_NOISE_BASIS_VALUE_HPP - -#include "./type/gradient.hpp" - -#include "../fwd.hpp" -#include "../../range.hpp" -#include "../../point.hpp" - -namespace util { namespace noise { namespace basis { - /// Single value per grid space - template < - size_t S, - typename T, - template < - typename - > class L - > - struct value : public type::gradient { - using value_t = T; - using point_t = point; - - value (seed_t); - - range bounds (void) const; - - value_t operator() (point_t) const noexcept; - - seed_t seed (void) const; - seed_t seed (seed_t); - - private: - seed_t m_seed; - }; -} } } - -#include "value.ipp" - -#endif diff --git a/noise/basis/value.ipp b/noise/basis/value.ipp deleted file mode 100644 index 6045ef81..00000000 --- a/noise/basis/value.ipp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_BASIS_VALUE_IPP -#error -#endif -#define __UTIL_NOISE_BASIS_VALIE_IPP - -#include "../rand.hpp" -#include "../../types.hpp" - - -namespace util { namespace noise { namespace basis { - /////////////////////////////////////////////////////////////////////////// - template class L> - value::value (seed_t _seed): - m_seed (_seed) - { ; } - - - //------------------------------------------------------------------------- - template class L> - util::range - value::bounds (void) const - { - return { -1, 1 }; - } - - - //------------------------------------------------------------------------- - template class L> - seed_t - value::seed (void) const - { - return m_seed; - } - - - //------------------------------------------------------------------------- - template class L> - seed_t - value::seed (seed_t _seed) - { - return m_seed = _seed; - } - - - //------------------------------------------------------------------------- - template class L> - T - value::operator() (util::point p) const noexcept - { - // extract integer and fractional parts. be careful to always round down - auto p_int = floor (p).template cast (); - auto p_rem = p - p_int; - - // generate the corner points - std::array,pow(2,S)> p_; - std::transform (std::begin (this->CORNERS), std::end (this->CORNERS), - std::begin (p_), - [p_int] (auto i) { return p_int + i; }); - - // Generate the corner values - std::array g_; - std::transform (std::begin (p_), std::end (p_), - std::begin (g_), - [this] (auto i) { return rand::scalar (m_seed, i) * 2 - 1; }); - - // Interpolate on one dimension, then the other. - T l_[pow(2,S)]; - std::copy (std::begin (g_), std::end (g_), std::begin (l_)); - - for (size_t i = S; i; --i) - for (size_t j = 0; j < std::pow(2,i); j += 2) - l_[j / 2] = L() (l_[j], l_[j+1], p_rem[S-i]); - return l_[0]; - } -} } } diff --git a/noise/basis/worley.hpp b/noise/basis/worley.hpp deleted file mode 100644 index 3a67deb7..00000000 --- a/noise/basis/worley.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - - -#ifndef __UTIL_NOISE_BASIS_WORLEY_HPP -#define __UTIL_NOISE_BASIS_WORLEY_HPP - -#include "./type/distance.hpp" - -#include "../fwd.hpp" -#include "../../point.hpp" -#include "../../range.hpp" - -namespace util { namespace noise { namespace basis { - template - struct worley : public type::distance { - using value_t = T; - using point_t = point; - - worley (seed_t); - - range bounds (void) const; - - value_t operator() (point_t) const noexcept; - - seed_t seed (void) const; - seed_t seed (seed_t); - - private: - point generate (point) const; - - seed_t m_seed; - }; -} } } - -#include "worley.ipp" - -#endif diff --git a/noise/basis/worley.ipp b/noise/basis/worley.ipp deleted file mode 100644 index 2ba3fbe6..00000000 --- a/noise/basis/worley.ipp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_BASIS_WORLEY_IPP -#error -#endif -#define __UTIL_NOISE_BASIS_WORLEY_IPP - - -#include "../../debug.hpp" - - -namespace util { namespace noise { namespace basis { - /////////////////////////////////////////////////////////////////////////// - template - worley::worley (seed_t _seed): - m_seed (_seed) - { ; } - - - //------------------------------------------------------------------------- - template - util::range - worley::bounds (void) const - { - return { 0.0, 1.5 }; - } - - - //------------------------------------------------------------------------- - template - seed_t - worley::seed (void) const - { - return m_seed; - } - - - //------------------------------------------------------------------------- - template - seed_t - worley::seed (seed_t _seed) - { - return m_seed = _seed; - } - - - //------------------------------------------------------------------------- - template - T - worley::operator() (point p) const noexcept - { - // extract integer and fractional parts. be careful to always round down - auto p_int = floor (p).template cast (); - auto p_rem = (p - p_int).template as (); - - // setup an array of distances - constexpr size_t COUNT = type::distance::OFFSET_SIZE; - T distances[COUNT]; - - std::transform (std::begin (this->OFFSETS), std::end (this->OFFSETS), - distances, - [p_int,p_rem,this] (auto i) { - auto q = this->generate (p_int + i); - return distance2 (q + i, p_rem); - }); - - // find the f'th lowest value - static_assert (F < COUNT, "worley order must be less than search radius"); - std::partial_sort (distances, distances + F, distances + COUNT); - CHECK_GE (distances[F], 0); - return distances[F]; - } - - - ////////////////////////////////////////////////////////////////////////// - template - point - worley::generate (point p) const - { - return rand::coord (m_seed, p); - } -} } } diff --git a/noise/fractal/base.hpp b/noise/fractal/base.hpp deleted file mode 100644 index 80ee5a6e..00000000 --- a/noise/fractal/base.hpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUvalue_t WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_FRACTAL_BASE_HPP -#define __UTIL_NOISE_FRACTAL_BASE_HPP - -#include - -#include "../../point.hpp" -#include "../rand.hpp" - -namespace util { namespace noise { namespace fractal { - /// Fractal Brownian Motion summation. - /// - /// Sum progressive layers of a noise basis with scaling frequency - /// and amplitude. - /// - /// octaves: count of layers to be summed - /// frequency: point scaling factor for the base octave - /// lacunarity: per octave frequency scaling factor - /// amplitude: maximum absolute value of the noise - /// gain: per octave amplitude scaling factor. typically 1/f. - template - struct base { - using value_t = typename B::value_t; - using point_t = typename B::point_t; - - // constructors - base (seed_t, - unsigned octaves, - value_t H, - value_t frequency, - value_t lacunarity, - value_t amplitude, - value_t gain); - - // accessors - constexpr unsigned octaves (void) const; - unsigned octaves (unsigned); - - constexpr value_t H (void) const; - value_t H (value_t); - - constexpr value_t frequency (void) const; - value_t frequency (value_t); - - constexpr value_t lacunarity (void) const; - value_t lacunarity (value_t); - - constexpr value_t amplitude (void) const; - value_t amplitude (value_t); - - constexpr value_t gain (void) const; - value_t gain (value_t); - - seed_t seed (void) const; - seed_t seed (seed_t); - - const B& basis (void) const; - B& basis (void); - - protected: - unsigned m_octaves; - value_t m_H; - - value_t m_frequency; - value_t m_lacunarity; - - value_t m_amplitude; - value_t m_gain; - - B m_basis; - - value_t m_invAH; - value_t m_invGH; - }; -} } } - -#include "base.ipp" - -#endif - diff --git a/noise/fractal/base.ipp b/noise/fractal/base.ipp deleted file mode 100644 index c1c13c32..00000000 --- a/noise/fractal/base.ipp +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUvalue_t WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_FRACTAL_BASE_IPP -#error -#endif -#define __UTIL_NOISE_FRACTAL_BASE_IPP - -#include - -namespace util { namespace noise { namespace fractal { - /////////////////////////////////////////////////////////////////////////// - template - base::base (seed_t _seed, - unsigned _octaves, - value_t _H, - value_t _frequency, - value_t _lacunarity, - value_t _amplitude, - value_t _gain): - // literals - m_octaves (_octaves), - m_H (_H), - m_frequency (_frequency), - m_lacunarity (_lacunarity), - m_amplitude (_amplitude), - m_gain (_gain), - // compound - m_basis (_seed), - // calculated - m_invAH (std::pow (_amplitude, -_H)), - m_invGH (std::pow (_gain, _H)) - { - CHECK_NEZ (m_octaves); - CHECK_NEZ (m_frequency); - CHECK_NEZ (m_amplitude); - } - - - /////////////////////////////////////////////////////////////////////////// - template - unsigned - base::octaves (unsigned _octaves) - { - return m_octaves = _octaves; - } - - - //------------------------------------------------------------------------- - template - constexpr unsigned - base::octaves (void) const - { - return m_octaves; - } - - - //------------------------------------------------------------------------- - template - typename base::value_t - base::H (value_t _h) - { - m_H = _h; - m_invAH = std::pow (m_amplitude, -m_H); - m_invGH = std::pow (m_gain, m_H); - return m_H; - } - - - //------------------------------------------------------------------------- - template - constexpr typename base::value_t - base::H (void) const - { - return m_H; - } - - - //------------------------------------------------------------------------- - template - typename base::value_t - base::frequency (value_t _frequency) - { - return m_frequency = _frequency; - } - - - //------------------------------------------------------------------------- - template - constexpr typename base::value_t - base::frequency (void) const - { - return m_frequency; - } - - - //------------------------------------------------------------------------- - template - typename base::value_t - base::lacunarity (value_t _lacunarity) - { - return m_lacunarity = _lacunarity; - } - - - //------------------------------------------------------------------------- - template - constexpr typename base::value_t - base::lacunarity (void) const - { - return m_lacunarity; - } - - - //------------------------------------------------------------------------- - template - constexpr typename base::value_t - base::amplitude (void) const - { - return m_amplitude; - } - - - //------------------------------------------------------------------------- - template - typename base::value_t - base::amplitude (value_t _amplitude) - { - m_amplitude = _amplitude; - m_invAH = std::pow (m_amplitude, -m_H); - return m_amplitude; - } - - - //------------------------------------------------------------------------- - template - constexpr typename base::value_t - base::gain (void) const - { - return m_gain; - } - - - //------------------------------------------------------------------------- - template - typename base::value_t - base::gain (value_t _gain) - { - m_gain = _gain; - m_invGH = std::pow (_gain, m_H); - return m_gain; - } - - - //------------------------------------------------------------------------- - template - seed_t - base::seed (seed_t _seed) - { - return m_basis.seed (_seed); - } - - - //------------------------------------------------------------------------- - template - seed_t - base::seed (void) const - { - return m_basis.seed (); - } - - - //------------------------------------------------------------------------- - template - const B& - base::basis (void) const - { - return m_basis; - } - - - //------------------------------------------------------------------------- - template - B& - base::basis (void) - { - return m_basis; - } -} } } diff --git a/noise/fractal/fbm.hpp b/noise/fractal/fbm.hpp deleted file mode 100644 index 9c5a7b40..00000000 --- a/noise/fractal/fbm.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUvalue_t WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_FRACTAL_FBM_HPP -#define __UTIL_NOISE_FRACTAL_FBM_HPP - -#include - -#include "base.hpp" -#include "../../point.hpp" - -namespace util { namespace noise { namespace fractal { - /// Fractal Brownian Motion summation. - /// - /// Sum progressive layers of a noise basis with scaling frequency - /// and amplitude. - /// - /// octaves: count of layers to be summed - /// frequency: point scaling factor for the base octave - /// lacunarity: per octave frequency scaling factor - /// amplitude: maximum absolute value of the noise - /// gain: per octave amplitude scaling factor. typically 1/f. - template - struct fbm : public base { - using value_t = typename base::value_t; - using point_t = typename base::point_t; - - static constexpr unsigned DEFAULT_OCTAVES = 8; - static constexpr value_t DEFAULT_H = 1; - static constexpr value_t DEFAULT_FREQUENCY = value_t(0.1); - static constexpr value_t DEFAULT_LACUNARITY = 2; - static constexpr value_t DEFAULT_AMPLITUDE = 1; - static constexpr value_t DEFAULT_GAIN = 1 / DEFAULT_LACUNARITY; - - fbm (seed_t seed, - unsigned octaves, - value_t H, - value_t frequency, - value_t lacunarity, - value_t amplitude, - value_t gain); - explicit fbm (seed_t = 0); - - value_t operator() (point_t) const noexcept; - }; -} } } - -#include "fbm.ipp" - -#endif diff --git a/noise/fractal/fbm.ipp b/noise/fractal/fbm.ipp deleted file mode 100644 index 6905f952..00000000 --- a/noise/fractal/fbm.ipp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUvalue_t WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_FRACTAL_FBM_IPP -#error -#endif -#define __UTIL_NOISE_FRACTAL_FBM_IPP - -#include "../../debug.hpp" - -namespace util { namespace noise { namespace fractal { - /////////////////////////////////////////////////////////////////////////// - template - fbm::fbm (seed_t _seed, - unsigned _octaves, - value_t _H, - value_t _frequency, - value_t _lacunarity, - value_t _amplitude, - value_t _gain): - base (_seed, - _octaves, - _H, - _frequency, - _lacunarity, - _amplitude, - _gain) - { ; } - - - //------------------------------------------------------------------------- - template - fbm::fbm (seed_t _seed): - fbm (_seed, - DEFAULT_OCTAVES, - DEFAULT_H, - DEFAULT_FREQUENCY, - DEFAULT_LACUNARITY, - DEFAULT_AMPLITUDE, - DEFAULT_GAIN) - { ; } - - - /////////////////////////////////////////////////////////////////////////// - template - typename fbm::value_t - fbm::operator() (point_t p) const noexcept - { - value_t total = 0; - value_t scale = this->m_invAH; - - p *= this->m_frequency; - - for (size_t i = 0; i < this->m_octaves; ++i) { - total += this->m_basis (p) * scale; - - p += PI; - p *= this->m_lacunarity; - scale *= this->m_invGH; - } - - return total; - } -} } } diff --git a/noise/fractal/hetero.hpp b/noise/fractal/hetero.hpp deleted file mode 100644 index a9926033..00000000 --- a/noise/fractal/hetero.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUvalue_t WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_FRACTAL_HETERO_HPP -#define __UTIL_NOISE_FRACTAL_HETERO_HPP - -#include - -#include "base.hpp" -#include "../../point.hpp" - -namespace util { namespace noise { namespace fractal { - /////////////////////////////////////////////////////////////////////// - /// Heterogeneous procedural terrain fucntion: stats by altitude method - template - struct hetero : public base { - using value_t = typename base::value_t; - using point_t = typename base::point_t; - - static constexpr unsigned DEFAULT_OCTAVES = 6; - static constexpr value_t DEFAULT_H = value_t(0.75); - static constexpr value_t DEFAULT_FREQUENCY = value_t(0.1); - static constexpr value_t DEFAULT_LACUNARITY = 2; - static constexpr value_t DEFAULT_AMPLITUDE = 1; - static constexpr value_t DEFAULT_GAIN = 1 / DEFAULT_LACUNARITY; - static constexpr value_t DEFAULT_OFFSET = value_t(0.7); - - hetero (seed_t, - unsigned octaves, - value_t H, - value_t frequency, - value_t lacunarity, - value_t amplitude, - value_t gain); - - hetero (seed_t, - unsigned octaves, - value_t H, - value_t frequency, - value_t lacunarity, - value_t amplitude, - value_t gain, - value_t offset); - - explicit hetero (seed_t = 0); - - constexpr value_t offset (void) const; - value_t offset (value_t); - - value_t operator() (point_t) const; - - private: - value_t m_offset; - }; -} } } - -#include "hetero.ipp" - -#endif - - diff --git a/noise/fractal/hetero.ipp b/noise/fractal/hetero.ipp deleted file mode 100644 index 60b19a8e..00000000 --- a/noise/fractal/hetero.ipp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUvalue_t WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_FRACTAL_HETERO_IPP -#error -#endif -#define __UTIL_NOISE_FRACTAL_HETERO_IPP - -namespace util { namespace noise { namespace fractal { - /////////////////////////////////////////////////////////////////////////// - template - hetero::hetero(seed_t _seed, - unsigned _octaves, - value_t _H, - value_t _frequency, - value_t _lacunarity, - value_t _amplitude, - value_t _gain): - hetero (_seed, - _octaves, - _H, - _frequency, - _lacunarity, - _amplitude, - _gain, - -this->basis ().bounds ().min + this->basis ().bounds ().magnitude () / value_t{2}) - { ; } - - - //------------------------------------------------------------------------- - template - hetero::hetero(seed_t _seed, - unsigned _octaves, - value_t _H, - value_t _frequency, - value_t _lacunarity, - value_t _amplitude, - value_t _gain, - value_t _offset): - base (_seed, - _octaves, - _H, - _frequency, - _lacunarity, - _amplitude, - _gain), - m_offset (_offset) - { ; } - - - //------------------------------------------------------------------------- - template - hetero::hetero (seed_t _seed): - hetero (_seed, - DEFAULT_OCTAVES, - DEFAULT_H, - DEFAULT_FREQUENCY, - DEFAULT_LACUNARITY, - DEFAULT_AMPLITUDE, - DEFAULT_GAIN, - DEFAULT_OFFSET) - { ; } - - - /////////////////////////////////////////////////////////////////////////// - template - constexpr typename hetero::value_t - hetero::offset (void) const - { - return m_offset; - } - - - //------------------------------------------------------------------------- - template - typename hetero::value_t - hetero::offset (value_t _offset) - { - return m_offset = _offset; - } - - - /////////////////////////////////////////////////////////////////////////// - template - typename hetero::value_t - hetero::operator() (point_t p) const - { - value_t scale = this->m_invAH; - - p *= this->m_frequency; - value_t result = (this->m_basis (p) + m_offset) * scale; - p *= this->m_lacunarity; - - value_t increment = 0; - - for (size_t i = 1; i < this->m_octaves; ++i) { - scale *= this->m_invGH; - - increment = this->m_basis (p) + m_offset; - increment *= scale; - increment *= result; - - result += increment; - - p += PI; - p *= this->m_lacunarity; - } - - return result; - } -} } } diff --git a/noise/fractal/hmf.hpp b/noise/fractal/hmf.hpp deleted file mode 100644 index 7e3311ea..00000000 --- a/noise/fractal/hmf.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_FRACTAL_HMF_HPP -#define __UTIL_NOISE_FRACTAL_HMF_HPP - -#include - -#include "../../point.hpp" - -namespace util { namespace noise { namespace fractal { - /////////////////////////////////////////////////////////////////////// - /// Musgrave's "Hybrid MultiFractal" - template - struct hmf : public base { - using value_t = typename base::value_t; - using point_t = typename base::point_t; - - // H should be fairly low due to the decreasing weight parameter in eval - static constexpr unsigned DEFAULT_OCTAVES = 6; - static constexpr value_t DEFAULT_H = value_t(0.25); - static constexpr value_t DEFAULT_FREQUENCY = value_t(0.1); - static constexpr value_t DEFAULT_LACUNARITY = 2; - static constexpr value_t DEFAULT_AMPLITUDE = 1; - static constexpr value_t DEFAULT_GAIN = 1 / DEFAULT_LACUNARITY; - static constexpr value_t DEFAULT_OFFSET = value_t(0.7); - - hmf (seed_t, - unsigned octaves, - value_t H, - value_t frequency, - value_t lacunarity, - value_t amplitude, - value_t gain, - value_t offset); - - explicit hmf (seed_t = 0); - - value_t operator() (point_t) const; - - private: - value_t m_offset; - }; -} } } - -#include "hmf.ipp" - -#endif - diff --git a/noise/fractal/hmf.ipp b/noise/fractal/hmf.ipp deleted file mode 100644 index 15d98147..00000000 --- a/noise/fractal/hmf.ipp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_FRACTAL_HMF_IPP -#error -#endif -#define __UTIL_NOISE_FRACTAL_HMF_IPP - - -namespace util { namespace noise { namespace fractal { - /////////////////////////////////////////////////////////////////////////// - template - hmf::hmf (seed_t _seed, - unsigned _octaves, - value_t _H, - value_t _frequency, - value_t _lacunarity, - value_t _amplitude, - value_t _gain, - value_t _offset): - base (_seed, - _octaves, - _H, - _frequency, - _lacunarity, - _amplitude, - _gain), - m_offset (_offset) - { ; } - - - //------------------------------------------------------------------------- - template - hmf::hmf (seed_t _seed): - hmf (_seed, - DEFAULT_OCTAVES, - DEFAULT_H, - DEFAULT_FREQUENCY, - DEFAULT_LACUNARITY, - DEFAULT_AMPLITUDE, - DEFAULT_GAIN, - DEFAULT_OFFSET) - { ; } - - - /////////////////////////////////////////////////////////////////////////// - template - typename hmf::value_t - hmf::operator() (point_t p) const - { - value_t scale = this->m_invAH; - - value_t result = 0; - value_t signal = 0; - value_t weight = 1; - - p *= this->m_frequency; - - for (size_t i = 0; i < this->m_octaves; ++i) { - signal = (this->m_basis (p) + m_offset) * scale; - result += signal * weight; - - weight *= signal; - weight = min (weight, value_t{1}); - - scale *= this->m_invGH; - p += PI; - p *= this->m_lacunarity; - } - - return result; - } -} } } diff --git a/noise/fractal/rmf.hpp b/noise/fractal/rmf.hpp deleted file mode 100644 index 6c06d526..00000000 --- a/noise/fractal/rmf.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_FRACTAL_RMF_HPP -#define __UTIL_NOISE_FRACTAL_RMF_HPP - -#include - -#include "base.hpp" -#include "../../point.hpp" - -namespace util { namespace noise { namespace fractal { - /// Rigid Multifractal summation, based on Musgrave's algorithm - /// - /// octaves: count of layers to be summed - /// H: hurst parameter (~roughness) - /// offset: TODO - /// frequency: point scaling factor for the base octave - /// lacunarity: incremental octave frequency scaling factor - /// amplitude: value scaling factor for the base octave - /// gain: incremental octave value scaling factor - template - struct rmf : public base { - using value_t = typename base::value_t; - using point_t = typename base::point_t; - - static constexpr unsigned DEFAULT_OCTAVES = 5; - static constexpr value_t DEFAULT_H = 1; - static constexpr value_t DEFAULT_OFFSET = 1; - static constexpr value_t DEFAULT_FREQUENCY = 1; - static constexpr value_t DEFAULT_LACUNARITY = 2; - static constexpr value_t DEFAULT_AMPLITUDE = 2; - static constexpr value_t DEFAULT_GAIN = 1 / DEFAULT_LACUNARITY; - - rmf (seed_t, - unsigned octaves, - value_t H, - value_t frequency, - value_t lacunarity, - value_t amplitude, - value_t gain, - value_t offset); - - explicit rmf (seed_t = 0); - - value_t operator() (point_t) const; - - value_t offset (void) const; - value_t offset (value_t); - - private: - value_t m_offset; - }; -} } } - -#include "rmf.ipp" - -#endif diff --git a/noise/fractal/rmf.ipp b/noise/fractal/rmf.ipp deleted file mode 100644 index 8e78d643..00000000 --- a/noise/fractal/rmf.ipp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_FRACTAL_RMF_IPP -#error -#endif -#define __UTIL_NOISE_FRACTAL_RMF_IPP - - -namespace util { namespace noise { namespace fractal { - /////////////////////////////////////////////////////////////////////////// - template - rmf::rmf (seed_t _seed, - unsigned _octaves, - value_t _H, - value_t _offset, - value_t _frequency, - value_t _lacunarity, - value_t _amplitude, - value_t _gain): - base (_seed, - _octaves, - _H, - _frequency, - _lacunarity, - _amplitude, - _gain), - m_offset (_offset) - { ; } - - - //------------------------------------------------------------------------- - template - rmf::rmf (seed_t _seed): - rmf (_seed, - DEFAULT_OCTAVES, - DEFAULT_H, - DEFAULT_FREQUENCY, - DEFAULT_LACUNARITY, - DEFAULT_AMPLITUDE, - DEFAULT_GAIN, - DEFAULT_OFFSET) - { ; } - - - /////////////////////////////////////////////////////////////////////////// - // we use the name 'amplitude' instead of musgrave's 'gain'. - // assumes basis distribution [-1,1] and offset ~= 1 - template - typename rmf::value_t - rmf::operator() (point_t p) const - { - value_t scale = this->m_invAH; - - value_t signal = 0; - value_t result = 0; - value_t weight = 1; - - p *= this->m_frequency; - - for (size_t i = 0; i < this->m_octaves; ++i) { - // generates ridged noise - signal = this->m_basis (p); - signal = std::fabs (signal); - signal = m_offset - signal; - - // sharpens the ridges - signal *= signal; - - // influence by sharpness of previous iteration - signal *= weight; - - // contribute to the weight - weight = signal * this->m_amplitude; - weight = limit (weight, 0, 1); - - // record and continue - result += signal * scale; - - scale *= this->m_invGH; - - p += PI; - p *= this->m_lacunarity; - } - - return result; - } - - - /////////////////////////////////////////////////////////////////////////// - template - typename rmf::value_t - rmf::offset (void) const - { - return m_offset; - } - - - //------------------------------------------------------------------------- - template - typename rmf::value_t - rmf::offset (value_t _offset) - { - return m_offset = _offset; - } -} } } diff --git a/noise/fractal/runtime.cpp b/noise/fractal/runtime.cpp deleted file mode 100644 index 75ac1f33..00000000 --- a/noise/fractal/runtime.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#include "runtime.hpp" -#include "../basis/runtime.hpp" - -template struct util::noise::fractal::runtime< - util::noise::basis::runtime<2,float> ->; diff --git a/noise/fractal/runtime.hpp b/noise/fractal/runtime.hpp deleted file mode 100644 index 7d729c71..00000000 --- a/noise/fractal/runtime.hpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - - -#ifndef __UTIL_NOISE_FRACTAL_RUNTIME_HPP -#define __UTIL_NOISE_FRACTAL_RUNTIME_HPP - -#include "base.hpp" - -#include - -namespace util { namespace noise { namespace fractal { - template - struct runtime { - public: - using value_t = typename B::value_t; - using point_t = typename B::point_t; - - runtime (seed_t) { } - runtime () = default; - runtime (runtime&&) = default; - runtime (const runtime&) = delete; - runtime& operator= (const runtime&) = delete; - - // basis functions - value_t operator () (point_t p) const noexcept { return (*m_child) (p); } - - unsigned octaves (void) const { return m_child->octaves (); } - unsigned octaves (unsigned _octaves) { return m_child->octaves (_octaves); } - - value_t H (void) const { return m_child->H (); } - value_t H (value_t _H) { return m_child->H (_H); } - - value_t frequency (void) const { return m_child->frequency (); } - value_t frequency (value_t _frequency) { return m_child->frequency (_frequency); } - - value_t lacunarity (void) const { return m_child->lacunarity (); } - value_t lacunarity (value_t _lacunarity) { return m_child->lacunarity (_lacunarity); } - - value_t amplitude (void) const { return m_child->amplitude (); } - value_t amplitude (value_t _amplitude) { return m_child->amplitude (_amplitude); } - - value_t gain (void) const { return m_child->gain (); } - value_t gain (value_t _gain) { return m_child->gain (_gain); } - - B& basis (void) { return m_child->basis (); } - const B& basis (void) const { return m_child->basis (); } - - seed_t seed (void) const { return m_child->seed (); } - seed_t seed (seed_t) { return m_child->seed (); } - - private: - struct base { - virtual ~base () = default; - - virtual value_t operator() (point_t) const noexcept = 0; - - virtual unsigned octaves (void) const = 0; - virtual unsigned octaves (unsigned) = 0; - - virtual value_t H (void) const = 0; - virtual value_t H (value_t) = 0; - - virtual value_t frequency (void) const = 0; - virtual value_t frequency (value_t) = 0; - - virtual value_t lacunarity (void) const = 0; - virtual value_t lacunarity (value_t) = 0; - - virtual value_t amplitude (void) const = 0; - virtual value_t amplitude (value_t) = 0; - - virtual value_t gain (void) const = 0; - virtual value_t gain (value_t) = 0; - - virtual B& basis (void) = 0; - virtual const B& basis (void) const = 0; - - virtual seed_t seed (void) const = 0; - virtual seed_t seed (seed_t) = 0; - }; - - template - struct child final : public base { - child (seed_t _seed): - data (_seed) - { ; } - - child (seed_t _seed, - unsigned _octaves, - value_t _H, - value_t _frequency, - value_t _lacunarity, - value_t _amplitude, - value_t _gain): - data (_seed, - _octaves, - _H, - _frequency, - _lacunarity, - _amplitude, - _gain) - { ; } - - value_t operator() (point_t p) const noexcept override { return data (p); } - - unsigned octaves (void) const override { return data.octaves (); } - unsigned octaves (unsigned _octaves) override { return data.octaves (_octaves); } - - value_t H (void) const override { return data.H (); } - value_t H (value_t _H) override { return data.H (_H); } - - value_t frequency (void) const override { return data.frequency (); } - value_t frequency (value_t _frequency) override { return data.frequency (_frequency); } - - value_t lacunarity (void) const override { return data.lacunarity (); } - value_t lacunarity (value_t _lacunarity) override { return data.lacunarity (_lacunarity); } - - value_t amplitude (void) const override { return data.amplitude (); } - value_t amplitude (value_t _amplitude) override { return data.amplitude (_amplitude); } - - value_t gain (void) const override { return data.gain (); } - value_t gain (value_t _gain) override { return data.gain (_gain); } - - B& basis (void) override { return data.basis (); } - const B& basis (void) const override { return data.basis (); } - - seed_t seed (void) const override { return data.seed (); } - seed_t seed (seed_t _seed) override { return data.seed (_seed); } - - F data; - }; - - std::unique_ptr m_child; - - public: - template - F& - reset (seed_t _seed) - { - using fractal_t = F; - using child_t = child; - - child_t *out; - m_child.reset (out= new child_t (_seed)); - return out->data; - } - }; -} } } - -#endif diff --git a/noise/fwd.hpp b/noise/fwd.hpp deleted file mode 100644 index 67f18c9b..00000000 --- a/noise/fwd.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_FWD_HPP -#define __UTIL_NOISE_FWD_HPP - -#include - -namespace util { namespace noise { - template using lerp_t = T (*)(T,T,T); - typedef uint64_t seed_t; -} } - -#endif diff --git a/noise/lerp.cpp b/noise/lerp.cpp deleted file mode 100644 index d549b54a..00000000 --- a/noise/lerp.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2011-2015 Danny Robson - */ - -#include "lerp.hpp" - -#include "debug.hpp" -#include "maths.hpp" - -#include - -using util::lerp::linear; -using util::lerp::cosine; -using util::lerp::cubic; -using util::lerp::quintic; - - -//----------------------------------------------------------------------------- -template -T -util::lerp::truncate::operator() (T a, T, T weight) noexcept -{ - static_assert (std::is_floating_point::value, - "lerp is only defined for floating types"); - - CHECK_LIMIT (weight, 0, 1); - (void)weight; - - return a; -} - -template struct util::lerp::truncate; -template struct util::lerp::truncate; - - -//----------------------------------------------------------------------------- -template -T -linear::operator() (T a, T b, T weight) noexcept -{ - static_assert (std::is_floating_point::value, - "lerp is only defined for floating types"); - CHECK_LIMIT (weight, 0, 1); - - return a * (1 - weight) + b * weight; -} - -template struct util::lerp::linear; -template struct util::lerp::linear; - - -//----------------------------------------------------------------------------- -template -T -cosine::operator() (T a, T b, T weight) noexcept -{ - static_assert (std::is_floating_point::value, - "lerp is only defined for floating types"); - CHECK_LIMIT (weight, 0, 1); - - T t = (1 - std::cos (weight * PI)) * T(0.5); - return a * (1 - t) + b * t; -} - -template struct util::lerp::cosine; -template struct util::lerp::cosine; - - -//----------------------------------------------------------------------------- -template -T -cubic::operator() (T a, T b, T weight) noexcept -{ - static_assert (std::is_floating_point::value, - "lerp is only defined for floating types"); - CHECK_LIMIT (weight, 0, 1); - - // -2w^3 * 3w^2 - T t = weight * weight * (3 - 2 * weight); - return a * (1 - t) + b * t; -} - -template struct util::lerp::cubic; -template struct util::lerp::cubic; - - -//----------------------------------------------------------------------------- -template -T -quintic::operator() (T a, T b, T weight) noexcept -{ - static_assert (std::is_floating_point::value, - "lerp is only defined for floating types"); - CHECK_LIMIT (weight, 0, 1); - - // from perlin's improved noise: 6w^5 -15w^4 +10w^3 - T t = weight * weight * weight * (weight * (weight * 6 - 15) + 10); - return a * (1 - t) + b * t; -} - -template struct util::lerp::quintic; -template struct util::lerp::quintic; diff --git a/noise/lerp.hpp b/noise/lerp.hpp deleted file mode 100644 index be7d11de..00000000 --- a/noise/lerp.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2011-2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_LERP_HPP -#define __UTIL_NOISE_LERP_HPP - -namespace util { namespace lerp { - template struct linear { T operator() (T, T, T weight) noexcept; }; - template struct cosine { T operator() (T, T, T weight) noexcept; }; - template struct cubic { T operator() (T, T, T weight) noexcept; }; - template struct quintic { T operator() (T, T, T weight) noexcept; }; - template struct truncate { T operator() (T, T, T weight) noexcept; }; -} } - -#endif diff --git a/noise/lut.cpp b/noise/lut.cpp deleted file mode 100644 index 88bc5351..00000000 --- a/noise/lut.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012 Danny Robson - */ - -#include "lut.hpp" - -const size_t util::noise::PERM[256] = { - 114, 247, 195, 115, 164, 64, 53, 51, - 82, 75, 244, 19, 255, 1, 43, 77, - 126, 141, 77, 23, 169, 7, 29, 72, - 92, 97, 69, 211, 218, 71, 47, 25, - 178, 10, 135, 139, 152, 38, 51, 90, - 206, 98, 130, 32, 192, 6, 2, 34, - 74, 50, 162, 111, 188, 7, 24, 27, - 22, 87, 49, 67, 202, 35, 22, 79, - 253, 197, 73, 94, 182, 39, 37, 51, - 121, 85, 17, 18, 109, 63, 48, 66, - 173, 245, 183, 201, 68, 21, 81, 70, - 200, 0, 191, 86, 52, 80, 29, 76, - 15, 180, 41, 58, 128, 2, 38, 33, - 132, 119, 60, 242, 6, 46, 7, 99, - 237, 108, 30, 93, 153, 12, 43, 16, - 163, 209, 219, 117, 83, 13, 26, 14, - 55, 159, 190, 81, 224, 78, 8, 76, - 118, 203, 8, 193, 248, 84, 13, 48, - 240, 38, 65, 227, 160, 9, 36, 36, - 122, 185, 33, 123, 158, 56, 47, 88, - 246, 215, 231, 131, 5, 24, 4, 25, - 230, 174, 189, 168, 241, 56, 31, 20, - 166, 186, 184, 155, 29, 42, 25, 0, - 35, 105, 221, 39, 216, 96, 28, 23, - 28, 61, 196, 101, 149, 13, 65, 16, - 175, 194, 44, 34, 187, 95, 99, 20, - 45, 112, 252, 11, 59, 26, 12, 17, - 171, 14, 70, 54, 142, 4, 67, 46, - 4, 127, 20, 133, 205, 54, 43, 3, - 110, 249, 172, 161, 140, 57, 40, 89, - 3, 150, 210, 232, 57, 45, 44, 54, - 91, 79, 250, 62, 37, 98, 36, 34, -}; - - -const double util::noise::LUT[256] = { - -0.8984982139196056, 0.4750710231804418, -0.6519676730721629, 0.34818237268881935, - -0.18205970986171605, 0.3451314956848195, 0.6414228668402755, -0.804052019344714, - 0.6838765435328942, 0.04489123586160382, 0.9387123107757223, -0.8286734231526627, - -0.5752448478162355, -0.7177473684716851, 0.9935836223400552, 0.7280624253259176, - 0.17859563727209138, -0.03606344150253982, -0.15882231678491388, 0.4578698195539206, - -0.4154225972126202, -0.5194028373429245, 0.24561279025507043, -0.8817931383760225, - 0.051621615744299465, -0.432105334458762, 0.1565615530978024, 0.6597775199873575, - 0.22566777177285857, -0.30483300012361036, -0.6958206141316641, -0.2930693331180243, - -0.7690503602769119, -0.7171818210252867, 0.8800261811087657, 0.8601395971416754, - 0.5784335763333026, 0.060900655607116994, 0.2837112260220951, -0.08799217109739876, - -0.2384174709999518, -0.770742115936714, 0.9217986500940929, 0.33319037162928433, - 0.2338527159073147, 0.9326260912305022, -0.3277100775267676, -0.6923414380512052, - 0.2743829582530313, 0.021903777340825714, -0.99594589251304, 0.08310122202568193, - 0.031989194381878194, 0.322274671882117, 0.15855440115773267, 0.7221472232498565, - -0.5369740081438523, -0.013966337693399833, -0.3797229432191469, -0.1449216443374528, - 0.4780175549902941, 0.3253792901693007, 0.8302471035699828, -0.19705446486920075, - -0.05145564508096312, 0.07804387053425987, -0.43766576462644347, -0.6841198355261591, - 0.7137706240638149, -0.05484055085953887, -0.8299960004843008, 0.18050577055894035, - -0.8541390034524383, -0.26341201926055424, 0.7023808019022437, 0.6230332593788754, - -0.2959807962046559, 0.8971411582261257, -0.37285148660593714, -0.9689413803647513, - 0.36271555405510414, -0.2369795401687047, -0.057686227499222476, 0.45924926449705117, - 0.5909634897508582, -0.8641968475739907, -0.9868274716835026, 0.15367421531182823, - 0.47868338795465704, 0.22205133716275216, 0.9342712841005696, 0.574755268557622, - -0.30781440722062237, 0.08940264916288165, -0.7364035085406784, -0.42804724032315544, - -0.3028896080136707, 0.08043452763728154, 0.35597931924492854, 0.8218045295996388, - -0.2639539020450863, 0.14018881766976743, -0.9679978866175825, 0.917534812674309, - 0.8315532029453319, -0.26657576198722377, 0.5292911314793278, 0.05106195480414244, - -0.20703582048726044, 0.9363562930545231, 0.07180492189859389, -0.9307494388376307, - 0.48401747690392316, -0.47666025737165385, -0.2995451643535043, 0.9645238474628381, - -0.9869506025182451, -0.6267193760632264, 0.9417871950627361, -0.3712682888227079, - 0.17116236816682484, 0.1637861802304843, 0.5979849303287379, -0.7943555560703199, - -0.8605593297161265, 0.24271029593235993, 0.8838806440116482, 0.6563769551024692, - 0.9357703879808301, -0.76818344297623, 0.7661179391954425, 0.426530438580041, - -0.7280736750184795, 0.5258880971264928, -0.3736324615581794, -0.3726200928816683, - -0.652698944621871, 0.1312826210242899, 0.022999070967927526, 0.8362192026388207, - -0.20524579974666657, -0.39989736807434273, 0.097666397673847, 0.25215779272486416, - -0.6800982672863105, 0.8013507802109068, 0.969941009294419, -0.2760313084806676, - 0.8961286070268608, 0.9455740223217473, -0.3908254141167051, 0.8195441725353367, - -0.571435969794009, 0.18987091511038434, -0.04181589713692069, -0.963609489444007, - -0.5281459088656999, 0.984266295584705, 0.5027560371807003, -0.1597738785923013, - 0.3411131481434917, 0.12429799530598684, -0.5159001480993852, 0.8865722840594523, - 0.32969200413777755, 0.26288894768315707, -0.054978081511632526, -0.37725903459638177, - 0.18451775548204163, -0.6691455193869638, 0.9285268978526233, -0.49526622636914563, - -0.12647685137552322, -0.08438978664878105, -0.4263493078967011, 0.04134592579064478, - 0.5682513712371484, 0.3144579798890128, -0.5560826395168046, -0.7651643315076799, - -0.4919051361482554, 0.4326849315222068, 0.9745607803884215, 0.5459754840343867, - -0.3314574932052319, 0.10102331343981996, -0.8762141515646111, -0.8182536989519216, - 0.5460251598764976, 0.11958795888450968, -0.7226482729866581, -0.5362654501182944, - 0.9461689136255056, 0.7302075935427872, 0.2067222384707743, -0.5515294144965857, - 0.5261119777013636, -0.6058524684579083, -0.7984088236296627, 0.5515069318003252, - 0.6842126925238694, 0.9653367596972298, -0.4209547631571078, -0.200564767100335, - -0.45471383032946067, -0.5407480745656619, 0.7853038244196648, 0.08741550867662506, - 0.46188948442462063, 0.32857850460858384, 0.2519455394025394, -0.5647397901411311, - -0.8010538532270075, 0.03511555124942123, 0.8126644809142252, -0.6165437893290324, - -0.769144309230668, 0.5811756737759881, 0.04347549540355833, -0.1516485473331033, - -0.8025604153817143, 0.2078203269944925, -0.8281743083984969, -0.5483796887270644, - -0.67075976237068, 0.08046291156170216, -0.726116057042915, 0.6064692851498683, - -0.2326853771750068, -0.1199137086641211, -0.007902895438233637, -0.024018850623878762, - 0.23518281506286076, 0.8739589142046267, 0.9461972684232018, -0.6298769685383707, - -0.37298229425868623, -0.0443367550367304, -0.9688376819157003, 0.09999263734937558, - -0.3975824040014859, 0.3353645267506893, -0.2693845909559329, -0.1133673242389015, - -0.8453467042866694, 0.5313565920953589, -0.5313028936659494, 0.23266080060836347, - 0.19579971665018436, 0.9392643282850877, 0.08508300565389537, -0.43964224026992116, - 0.5862798492854766, 0.7001806971895554, 0.9050597336377173, -0.5789943930802939, -}; diff --git a/noise/lut.hpp b/noise/lut.hpp deleted file mode 100644 index e7e751c0..00000000 --- a/noise/lut.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012 Danny Robson - */ - -#ifndef __UTIL_NOISE_LUT_HPP -#define __UTIL_NOISE_LUT_HPP - -#include -#include - -#include "types.hpp" - -namespace util { - namespace noise { - extern const size_t PERM[256]; - extern const double LUT [256]; - - template - typename std::enable_if::value, size_t>::type - permute (T idx) { - return PERM[(size_t)idx % elems (PERM)]; - } - - template - size_t permute (T1 t1, T2 t2, R ...r) { - auto p = permute (t1); - p += permute (t2, r...); - return p % elems (PERM); - } - } -} - -#endif diff --git a/noise/midpoint.cpp b/noise/midpoint.cpp deleted file mode 100644 index b3673e42..00000000 --- a/noise/midpoint.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - -#include "midpoint.hpp" - -#include "region.hpp" -#include "point.hpp" -#include "rand.hpp" - - -/////////////////////////////////////////////////////////////////////////////// -// assumes corner points have been assigned their weights -template -static void -fill (util::image::buffer<1,T> &img, - uint64_t seed, - util::region2u target, - float scale, - float persistence, - float sides) -{ - CHECK_EQ (target.e.w % 2, 1u); - CHECK_EQ (target.e.h % 2, 1u); - CHECK_GE (target.area (), 9u); - - CHECK_GT (scale, 0); - CHECK_GT (persistence, 0); - CHECK_GE (sides, 0); - - const auto w = target.w; - const auto h = target.h; - - // 0--1 - // | | - // 2--3 - - const auto p0 = target.p + util::vector2u {0, 0 }; - const auto p1 = target.p + util::vector2u {w-1, 0 }; - const auto p2 = target.p + util::vector2u {0, h-1}; - const auto p3 = target.p + util::vector2u {w-1, h-1}; - - const auto v0 = img[p0]; - const auto v1 = img[p1]; - const auto v2 = img[p2]; - const auto v3 = img[p3]; - - // do the centre - { - const auto avg = (v0 + v1 + v2 + v3) / 4; - const auto val = avg + scale * util::noise::rand::scalar (seed, target.centre ()); - const auto pos = target.p + target.e / 2; - - img[pos] = val * 2 - 1; - } - - // average the sides - { - const auto p01 = target.p + util::vector2u{w/2, 0}; - const auto p13 = target.p + util::vector2u{w-1, h/2}; - const auto p32 = target.p + util::vector2u{w/2, h-1}; - const auto p20 = target.p + util::vector2u{0, h/2}; - - const auto v01 = (v0 + v1) / 2 + sides * scale * util::noise::rand::scalar (seed, p01); - const auto v13 = (v1 + v3) / 2 + sides * scale * util::noise::rand::scalar (seed, p13); - const auto v32 = (v3 + v2) / 2 + sides * scale * util::noise::rand::scalar (seed, p32); - const auto v20 = (v2 + v0) / 2 + sides * scale * util::noise::rand::scalar (seed, p20); - - img[p01] = v01 * 2 - 1; - img[p13] = v13 * 2 - 1; - img[p32] = v32 * 2 - 1; - img[p20] = v20 * 2 - 1; - } - - // recurse - if (target.area () > 9) { - auto e = target.e / 2 + 1; - - fill (img, seed, {target.p + util::vector2u{ 0, 0 }, e}, scale * persistence, persistence, sides); - fill (img, seed, {target.p + util::vector2u{ w/2, 0 }, e}, scale * persistence, persistence, sides); - fill (img, seed, {target.p + util::vector2u{ 0, h/2 }, e}, scale * persistence, persistence, sides); - fill (img, seed, {target.p + util::vector2u{ w/2, h/2 }, e}, scale * persistence, persistence, sides); - } -} - - -/////////////////////////////////////////////////////////////////////////////// -template -void -util::noise::midpoint (image::buffer<1,T> &img, uint64_t seed, float persistence, float sides) -{ - auto ext = img.extent (); - - static const util::point2u CORNERS[] = { - { 0, 0 }, - { 0, ext.w - 1 }, - { ext.h - 1, 0 }, - { ext.h - 1, ext.w - 1 } - }; - - for (auto i: CORNERS) - img[i] = util::noise::rand::scalar (seed, i) * 2 - 1; - - fill (img, seed, { { 0, 0 }, img.extent () }, 1.f, persistence, sides); -} - - -//----------------------------------------------------------------------------- -template void util::noise::midpoint (image::buffer<1,float>&, uint64_t, float, float); diff --git a/noise/midpoint.hpp b/noise/midpoint.hpp deleted file mode 100644 index 36977c72..00000000 --- a/noise/midpoint.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_MIDPOINT_HPP -#define __UTIL_NOISE_MIDPOINT_HPP - -#include "../image/buffer.hpp" - -namespace util { namespace noise { - template - void - midpoint (image::buffer<1,T>&, uint64_t seed, float persistence = 0.65f, float sides = 0.25f); -} } - -#endif diff --git a/noise/rand.hpp b/noise/rand.hpp deleted file mode 100644 index d7c6462a..00000000 --- a/noise/rand.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_RAND_HPP -#define __UTIL_NOISE_RAND_HPP - -#include "./rand/permute.hpp" -#include "./rand/hash.hpp" - -#include - -namespace util { namespace noise { - using seed_t = uint64_t; -} } - -namespace util { namespace noise { namespace rand { - /// generate a uniform random floating point in the range [0, 1] from a seed and vector - template < - typename U, - size_t S, - typename T, - template class Q - > - U - scalar (uint64_t seed, Q value) noexcept - { - #if 1 - return permute::scalar (seed, value); - #else - return hash::scalar (seed, value); - #endif - } - - /// generate a coordinate type with uniform random components in the range [0, 1] - template < - template class R, - typename U, - size_t S, - typename T, - template class Q - > - R - coord (uint64_t seed, Q value) noexcept - { - #if 1 - return permute::coord (seed, value); - #else - return hash::coord (seed, value); - #endif - } -} } } - -#endif diff --git a/noise/rand/hash.hpp b/noise/rand/hash.hpp deleted file mode 100644 index 03f9cf70..00000000 --- a/noise/rand/hash.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - - -#ifndef __UTIL_NOISE_RAND_HASH_HPP -#define __UTIL_NOISE_RAND_HASH_HPP - -/////////////////////////////////////////////////////////////////////////////// -namespace util { namespace noise { namespace rand { - struct hash { - /// generate a uniform random floating point in the range [0, 1] from a seed and vector - template < - typename U, - size_t S, - typename T, - template class Q - > - static U - scalar (uint64_t seed, Q value) noexcept; - - /// generate a coordinate type with uniform random components in the range [0, 1] - template < - template class R, - typename U, - size_t S, - typename T, - template class Q - > - static R - coord (uint64_t seed, Q value) noexcept; - }; -} } } - -#include "./hash.hpp" - -#endif diff --git a/noise/rand/hash.ipp b/noise/rand/hash.ipp deleted file mode 100644 index 853ad8ac..00000000 --- a/noise/rand/hash.ipp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - - -#ifdef __UTIL_NOISE_RAND_HASH_IPP -#error -#endif - -#define __UTIL_NOISE_RAND_HASH_IPP - -namespace util { namespace noise { namespace rand { - //------------------------------------------------------------------------- - template < - typename U, - size_t S, - typename T, - template class Q - > - U - hash::scalar (uint64_t seed, Q query) noexcept - { - constexpr decltype(seed) BITS = 0xFFFF; - static_assert (std::is_integral::value, - "mixing only works on integral types"); - - uint64_t accum = seed; - for (auto i: query) - accum = util::hash::murmur2::mix (accum, i); - - return (accum & BITS) / U{BITS}; - } - - - //------------------------------------------------------------------------- - template < - template class R, - typename U, - size_t S, - typename T, - template class Q - > - R - hash::coord (uint64_t seed, Q query) noexcept - { - constexpr decltype(seed) PERTURB = 0x96c39996c36c36c3; - constexpr decltype(seed) BITS = 0xFFFF; - - auto accum = seed ^ PERTURB; - for (auto i: query) - accum = util::hash::murmur2::mix (accum, i); - - R result; - for (auto &i: result) { - i = (accum & BITS); - i /= BITS; - accum = util::hash::murmur2::mix (accum, seed); - } - - return result; - } -} } } diff --git a/noise/rand/permute.cpp b/noise/rand/permute.cpp deleted file mode 100644 index d7f89480..00000000 --- a/noise/rand/permute.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "./permute.hpp" - - -using util::noise::rand::permute; - -// static permutation offsets. consists of numbers [0,255] in a randomised -// pattern. the exact arrangement is irrelevant. -const std::array permute::PERMUTE = { - 148, 94, 173, 74, 199, 189, 102, 184, 149, 18, 177, 211, 16, 221, 252, 232, - 82, 104, 164, 196, 78, 4, 247, 11, 206, 176, 137, 45, 30, 118, 72, 59, - 39, 198, 158, 220, 213, 230, 197, 209, 145, 172, 188, 10, 214, 144, 241, 242, - 84, 128, 168, 229, 64, 32, 20, 249, 236, 194, 253, 183, 132, 6, 43, 96, - 181, 27, 127, 106, 63, 21, 134, 120, 170, 166, 93, 191, 70, 240, 46, 85, - 23, 56, 228, 28, 160, 67, 175, 161, 36, 61, 204, 71, 140, 103, 190, 66, - 100, 130, 192, 251, 174, 201, 79, 169, 231, 53, 48, 50, 119, 178, 87, 205, - 243, 165, 207, 13, 116, 235, 24, 224, 47, 81, 195, 218, 97, 83, 238, 227, - 113, 180, 33, 111, 126, 200, 153, 5, 146, 112, 179, 255, 250, 19, 92, 80, - 135, 222, 95, 22, 142, 40, 15, 107, 217, 41, 77, 110, 210, 246, 185, 54, - 163, 105, 114, 193, 215, 73, 150, 129, 208, 155, 171, 154, 115, 0, 8, 233, - 162, 138, 109, 157, 248, 26, 25, 244, 31, 62, 75, 35, 29, 60, 182, 156, - 55, 223, 125, 51, 76, 88, 9, 151, 117, 122, 38, 159, 124, 49, 44, 254, - 202, 147, 225, 219, 90, 234, 133, 212, 14, 7, 167, 2, 91, 68, 187, 216, - 65, 42, 69, 245, 123, 152, 89, 52, 37, 121, 143, 1, 57, 226, 3, 239, - 99, 98, 108, 186, 17, 139, 203, 58, 86, 131, 141, 136, 34, 101, 12, 237 -}; diff --git a/noise/rand/permute.hpp b/noise/rand/permute.hpp deleted file mode 100644 index 672a17c0..00000000 --- a/noise/rand/permute.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - - -#ifndef __UTIL_NOISE_RAND_PERMUTE_HPP -#define __UTIL_NOISE_RAND_PERMUTE_HPP - -#include - -/////////////////////////////////////////////////////////////////////////////// -namespace util { namespace noise { namespace rand { - struct permute { - /// generate a uniform random floating point in the range [0, 1] from a seed and vector - template < - typename U, - size_t S, - typename T, - template class Q - > - static U - scalar (uint64_t seed, Q value) noexcept; - - /// generate a coordinate type with uniform random components in the range [0, 1] - template < - template class R, - typename U, - size_t S, - typename T, - template class Q - > - static R - coord (uint64_t seed, Q value) noexcept; - - private: - static const std::array PERMUTE; - }; -} } } - -#include "./permute.ipp" - -#endif - diff --git a/noise/rand/permute.ipp b/noise/rand/permute.ipp deleted file mode 100644 index a8e9b84f..00000000 --- a/noise/rand/permute.ipp +++ /dev/null @@ -1,47 +0,0 @@ - -/////////////////////////////////////////////////////////////////////////////// -namespace util { namespace noise { namespace rand { - template < - typename U, - size_t S, - typename T, - template class Q - > - U - permute::scalar (uint64_t seed, Q query) noexcept - { - - size_t idx = PERMUTE[seed&0xff]; - for (auto i: query) - idx = PERMUTE[(idx+i)&0xff]; - return PERMUTE[idx] / U(0xff); - } - - //------------------------------------------------------------------------- - template < - template class R, - typename U, - size_t S, - typename T, - template class Q - > - R - permute::coord (uint64_t seed, Q query) noexcept - { - auto accum = seed; - for (auto q: query) { - size_t idx = q + accum; - accum = PERMUTE[idx & 0xff]; - } - - R res; - for (size_t i = 0; i < S; ++i) { - res[i] = PERMUTE[accum]; - res[i] /= 0xff; - - accum = PERMUTE[(accum + i) & 0xff]; - } - - return res; - } -} } } diff --git a/noise/turbulence.hpp b/noise/turbulence.hpp deleted file mode 100644 index 70e56dc1..00000000 --- a/noise/turbulence.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifndef __UTIL_NOISE_TURBULENCE_HPP -#define __UTIL_NOISE_TURBULENCE_HPP - -#include "../point.hpp" -#include "../vector.hpp" - -#include - -namespace util { namespace noise { - /// perturb the evaluation point of a noise function by the results of - /// a per-dimension noise function - /// - /// assumes the pertubation function is roughly symetrical around 0. - /// nothing will explode if it isn't, but you'll see strong directional - /// artefacts with higher scaling factors. - template < - typename D, // data fractal - typename P // pertubation fractal - > - struct turbulence { - using value_t = typename D::value_t; - using point_t = typename D::point_t; - using scale_t = vector; - - static constexpr size_t S = D::point_t::dimension; - - static_assert (std::is_same::value, - "data and perturbation value types must match"); - static_assert (std::is_same::value, - "data and perturbation point types must match"); - - turbulence (seed_t, scale_t); - - seed_t seed (seed_t); - seed_t seed (void) const; - - constexpr value_t operator() (point_t) const; - - D data; - - // XXX: use a union to defer initialization of pertubation fractals in - // the constructor. i know this is horrible, but there's no time to - // write the proper generator constructor to pass out the seeds. - P perturb[S]; - - scale_t scale; - }; -} } - -#include "turbulence.ipp" - -#endif diff --git a/noise/turbulence.ipp b/noise/turbulence.ipp deleted file mode 100644 index 89d73768..00000000 --- a/noise/turbulence.ipp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2012-2015 Danny Robson - */ - -#ifdef __UTIL_NOISE_TURBULENCE_IPP -#error -#endif -#define __UTIL_NOISE_TURBULENCE_IPP - -#include "../hash/wang.hpp" - - -namespace util { namespace noise { - /////////////////////////////////////////////////////////////////////////// - template - turbulence::turbulence (seed_t _seed, - scale_t _scale): - data (_seed), - scale (_scale) - { - for (auto &p: perturb) - p.seed (_seed = hash::wang (_seed)); - } - - //////////////////////////////////////////////////////////////////////////// - template - seed_t - turbulence::seed (void) const - { - return data.seed (); - } - - - //------------------------------------------------------------------------- - template - seed_t - turbulence::seed (seed_t _seed) - { - auto ret = _seed; - data.seed (_seed); - - for (size_t i = 0; i < S; ++i) - perturb[i].seed (_seed = hash::wang (_seed)); - - return ret; - } - - - /////////////////////////////////////////////////////////////////////////// - template - constexpr typename turbulence::value_t - turbulence::operator() (point_t p) const - { - scale_t n; - for (size_t i = 0; i < S; ++i) - n[i] = perturb[i] (p); - - // scale by the data frequency so that we match scale - return data (p + n * scale / data.frequency ()); - } -} }