#include "nfold_vec.h"
#include <math.h>
#include "gpkieee754.h"

C int N2foldVec::symmetry = 2;

N2foldVec::N2foldVec()
: x0(quiet_nan(0)), x1(quiet_nan(0))
{}


N2foldVec N2foldVec::operator*(double c) C
{
 return N2foldVec(x0*c, x1*c, 1);
}


N2foldVec& N2foldVec::operator+=(C N2foldVec& a)
{
 x0 += a.x0;
 x1 += a.x1;
 return *this;
}


void N2foldVec::make(double xx0, double xx1)
{
 C double r = hypot(xx0, xx1);
 C double a = r>0 ? atan2(xx1, xx0) : 0.0;
 x0 = r*cos(a*symmetry);
 x1 = r*sin(a*symmetry);
}


N2foldVec::N2foldVec(C vector2& x)
{
 make(x(0), x(1));
}


N2foldVec::N2foldVec(double xx0, double xx1)
{
 make(xx0, xx1);
}


C vector2 N2foldVec::pos(int n) C
{
 C double r = hypot(x0, x1);
 C double a = atan2(x1, x0);
 return vector2(r*cos((a+2*M_PI*n)/symmetry), r*sin((a+2*M_PI*n)/symmetry));
}
