#pragma once #include #include #include #include #include "mathlib.h" namespace celmath { extern float turbulence(const Eigen::Vector2f& p, float freq); extern float turbulence(const Eigen::Vector3f& p, float freq); extern float fractalsum(const Eigen::Vector2f& p, float freq); extern float fractalsum(const Eigen::Vector3f& p, float freq); extern float noise(float arg); extern float noise(const Eigen::Vector2f& arg); extern float noise(const Eigen::Vector3f& arg); template struct RealDists { static std::uniform_real_distribution Unit; static std::uniform_real_distribution SignedUnit; static std::uniform_real_distribution SignedFullAngle; }; template std::uniform_real_distribution RealDists::Unit{static_cast(0), static_cast(1)}; template std::uniform_real_distribution RealDists::SignedUnit{static_cast(-1), static_cast(1)}; template std::uniform_real_distribution RealDists::SignedFullAngle{-celestia::numbers::pi_v, celestia::numbers::pi_v}; template Eigen::Matrix randomOnCircle(RNG&& rng) { using std::cos, std::sin; T phi = RealDists::SignedFullAngle(rng); return Eigen::Matrix{cos(phi), sin(phi)}; } template Eigen::Matrix randomOnSphere(RNG&& rng) { using std::cos, std::sin, std::sqrt; T phi = RealDists::SignedFullAngle(rng); T cosTheta = RealDists::SignedUnit(rng); T xyScale = sqrt(static_cast(1) - square(cosTheta)); return Eigen::Matrix{xyScale * cos(phi), xyScale * sin(phi), cosTheta}; } std::mt19937& getRNG(); }