#include <math.h>
#include "GR_BdryPatch2D.h"

// *******************************************************************
//
// BdryBezier2D
// -------
//
// Descendant of BdryCubicParam2D. Simply need to calculate the coefficients
// in a different way
//
// *******************************************************************

BdryBezier2D::
BdryBezier2D () : iCPt1(-1), iCPt2(-1)
{
  iBCLeft = iBCRight = iInvalidBC;
  iRegionLeft = iRegionRight = iInvalidRegion;
  iBeginPt = iEndPt = -1;
  eGeom2DType = eBezier;
}

BdryBezier2D::
BdryBezier2D(Bdry2D* pBdryObject, const int iBCL, const int iBCR,
	  const int iRL, const int iRR,
	  const int iBPt, const int iEPt,
	  const int iC1, const int iC2):
  BdryCubicParam2D (pBdryObject, iBCL, iBCR, iRL, iRR, iBPt, iEPt),
  iCPt1(iC1), iCPt2(iC2)
{
	double dB[2], dE[2];
	double adC1[2], adC2[2];
	
	assert (iC1 >= 0);
	assert (iC2 >= 0);
	// Get the coordinates of the points
	vGetBeginPoint(dB);
	vGetEndPoint(dE);
	pB2D->vGetPoint(iCPt1, adC1);
	pB2D->vGetPoint(iCPt2, adC2);
	
	// Find the coefficients
	adCoeffs[0][0] = -dB[0] + 3.0*adC1[0] - 3.0*adC2[0] + dE[0];
	adCoeffs[1][0] = -dB[1] + 3.0*adC1[1] - 3.0*adC2[1] + dE[1];
	adCoeffs[0][1] = 3.0*dB[0] - 6.0*adC1[0] + 3.0*adC2[0];
	adCoeffs[1][1] = 3.0*dB[1] - 6.0*adC1[1] + 3.0*adC2[1];
	adCoeffs[0][2] = -3.0*dB[0] + 3.0*adC1[0];
	adCoeffs[1][2] = -3.0*dB[1] + 3.0*adC1[1];
	adCoeffs[0][3] = dB[0];
	adCoeffs[1][3] = dB[1];
  // Set boundary type
  eGeom2DType = eBezier;

  // Calculate stuff
  vRefresh();

}

void BdryBezier2D::
vAssignData (Bdry2D* pBdryObject, const int iBCL, const int iBCR,
	     const int iRL, const int iRR,
	     const int iBPt, const int iEPt)
{
  BdryPatch2D::vAssignData (pBdryObject, iBCL, iBCR, iRL, iRR, iBPt, iEPt);
  // Compute data..
  vRefresh ();
}

void BdryBezier2D::
vGetBezierPoints(double dP1[2], double dP2[2], double dP3[2], double dP4[2]) const 
{
	// No need to calculate anything here...
	vGetBeginPoint(dP1);
	vGetEndPoint(dP4);
	pB2D->vGetPoint(iCPt1, dP2);
	pB2D->vGetPoint(iCPt2, dP3);
}

BdryBezier2D::~BdryBezier2D ()
{
  // Destructor
}
