#include "TriMesh.h"

#include "Edge.h"
#include "TriFace.h"

TriMesh::~TriMesh()
{

}

AbstractMesh::MeshType TriMesh::getType() const
{
    return AbstractMesh::MeshType::TRI;
}

std::unique_ptr<AbstractMesh> TriMesh::copy() const
{
    VecNodes nodes(mNodes.size());
    unsigned count = 0;
    for (auto& node : mNodes)
    {
        nodes[count] = std::make_unique<Node>(node->getPoint());
        count++;
    }

    VecEdges edges(mEdges.size());
    count = 0;
    for (auto& edge : mEdges)
    {
        edges[count] = std::make_unique<Edge>(nodes[edge->getNode0Id()].get(), nodes[edge->getNode0Id()].get());
        count++;
    }

    VecFaces faces(mFaces.size());
    count = 0;
    for (auto& face : mFaces)
    {
        auto ids = face->getEdgeIds();
        faces[count] = std::make_unique<TriFace>(edges[ids[0]].get(), edges[ids[1]].get(), edges[ids[2]].get());
        count++;
    }

    auto mesh = std::make_unique<TriMesh>();
    mesh->populate(nodes, edges, faces);
    return mesh;
}
