#include "CubicBezierCurve.h"

#include "PointParser.h"

CubicBezierCurve::CubicBezierCurve(const Point& startPoint, const Point& endPoint, const Point& startControlPoint, const Point& endControlPoint)
	: mStartPoint(startPoint),
	mEndPoint(endPoint),
	mStartControlPoint(startControlPoint),
	mEndControlPoint(endControlPoint)
{

}

Point CubicBezierCurve::getFirstPoint() const
{
	return mStartPoint;
}

Point CubicBezierCurve::getEndPoint() const
{
	return mEndPoint;
}

const Point& CubicBezierCurve::getStartControlPoint() const
{
	return mStartControlPoint;
}

const Point& CubicBezierCurve::getEndControlPoint() const
{
	return mEndControlPoint;
}

std::string CubicBezierCurve::toPostScriptString(std::size_t precision) const
{
	if (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO)
	{
		const auto start_control = PointParser::toStringRelative(mStartControlPoint, mStartPoint, 2, " ", precision);
		const auto end_control = PointParser::toStringRelative(mEndControlPoint, mStartPoint, 2, " ", precision);
		const auto end = PointParser::toStringRelative(mEndPoint, mStartPoint, 2, " ", precision);
		return "c" + start_control + " " + end_control + " " + end;
	}
	else
	{
		const auto start_control = PointParser::toString(mStartControlPoint, 2, " ", precision);
		const auto end_control = PointParser::toString(mEndControlPoint, 2, " ", precision);
		const auto end = PointParser::toString(mEndPoint, 2, " ", precision);
		return "C" + start_control + " " + end_control + " " + end;
	}
}

Bounds CubicBezierCurve::getBounds() const
{
	return {};
}

const Point& CubicBezierCurve::getLocation() const
{
	return mStartPoint;
}

void CubicBezierCurve::sample(SparseGrid<bool>*) const
{

}

CubicBezierCurve::Type CubicBezierCurve::getType() const
{
	return Type::CURVE;
}

CubicBezierCurve::CurveType CubicBezierCurve::getCurveType() const
{
	return CurveType::CUBIC_BEZIER;
}
