#include <gpk_std.h>
#include "../line.h"
#include <stdio.h>
#include <assert.h>
#include <math.h>

main()
{
 C line one(vector2(0,0), 0.5);
 C line two(vector2(5.4, 2.221), 0.5);
 C line op = one+vector2(5.4,2.221);
 printf("op: xi=%g yi=%g\n", op.x_intercept(), op.y_intercept());
 printf("two: xi=%g yi=%g\n", two.x_intercept(), two.y_intercept());
 assert(fabs(op.x_intercept()-two.x_intercept()) < 1e-7);
 assert(fabs(op.y_intercept()-two.y_intercept()) < 1e-7);
 C double correct_y_int = 2.221-5.4*tan(0.5);
 C double correct_x_int = 5.4-2.221/tan(0.5);
 assert(fabs(correct_x_int-op.x_intercept()) < 1e-5);
 assert(fabs(correct_y_int-op.y_intercept()) < 1e-5);

 double th;
 for(th=0;th<15;th+=0.01)	{
 	C double ath = line(vector2(1.2-th*th,th+1), th).angle();
	assert(ath>=-M_PI && ath<=M_PI);
	assert(fabs(sin(th-ath))<1e-6 && fabs(cos(th-ath))>0.99999);
	}

 C line ll(vector2(0,0), vector2(1,1));
 assert(fabs(ll.angle()-M_PI/4) < 1e-8);

 C line lte(vector2(0,0), vector2(cos(0.1), sin(0.1)));
 assert(fabs(lte.angle()-0.1) < 1e-8);

 printf("OK\n");
}
