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

main()
{
 C vector2 spot(5.4, 2.221);
 C line one(spot, 0.5121);
 C line two(spot, 0.12223);
 C line_intersection ot(one, two);

 assert(two.angle()>.12222 && two.angle()<.12224);
 assert(one.angle()>.5120 && one.angle()<.5122);

 assert(ot.one_int());
 printf("intersect at (%g %g), should be (%g %g)\n", ot[0](0), ot[0](1),
 				spot(0), spot(1));
 assert(dist(spot-ot[0]) < 1e-7);
 assert(fabs(ot.sa(0)) < 1e-7);
 assert(fabs(ot.sb(0)) < 1e-7);

 C line_intersection ab(line(vector2(1,0), vector2(1,5)),
 						line(vector2(0,2), vector2(1,2)));
 assert(ab.one_int());
 printf("intersect at (%g %g), should be (%g %g)\n", ab[0](0), ab[0](1),
 				1.0, 2.0);
 assert(dist(ab[0]-vector2(1,2)) < 1e-8);
 assert(fabs(ab.sa(0)-0.4)<1e-7);
 assert(fabs(ab.sb(0)-1.0)<1e-7);

 C line_intersection at(line(vector2(1,0), M_PI/2.0),
 						line(vector2(0,2), 0.0));
 assert(at.one_int());
 printf("intersect at (%g %g), should be (%g %g)\n", at[0](0), at[0](1),
 				1.0, 2.0);
 assert(dist(at[0]-vector2(1,2)) < 1e-8);

 C line_intersection oo(one, one);
 assert(oo.line_int());
 C line os = one+vector2(1.0,55.0);
 C line_intersection oos(one, os);
 assert(oos.no_int() || oos.at_inf());

 C line_intersection pp(line(vector2(3,2), vector2(-1,5)),
 						line(vector2(0,33.33), vector2(3,2)));
 assert(pp.one_int());
 printf("intersect at (%g %g), should be (%g %g)\n", pp[0](0), pp[0](1),
 				3.0, 2.0);
 assert(dist(pp[0]-vector2(3,2)) < 1e-8);

 printf("OK\n");
}
