From 9d98906cb63562348a781bc4dc7cb517e1255141 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Wed, 19 Oct 2022 17:41:25 +0800 Subject: [PATCH] Fix simplex noise documentation --- src/math/noise/fbm.hpp | 8 ++--- src/math/noise/simplex.hpp | 62 +++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/math/noise/fbm.hpp b/src/math/noise/fbm.hpp index 26ffe89..850bbff 100644 --- a/src/math/noise/fbm.hpp +++ b/src/math/noise/fbm.hpp @@ -35,7 +35,7 @@ namespace noise { * @tparam T Real type. * @tparam N Number of dimensions. * - * @param x n-dimensional input value. + * @param position Input position. * @param octaves Number of octaves. * @param lacunarity Frequency multiplier. * @param gain Amplitude multiplier. @@ -46,7 +46,7 @@ namespace noise { template T fbm ( - vector x, + vector position, std::size_t octaves, T lacunarity, T gain, @@ -59,8 +59,8 @@ T fbm while (octaves--) { - value += noise(x, hash) * amplitude; - x *= lacunarity; + value += noise(position, hash) * amplitude; + position *= lacunarity; amplitude *= gain; } diff --git a/src/math/noise/simplex.hpp b/src/math/noise/simplex.hpp index 63a5541..3bb2001 100644 --- a/src/math/noise/simplex.hpp +++ b/src/math/noise/simplex.hpp @@ -29,36 +29,57 @@ namespace math { namespace noise { -/// @private -/// @{ - -/// Number of corners in an *n*-dimensional simplex lattice cell. +/** + * Number of corners in an *n*-dimensional simplex lattice cell. + * + * @private + */ template constexpr std::size_t simplex_corner_count = std::size_t(2) << std::max(0, N - 1); -/// Number of edges in an *n*-dimensional simplex lattice cell. +/** + * Number of edges in an *n*-dimensional simplex lattice cell. + * + * @private + */ template constexpr std::size_t simplex_edge_count = (N > 1) ? N * simplex_corner_count : 2; -/// Returns the simplex lattice cell corner vector for a given dimension and index. +/** + * Returns the simplex lattice cell corner vector for a given dimension and index. + * + * @private + */ template constexpr vector make_simplex_corner(std::size_t i, std::index_sequence) { return {((i >> I) % 2) * T{2} - T{1}...}; } -/// Builds an array of simplex lattice cell corner vectors for a given dimension. +/** + * Builds an array of simplex lattice cell corner vectors for a given dimension. + * + * @private + */ template constexpr std::array, simplex_corner_count> make_simplex_corners(std::index_sequence) { return {make_simplex_corner(I, std::make_index_sequence{})...}; } -/// Array of simplex lattice cell corner vectors for a given dimension. +/** + * Array of simplex lattice cell corner vectors for a given dimension. + * + * @private + */ template constexpr auto simplex_corners = make_simplex_corners(std::make_index_sequence>{}); -/// Returns the simplex lattice cell edge vector for a given dimension and index. +/** + * Returns the simplex lattice cell edge vector for a given dimension and index. + * + * @private + */ template constexpr vector make_simplex_edge(std::size_t i, std::index_sequence) { @@ -77,7 +98,11 @@ constexpr vector make_simplex_edge(std::size_t i, std::index_sequence constexpr std::array, simplex_edge_count> make_simplex_edges(std::index_sequence) { @@ -87,20 +112,21 @@ constexpr std::array, simplex_edge_count> make_simplex_edges(std return {make_simplex_edge(I, std::make_index_sequence{})...}; } -/// Array of simplex lattice cell edge vectors for a given dimension. +/** + * Array of simplex lattice cell edge vectors for a given dimension. + * + * @private + */ template constexpr auto simplex_edges = make_simplex_edges(std::make_index_sequence>{}); -/// @} - /** * *n*-dimensional simplex noise. * * @tparam T Real type. * @tparam N Number of dimensions. - * @tparam U Hash function return type. * - * @param x Input vector. + * @param position Input position. * @param hash Hash function. * * @return Noise value, on `[-1, 1]`. @@ -114,7 +140,7 @@ constexpr auto simplex_edges = make_simplex_edges(std::make_index_sequence template T simplex ( - const vector& x, + const vector& position, vector, N> (*hash)(const vector&) = &hash::pcg ) { @@ -146,10 +172,10 @@ T simplex static const T edge_normalization = corner_normalization * (std::sqrt(static_cast(N)) / length(simplex_edges[0])); // Skew input position to get the origin vertex of the unit hypercube cell to which they belong - const vector origin_vertex = floor(x + sum(x) * f); + const vector origin_vertex = floor(position + sum(position) * f); // Displacement vector from origin vertex position to input position - const vector dx = x - origin_vertex + sum(origin_vertex) * g; + const vector dx = position - origin_vertex + sum(origin_vertex) * g; // Find axis traversal order vector axis_order;