#include "PointParser.h"

#include <sstream>

std::string PointParser::toString(const Point& p, std::size_t dimensions, const std::string& delimiter, std::size_t precision)
{
    return toString(p.getX(), p.getY(), p.getZ(), dimensions, delimiter, precision);
}

std::string PointParser::toStringRelative(const Point& p, const Point& relativeTo, std::size_t dimensions, const std::string& delimiter, std::size_t precision)
{
    return toString(relativeTo.getDeltaX(p), relativeTo.getDeltaY(p), relativeTo.getDeltaZ(p), dimensions, delimiter, precision);
}

std::string PointParser::toString(double x, double y, double z, std::size_t dimensions, const std::string& delimiter, std::size_t precision)
{
    if (precision == 0)
    {
        if (dimensions == 1)
        {
            return std::to_string(x);
        }
        else if (dimensions == 2)
        {
            return std::to_string(x) + delimiter + std::to_string(y);
        }
        else
        {
            return std::to_string(x) + delimiter + std::to_string(y) + delimiter + std::to_string(z);
        }
    }
    else
    {
        std::stringstream sstr;
        sstr.precision(precision);
        if (dimensions == 1)
        {
            sstr << x;
        }
        else if (dimensions == 2)
        {
            sstr << x << delimiter << y;
        }
        else
        {
            sstr << x << delimiter << y << delimiter << z;
        }
        return sstr.str();
    }
}

std::string PointParser::toString(double x, std::size_t precision)
{
    if (precision == 0)
    {
        return std::to_string(x);
    }
    else
    {
        std::stringstream sstr;
        sstr.precision(precision);
        sstr << x;
        return sstr.str();
    }
}

