#include "Node.h"

std::unique_ptr<Node> Node::Create(const Point& p, std::size_t index)
{
    return std::make_unique<Node>(p, index);
}

Node::~Node()
{

}

Node::Node(const Point& p, std::size_t index)
    : mIndex(index),
      mPoint(p)
{

}

std::size_t Node::getIndex() const
{
    return mIndex;
}

void Node::updateIndex(std::size_t index)
{
    mIndex = index;
}

void Node::addVectorAttribute(const std::string& tag, const std::vector<double>& values)
{
    mVectorAttributes[tag] = values;
}

std::vector<double> Node::getVectorAttribute(const std::string& tag) const
{
    auto iter = mVectorAttributes.find(tag);
    if (iter != mVectorAttributes.end())
    {
        return iter->second;
    }
    return {};
}

const Point& Node::getPoint() const
{
    return mPoint;
}

void Node::apply(const Transform& transform)
{
    mPoint.apply(transform);
}

bool Node::isCoincident(Node* node) const
{
    return node->getPoint() == mPoint;
}

void Node::setState(State state)
{
    mState = state;
}

Node::State Node::getState() const
{
    return mState;
}

void Node::clearConnectivity()
{
    mAssociatedEdgeIds.clear();
    mAssociatedFaceIds.clear();
}

std::size_t Node::getNumConnectedEdges() const
{
    return mAssociatedEdgeIds.size();
}

std::size_t Node::getNumConnectedFaces() const
{
    return mAssociatedFaceIds.size();
}

void Node::associateEdge(std::size_t edgeId)
{
    mAssociatedEdgeIds.push_back(edgeId);
}

void Node::associateFace(std::size_t faceId)
{
    mAssociatedFaceIds.push_back(faceId);
}

std::size_t Node::getConnectedEdgeId(std::size_t idx) const
{
    return mAssociatedEdgeIds[idx];
}

std::size_t Node::getConnectedFaceId(std::size_t idx) const
{
    return mAssociatedFaceIds[idx];
}

void Node::setIndex(std::size_t idx)
{
    mIndex = idx;
}


