LCOV - code coverage report
Current view: top level - src/interfaces - TransformationBuilderInterface.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 30 60.0 %
Date: 2025-05-02 21:49:25 Functions: 9 14 64.3 %

          Line data    Source code
       1             : // SPDX-FileCopyrightText: 2024 Pairinteraction Developers
       2             : // SPDX-License-Identifier: LGPL-3.0-or-later
       3             : 
       4             : #include "pairinteraction/interfaces/TransformationBuilderInterface.hpp"
       5             : 
       6             : #include "pairinteraction/enums/TransformationType.hpp"
       7             : #include "pairinteraction/utils/euler.hpp"
       8             : 
       9             : namespace pairinteraction {
      10             : 
      11         151 : IndicesOfBlock::IndicesOfBlock(size_t start, size_t end) : start(start), end(end) {}
      12             : 
      13         290 : size_t IndicesOfBlock::size() const { return end - start; }
      14             : 
      15          57 : IndicesOfBlocksCreator::IndicesOfBlocksCreator(std::initializer_list<size_t> boundaries)
      16          57 :     : boundaries(boundaries) {}
      17             : 
      18          94 : void IndicesOfBlocksCreator::add(size_t boundary) { boundaries.insert(boundary); }
      19             : 
      20          57 : std::vector<IndicesOfBlock> IndicesOfBlocksCreator::create() const {
      21          57 :     std::vector<IndicesOfBlock> blocks;
      22          57 :     if (boundaries.empty()) {
      23           0 :         return blocks;
      24             :     }
      25             : 
      26          57 :     auto it = boundaries.begin();
      27          57 :     size_t start = *it++;
      28             : 
      29         208 :     while (it != boundaries.end()) {
      30         151 :         blocks.emplace_back(start, *it);
      31         151 :         start = *it++;
      32             :     }
      33             : 
      34          57 :     return blocks;
      35           0 : }
      36             : 
      37           0 : size_t IndicesOfBlocksCreator::size() const {
      38           0 :     return boundaries.empty() ? 0 : boundaries.size() - 1;
      39             : }
      40             : 
      41             : template <typename Scalar>
      42          40 : Transformation<Scalar>::Transformation(Eigen::SparseMatrix<Scalar, Eigen::RowMajor> matrix,
      43             :                                        std::vector<TransformationType> transformation_type)
      44          40 :     : matrix(std::move(matrix)), transformation_type(std::move(transformation_type)) {}
      45             : 
      46             : template <typename Scalar>
      47          57 : Transformation<Scalar>::Transformation(Eigen::SparseMatrix<Scalar, Eigen::RowMajor> matrix)
      48          57 :     : matrix(std::move(matrix)), transformation_type({TransformationType::ARBITRARY}) {}
      49             : 
      50           0 : Sorting::Sorting(Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic> matrix,
      51           0 :                  std::vector<TransformationType> transformation_type)
      52           0 :     : matrix(std::move(matrix)), transformation_type(std::move(transformation_type)) {}
      53             : 
      54           0 : Sorting::Sorting(Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic> matrix)
      55           0 :     : matrix(std::move(matrix)), transformation_type({TransformationType::ARBITRARY}) {}
      56             : 
      57             : template <typename Scalar>
      58             : Transformation<Scalar>
      59           0 : TransformationBuilderInterface<Scalar>::get_rotator(const std::array<real_t, 3> &to_z_axis,
      60             :                                                     const std::array<real_t, 3> &to_y_axis) const {
      61           0 :     auto euler_zyz_angles = euler::get_euler_angles(to_z_axis, to_y_axis);
      62           0 :     return this->get_rotator(euler_zyz_angles[0], euler_zyz_angles[1], euler_zyz_angles[2]);
      63             : }
      64             : 
      65             : // Explicit instantiations
      66             : // NOLINTBEGIN(bugprone-macro-parentheses, cppcoreguidelines-macro-usage)
      67             : #define INSTANTIATE_TRANSFORMATION(SCALAR)                                                         \
      68             :     template struct Transformation<SCALAR>;                                                        \
      69             :     template class TransformationBuilderInterface<SCALAR>;
      70             : // NOLINTEND(bugprone-macro-parentheses, cppcoreguidelines-macro-usage)
      71             : 
      72             : INSTANTIATE_TRANSFORMATION(double)
      73             : INSTANTIATE_TRANSFORMATION(std::complex<double>)
      74             : 
      75             : #undef INSTANTIATE_TRANSFORMATION
      76             : } // namespace pairinteraction

Generated by: LCOV version 1.16