//------------------------------------------------------------------------------------
// irr::core::rectf wrappers
//
//	WARNINGS: get warnings on isValid() and repair() due to their use of integers
//
//------------------------------------------------------------------------------------

// defaults: x,y,z=0.0f

extern "C" 
{

	rectf* IrrCore_Rectf_newFromVals(f32 x1,f32 y1,f32 x2,f32 y2)
	{
		return new rectf(x1,y1,x2,y2);
	}
	
	rectf* IrrCore_Rectf_new()
	{
		return new rectf();
	}
	
	rectf* IrrCore_Rectf_newFromPos(position2d<f32>* upperLeft,position2d<f32>* lowerRight)
	{
		return new rectf(*upperLeft,*lowerRight);
	}
	
	rectf* IrrCore_Rectf_newFromPosSize(position2d<f32>* pos,dimension2d<f32>* size)
	{
		return new rectf(*pos,*size);
	}
	
	rectf* IrrCore_Rectf_newFromRect(rectf* r)
	{
		return IrrCore_Rectf_newFromPos(&r->UpperLeftCorner,&r->LowerRightCorner);
	}
	
	void IrrCore_Rectf_del(rectf* del)
	{
		if (del)
			delete del;
			
		del=0;
	}
	
	bool IrrCore_Rectf_isPointInside(rectf* r,position2d<f32>* pos)
	{
		bool lRetVal=false;
		
		if (r>0)
			lRetVal=r->isPointInside(*pos);
	
		return lRetVal;
	}
	
	bool IrrCore_Rectf_isRectCollided(rectf* r,rectf* other)
	{
		bool lRetVal=false;
		
		if (r>0)
			lRetVal=r->isRectCollided(*other);
	
		return lRetVal;
	}
	
	void IrrCore_Rectf_clipAgainst(rectf* r,rectf* other) 
	{
		if (r>0)
			r->clipAgainst(*other);
	}
	
	f32 IrrCore_Rectf_getWidth(rectf* r)
	{
		f32 fRetVal=0.0f;
	
		if (r>0)
			fRetVal=r->getWidth();
	
		return fRetVal;
	}
	
	f32 IrrCore_Rectf_getHeight(rectf* r)
	{
		f32 fRetVal=0.0f;
	
		if (r>0)
			fRetVal=r->getHeight();
	
		return fRetVal;
	}
	
	void IrrCore_Rectf_repair(rectf* r) 
	{
		if (r>0)
			r->repair();
	}
	
	bool IrrCore_Rectf_isValid(rectf* r)
	{
		bool lRetVal=false;
		
		if (r>0)
			lRetVal=r->isValid();
	
		return lRetVal;
	}
	
	position2d<f32>* IrrCore_Rectf_getCenter(rectf* r)
	{
		position2d<f32>* pRetVal=0;
	
		if (r>0)
			pRetVal=new position2d<f32>(r->getCenter());
	
		return pRetVal;
	}
	
	position2d<f32>* IrrCore_Rectf_getUpperLeftCorner(rectf* r)
	{
		position2d<f32>* pRetVal=0;
	
		if (r>0)
			pRetVal=&r->UpperLeftCorner;
	
		return pRetVal;
	}
	
	position2d<f32>* IrrCore_Rectf_getLowerRightCorner(rectf* r)
	{
		position2d<f32>* pRetVal=0;
	
		if (r>0)
			pRetVal=&r->LowerRightCorner;
	
		return pRetVal;
	}
		
	// do not delete
	rectf* IrrCore_Rectf_PlusEq(rectf* r,position2d<f32>* other)
	{
		if (r>0) {
			*r+=*other;
			return r;
		} else return 0;
			
	}
	
	rectf* IrrCore_Rectf_Plus(rectf* r,position2d<f32>* other)
	{
		return new rectf((*r+*other));
	}

	rectf* IrrCore_Rectf_Minus(rectf* r,position2d<f32>* other)
	{
		return new rectf((*r-*other));
	}

	rectf* IrrCore_Rectf_MinusEq(rectf* r,position2d<f32>* other)
	{
		if (r>0) {
			*r-=*other;
			return r;
		} else return 0;
	}
		
	bool IrrCore_Rectf_EqEq(rectf* r,rectf* other)
	{
		bool lRetVal=false;
		
		if (r>0)
			lRetVal=(*r==*other);
	
		return lRetVal;
	}
	
	bool IrrCore_Rectf_NotEq(rectf* r,rectf* other)
	{
		bool lRetVal=false;
		
		if (r>0)
			lRetVal=(*r!=*other);
	
		return lRetVal;
	}
	
	// must delete ptr
	dimension2df* IrrCore_Rectf_getSize(rectf* r) 
	{
		dimension2df* retval=0;
		
		if (r>0)
			retval=new dimension2df(r->getSize());
	
		return retval;
	}

	void IrrCore_Rectf_addInternalPointFromPos(rectf* r,const position2d<f32>& p)
	{
		if (r)
			r->addInternalPoint(p);
	}
	
	void IrrCore_Rectf_addInternalPoint(rectf* r,f32 x, f32 y)
	{
		if (r)
			r->addInternalPoint(x,y);
	}
	
	f32 IrrCore_Rectf_getArea(rectf* r)
	{
		if (r)
			return r->getArea();
		else return 0.0f;
	}

	bool IrrCore_Rectf_constrainTo(rectf* r,const rectf& other)
	{
		if (r)
			return r->constrainTo(other);
		else return false;
	}		

	bool IrrCore_Rectf_Less(rectf* r,const rectf& other)
	{
		if (r)
			return (*r < other);
		else return false;
	}	
}
