#include "Arc.h"

#include "PointParser.h"
#include <sstream>

namespace ntk {
	Arc::Arc(const Point& startPoint, const Point& endPoint, double rX, double rY, double rotation, bool largeArc, bool sweep)
		: mStartPoint(startPoint),
		mEndPoint(endPoint),
		mRx(rX),
		mRy(rY),
		mRotation(rotation),
		mLargeArc(largeArc),
		mSweep(sweep)
	{

	}

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

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

	std::string Arc::toPostScriptString(std::size_t precision) const
	{
		const auto large = mLargeArc ? "1" : "0";
		const auto sweep = mSweep ? "1" : "0";
		std::stringstream sstr;
		if (precision > 0)
		{
			sstr.precision(precision);
		}
		if (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO)
		{
			sstr << "a";
		}
		else
		{
			sstr << "A";
		}
		sstr << mRx << " " << mRy << " " << mRotation << " " << large << " " << sweep << " ";
		if (mPostscriptPositioning == PostscriptPositioning::RELATIVE_TO)
		{
			sstr << PointParser::toStringRelative(mEndPoint, mStartPoint, 2, " ", precision);
		}
		else
		{
			sstr << PointParser::toString(mEndPoint, 2, " ", precision);
		}
		return sstr.str();
	}

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

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

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

	}

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

	Arc::CurveType Arc::getCurveType() const
	{
		return CurveType::ARC;
	}

	double Arc::getRx() const
	{
		return mRx;
	}

	double Arc::getRy() const
	{
		return mRy;
	}

	double Arc::getRotation() const
	{
		return mRotation;
	}

	bool Arc::getUseLargeArc() const
	{
		return mLargeArc;
	}

	bool Arc::getSweepParam() const
	{
		return mSweep;
	}
}
