1 /* test_uniform_on_sphere.cpp 2 * 3 * Copyright Steven Watanabe 2011 4 * Distributed under the Boost Software License, Version 1.0. (See 5 * accompanying file LICENSE_1_0.txt or copy at 6 * http://www.boost.org/LICENSE_1_0.txt) 7 * 8 * $Id$ 9 * 10 */ 11 12 #include <boost/random/uniform_on_sphere.hpp> 13 #include <boost/random/uniform_int.hpp> 14 #include <boost/math/distributions/uniform.hpp> 15 #include <cmath> 16 17 class uniform_on_sphere_test { 18 public: 19 typedef double result_type; uniform_on_sphere_test(int dims,int x,int y)20 uniform_on_sphere_test(int dims, int x, int y) 21 : impl(dims), idx1(x), idx2(y) {} 22 template<class Engine> operator ()(Engine & rng)23 result_type operator()(Engine& rng) { 24 const boost::random::uniform_on_sphere<>::result_type& tmp = impl(rng); 25 // This should be uniformly distributed in [-pi,pi) 26 return std::atan2(tmp[idx1], tmp[idx2]); 27 } 28 private: 29 boost::random::uniform_on_sphere<> impl; 30 int idx1, idx2; 31 }; 32 33 static const double pi = 3.14159265358979323846; 34 35 #define BOOST_RANDOM_DISTRIBUTION uniform_on_sphere_test 36 #define BOOST_RANDOM_DISTRIBUTION_NAME uniform_on_sphere 37 #define BOOST_MATH_DISTRIBUTION boost::math::uniform 38 #define BOOST_RANDOM_ARG1_TYPE double 39 #define BOOST_RANDOM_ARG1_NAME n 40 #define BOOST_RANDOM_ARG1_DEFAULT 6 41 #define BOOST_RANDOM_ARG1_DISTRIBUTION(n) boost::uniform_int<>(2, n) 42 #define BOOST_RANDOM_DISTRIBUTION_INIT (n, 0, n-1) 43 #define BOOST_MATH_DISTRIBUTION_INIT (-pi, pi) 44 45 #include "test_real_distribution.ipp" 46