#ifndef LINE_H
# define LINE_H

# ifndef GPK_STD_H
#  include <gpk_std.h>
# endif
# ifndef V2_H
#  include "v2.h"
# endif




class line	{
	vector2 _base, _dir;	/* parametric form */

	public:
	line();
	line(C vector2& point1, C vector2& point2);
	line(C vector2& point, double angle);
	line(double a, double b, double c); /* ax+by+c=0 */
	line(C line& aa) : _base(aa._base), _dir(aa._dir) {}
	line& operator=(C line& aa)	{_base=aa._base; _dir=aa._dir; return *this;}

	double slope() C	{return _dir(1)/_dir(0);}
	double x_intercept() C;
	double y_intercept() C;
	double angle() C;
	double a() C	{return -_dir(1);}
	double b() C	{return _dir(0);}
	double c() C	{return -(a()*_base(0)+b()*_base(1));}
	C vector2& base() C	{return _base;}
	C vector2& dir() C	{return _dir;}
	vector2 operator()(double s) C	{return _dir*s + _base;}
	vector2 nearest_to_origin() C	{return (*this)(p_nearest_to_origin());}
	double p_nearest_to_origin() C;

	BOOL ok() C	{return vector_space::vseQ(_base.space(), _dir.space());}
	};

line operator+(C line& a, C vector2& b);
inline line operator-(C line& a, C vector2& b)	{return a + (-b);}
inline line operator+(C vector2& b, C line& a)	{return a+b;}
double dist(C line& b);	/* distance from (0,0) */

// #include <iostream.h>
// ostream& operator<<(ostream& s, C line& l);

#endif
