#ifndef NBOX_H
# define NBOX_H

# ifndef V2_H
#  include "v2.h"
# endif
# ifndef NLTRANS_H
#  include "nltrans.h"
# endif
# ifndef BOX_H
#  include "box.h"
# endif
# ifndef NLINE_H
#  include "nline.h"
# endif

class nparallelogram : public geo_shape	{
	nltransform a;

	public:

	~nparallelogram();
	nparallelogram(C box& x);
	nparallelogram(C nltransform& b, C box& x);
	nparallelogram(C nparallelogram& i) : geo_shape(), a(i.a) {}
	nparallelogram& operator=(C nparallelogram& i) {a=i.a; return *this;}

	vector2 c(int which_corner) C;
	vector2 c00() C	{return a(box::unitbox.c00());}
	vector2 c01() C	{return a(box::unitbox.c01());}
	vector2 c10() C	{return a(box::unitbox.c10());}
	vector2 c11() C	{return a(box::unitbox.c11());}
	vector2 center() C	{return a(box::unitbox.center());}
	nline s(int which_side) C;
	nline s0() C	{return s(0);}
	nline s1() C	{return s(1);}
	nline s2() C	{return s(2);}
	nline s3() C	{return s(3);}
	line chord0() C	{return chord(0);}
	line chord1() C	{return chord(1);}
	line chord2() C	{return chord(2);}
	line chord3() C	{return chord(3);}
	line chord(int which_side) C;

	double area() C;
	box outsidebox() C;
	box insidebox() C;
	box insidebox(C vector2& ctr) C;
	BOOL encloses(C vector2& pos) C; /* No trivial algorithm exists. */

	friend nparallelogram operator*(C nltransform& a, C nparallelogram& b);
	friend nparallelogram operator*(C ltransform& a, C nparallelogram& b);
	friend nparallelogram operator+(C nparallelogram& a, C vector2& shift);
	C nltransform& Transform() C	{return a;}
	BOOL ok() C	{return a.ok();}
	C vector_space *space() C	{return a.Shift().space();}
	};

nparallelogram operator*(C nltransform& a, C nparallelogram& b);
nparallelogram operator*(C ltransform& a, C nparallelogram& b);
nparallelogram operator*(C nltransform& a, C box& b);
nparallelogram operator+(C nparallelogram& a, C vector2& shift);
inline nparallelogram operator-(C nparallelogram& a, C vector2& shift)
	{return a+(-shift);}
inline nparallelogram operator+(C vector2& shift, C nparallelogram& a)
	{return a+shift;}
box inverse_image(C box& db1, C nltransform& fwd);

#endif
