#include "cellshapestruct.h"

#include <random>

CellBase::CellBase(double _xspan, double _yspan, double _zspan)
{
    xspan = _xspan;
    yspan = _yspan;
    zspan = _zspan;
}

void CellBase::setSpan(double _xspan, double _yspan, double _zspan)
{
    xspan = _xspan;
    yspan = _yspan;
    zspan = _zspan;
}

CellVertex::CellVertex(double _xspan /*= 3.0*/, double _yspan /*= 4.0*/, double _zspan /*= 5.0*/)
    : CellBase(_xspan, _yspan, _zspan)
{
    p.resize(1);
}

void CellVertex::setCoordinate(double x, double y, double z)
{
	p[0] = { x, y, z };
}

CellPolyVertex::CellPolyVertex(double _xspan /*= 3.0*/, double _yspan /*= 4.0*/, double _zspan /*= 5.0*/, int _pointNum /*= -1*/)
    : CellBase(_xspan, _yspan, _zspan)
{
    if (_pointNum <= 0)
    {
		std::random_device rd;
		std::uniform_int_distribution<int> dist(1, 20);
		pointNum = dist(rd);
    }
    else
    {
        pointNum = _pointNum;
    }
    p.resize(pointNum);
}

void CellPolyVertex::setCoordinate(double x, double y, double z)
{
    for (int i = 0; i < pointNum; i++)
    {
        p[i] = {x + i * xspan, y + i * yspan, z + i * zspan};
    }
}

CellLine::CellLine(double _xspan /*= 3.0*/, double _yspan /*= 4.0*/, double _zspan /*= 5.0*/)
    : CellBase(_xspan, _yspan, _zspan)
{
    p.resize(2);
}

void CellLine::setCoordinate(double x, double y, double z)
{
	p[0] = { x, y, z };
	p[1] = { x + xspan, y + yspan, z + zspan };
}

CellPolyLine::CellPolyLine(double _xspan /*= 3.0*/, double _yspan /*= 4.0*/, double _zspan /*= 5.0*/, int _pointNum /*= -1*/)
    : CellBase(_xspan, _yspan, _zspan)
{
	if (_pointNum <= 0)
	{
		std::random_device rd;
		std::uniform_int_distribution<int> dist(1, 20);
		pointNum = dist(rd);
	}
	else
	{
		pointNum = _pointNum;
	}
	p.resize(pointNum);
}

void CellPolyLine::setCoordinate(double x, double y, double z)
{
	for (int i = 0; i < pointNum; i++)
	{
		p[i] = { x + i * xspan, y + i * yspan, z + i * zspan };
	}
}

CellTriangle::CellTriangle(double _xspan, double _yspan, double _zspan)
    : CellBase(_xspan, _yspan, _zspan)
{
    p.resize(3);
}

void CellTriangle::setCoordinate(double x, double y, double z)
{
    p[0] = {x, y, z};
    p[1] = {x, y + yspan, z};
    p[2] = {x, y + yspan / 2.0, z + zspan};
}

CellQuad::CellQuad(double _xspan, double _yspan, double _zspan)
    : CellBase(_xspan, _yspan, _zspan)
{
    p.resize(4);
}

void CellQuad::setCoordinate(double x, double y, double z)
{
    p[0] = {x, y, z};
    p[1] = {x, y + yspan, z};
    p[2] = {x, y + yspan, z + zspan};
    p[3] = {x, y, z + zspan};
}

CellTetra::CellTetra(double _xspan, double _yspan, double _zspan)
    : CellBase(_xspan, _yspan, _zspan)
{
    p.resize(4);
}

void CellTetra::setCoordinate(double x, double y, double z)
{
    p[0] = {x - xspan / 2.0, y - yspan / 2.0, z - zspan / 2.0};
    p[1] = {x + xspan / 2.0, y - yspan / 2.0, z - zspan / 2.0};
    p[2] = {x, y - yspan / 2.0, z + zspan / 2.0};
    p[3] = {x, y + yspan / 2.0, z};
}

