#include "Rod2d.hpp"

#include "Eigen/Dense"
#include "tools.hpp"
Rod2d::Rod2d(double L) : m_pos({1, 1}), m_e({1, 0}) {
    assert(L >= 1.0);
    if (L == 1.0) {
        m_D_rot = 3.0;
        m_Diff << 1, 0, 0, 1;
    } else {
        const double D0 = 3.0 * Tools::M_Pl / L;
        const double p = L;
        auto D_para = Tools::D_para(D0, p);
        auto D_ortho = Tools::D_ortho(D0, p);
        m_D_rot = Tools::D_rot(D0, p);
        m_Diff << D_para, 0, 0, D_ortho;
    }
    m_Diff_sqrt = m_Diff;
    m_D_rot_sqrt = sqrt(m_D_rot);
    Tools::mat_sqrt(m_Diff_sqrt);
}

void Rod2d::setPos(const Eigen::Vector2d &Pos) { m_pos = Pos; }

double Rod2d::getDRot() const { return m_D_rot; }

const Eigen::Vector2d &Rod2d::getPos() const { return m_pos; }

const Eigen::Matrix2d &Rod2d::getDiff() const { return m_Diff; }

const Eigen::Matrix2d &Rod2d::getDiff_Sqrt() const { return m_Diff_sqrt; }

double Rod2d::getDRot_Sqrt() const { return m_D_rot_sqrt; }

const Eigen::Vector2d &Rod2d::getE() const { return m_e; }

void Rod2d::setE(const Eigen::Vector2d &mE) { m_e = mE; }
