summaryrefslogtreecommitdiff
path: root/vector.hpp
blob: 04a1a9792ad057c4f5dfe206f475c57323e3e44e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

#pragma once

#include "mod.hpp"
#include <eigen3/Eigen/Dense>

template <class T, int D> using Vector = Eigen::Matrix<T, D, 1>;

template <class T, int D> Vector<T, D> diff(T L, Vector<T, D> v1, Vector<T, D> v2) {
  Vector<T, D> v;

  for (unsigned i = 0; i < D; i++) {
    v(i) = mod(std::abs(v1(i) - v2(i)), L);
    if (v(i) > L / 2) {
      v(i) = L - v(i);
    }
  }

  return v;
}