CellWedge::CellWedge(double _xspan, double _yspan, double _zspan)
    : CellBase(_xspan, _yspan, _zspan)
{
    p.resize(6);
}

void CellWedge::setCoordinate(double x, double y, double z)
{
    p[0] = {x + xspan / 2.0, y + yspan / 2.0, z - zspan / 2.0};
    p[1] = {x + xspan / 2.0, y - yspan / 2.0, z - zspan / 2.0};
    p[2] = {x + xspan / 2.0, y, z + zspan / 2.0};
    p[3] = {x - xspan / 2.0, y + yspan / 2.0, z - zspan / 2.0};
    p[4] = {x - xspan / 2.0, y - yspan / 2.0, z - zspan / 2.0};
    p[5] = {x - xspan / 2.0, y, z + zspan / 2.0};
}

CellPyramid::CellPyramid(double _xspan, double _yspan, double _zspan)
    : CellBase(_xspan, _yspan, _zspan)
{
    p.resize(5);
}

void CellPyramid::setCoordinate(double x, double y, double z)
{
    p[0] = {x - xspan / 2.0, y + yspan / 2.0, z - zspan / 2.0};
    p[1] = {x + xspan / 2.0, y + yspan / 2.0, z - zspan / 2.0};
    p[2] = {x + xspan / 2.0, y - yspan / 2.0, z - zspan / 2.0};
    p[3] = {x - xspan / 2.0, y - yspan / 2.0, z - zspan / 2.0};
    p[4] = {x, y, z + zspan / 2.0};
}

CellPentagonalPrism::CellPentagonalPrism(double _xspan, double _yspan, double _zspan)
{
    p.resize(10);
}

void CellPentagonalPrism::setCoordinate(double x, double y, double z)
{
    p[0] = {x - xspan / 2.0, y + yspan / 4.0, z - zspan / 2.0};
    p[1] = {x - xspan / 2.0, y - yspan / 4.0, z - zspan / 2.0};
    p[2] = {x - xspan / 2.0, y - yspan / 2.0, z};
    p[3] = {x - xspan / 2.0, y, z + zspan / 2.0};
    p[4] = {x - xspan / 2.0, y + yspan / 2.0, z};
    p[5] = {x + xspan / 2.0, y + yspan / 4.0, z - zspan / 2.0};
    p[6] = {x + xspan / 2.0, y - yspan / 4.0, z - zspan / 2.0};
    p[7] = {x + xspan / 2.0, y - yspan / 2.0, z};
    p[8] = {x + xspan / 2.0, y, z + zspan / 2.0};
    p[9] = {x + xspan / 2.0, y + yspan / 2.0, z};
}

CellHexagonalPrism::CellHexagonalPrism(double _xspan, double _yspan, double _zspan)
{
    p.resize(12);
}

void CellHexagonalPrism::setCoordinate(double x, double y, double z)
{
    p[0] = {x - xspan / 2.0, y + yspan / 4.0, z - zspan / 2.0};
    p[1] = {x - xspan / 2.0, y - yspan / 4.0, z - zspan / 2.0};
    p[2] = {x - xspan / 2.0, y - yspan / 2.0, z};
    p[3] = {x - xspan / 2.0, y - yspan / 4.0, z + zspan / 2.0};
    p[4] = {x - xspan / 2.0, y + yspan / 4.0, z + zspan / 2.0};
    p[5] = {x - xspan / 2.0, y + yspan / 2.0, z};
    p[6] = {x + xspan / 2.0, y + yspan / 4.0, z - zspan / 2.0};
    p[7] = {x + xspan / 2.0, y - yspan / 4.0, z - zspan / 2.0};
    p[8] = {x + xspan / 2.0, y - yspan / 2.0, z};
    p[9] = {x + xspan / 2.0, y - yspan / 4.0, z + zspan / 2.0};
    p[10] = {x + xspan / 2.0, y + yspan / 4.0, z + zspan / 2.0};
    p[11] = {x + xspan / 2.0, y + yspan / 2.0, z};
}





