#ifndef GENERATERANDOMPOINTS_H
#define GENERATERANDOMPOINTS_H

#include <vector>
using namespace std;

#include <typedefs.h>


/*!
\brief Generate random points inside a unit circle.
*/
template< typename T, typename D, typename RG >
class generateRandomPointsInCircle
{
public:

  /** Random points in unit circle centered at the origin. */
  generateRandomPointsInCircle
  (
    vector< T > & v,
    uintc n
  );
};


/*!
\brief Generate random points inside a unit sphere.
*/
template< typename T, typename D, typename RG >
class generateRandomPointsInSphere
{
public:

  /** Random points in unit circle centered at the origin. */
  generateRandomPointsInSphere
  (
    vector< T > & v,
    uintc n
  );
};



//---------------------------------------------------------
//  Implementation


template< typename T, typename D, typename RG >
generateRandomPointsInCircle<T,D,RG>::generateRandomPointsInCircle
(
  vector< T > & v,
  uintc n
)
{
  RG r;
  D x;
  D y;
  for (uint i=0; i<n; )
  {
    x = (D)2.0*r()-(D)1.0;
    y = (D)2.0*r()-(D)1.0;
    if (x*x+y*y <= (D)1.0)
    {
      v.push_back( T(x,y) );
      ++i;
    }
  }
}


template< typename T, typename D, typename RG >
generateRandomPointsInSphere<T,D,RG>::generateRandomPointsInSphere
(
  vector< T > & v,
  uintc n
)
{
  RG r;
  D x;
  D y;
  D z;
  for (uint i=0; i<n; )
  {
    x = (D)2.0*r()-(D)1.0;
    y = (D)2.0*r()-(D)1.0;
    z = (D)2.0*r()-(D)1.0;
    if (x*x+y*y+z*z <= (D)1.0)
    {
      v.push_back( T(x,y,z) );
      ++i;
    }
  }
}






#endif



