//
// Created by jholder on 21.10.21.
//

#include "Simulation.h"

Simulation::Simulation(double t_delta_T, size_t seed)
    : m_xBorder(100),
      m_yBorder(100),
      m_delta_T(t_delta_T),
      m_std(std::sqrt(t_delta_T * 2.0)),
      m_generator(seed),
      m_norm(0, 1.0) {}

double Simulation::getNorm(double t_norm) {
    return t_norm * m_norm(m_generator);
}

double Simulation::getMDeltaT() const { return m_delta_T; }

double Simulation::getSTD() const { return m_std; }

void Simulation::set_xBorder(double border) {
    m_enable_border = true;
    m_xBorder = border;
};
void Simulation::set_yBorder(double border) {
    m_enable_border = true;
    m_yBorder = border;
};
pos_type Simulation::boundaryPos(pos_type pos) const {
    if (not m_enable_border) {
        return pos;
    }
    if (pos[0] > m_xBorder) {
        pos[0] -= m_xBorder;
    }
    if (pos[1] > m_yBorder) {
        pos[1] -= m_yBorder;
    }
    return pos;
}

pos_type Simulation::boundaryDistance(const pos_type& pos1, const pos_type& pos2) const {
    pos_type distance = pos2 - pos1;
    if (not m_enable_border) {
        return distance;
    }
    if (distance[0] > m_xBorder / 2) {
        distance[0] -= m_xBorder;
    }
    if (distance[1] > m_yBorder / 2) {
        distance[1] -= m_yBorder;
    }
    return distance;
}
