/* * 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, vector<2,T> _scale): data (_seed), perturb { hash::wang (_seed), hash::wang (hash::wang (_seed)) }, scale (_scale) { ; } //////////////////////////////////////////////////////////////////////////// template typename turbulence::seed_t turbulence::seed (void) const { return data.seed (); } //------------------------------------------------------------------------- template typename turbulence::seed_t turbulence::seed (seed_t _seed) { auto ret = _seed; data.seed (_seed); _seed = hash::wang (_seed); perturb[0].seed (_seed); _seed = hash::wang (_seed); perturb[1].seed (_seed); _seed = hash::wang (_seed); return ret; } /////////////////////////////////////////////////////////////////////////// template constexpr T turbulence::operator() (point<2,T> p) const { vector<2,T> n = { perturb[0] (p), perturb[1] (p) }; // scale by the data frequency so that we match scale return data (p + n * scale / data.frequency ()); } } }