LCOV - code coverage report
Current view: top level - pairinteraction - Symmetry.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 6 9 66.7 %
Date: 2024-04-29 00:41:50 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016 Sebastian Weber, Henri Menke. All rights reserved.
       3             :  *
       4             :  * This file is part of the pairinteraction library.
       5             :  *
       6             :  * The pairinteraction library is free software: you can redistribute it and/or modify
       7             :  * it under the terms of the GNU Lesser General Public License as published by
       8             :  * the Free Software Foundation, either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * The pairinteraction library is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU Lesser General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public License
      17             :  * along with the pairinteraction library. If not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #ifndef SYMMETRY_H
      21             : #define SYMMETRY_H
      22             : 
      23             : #include <array>
      24             : #include <climits>
      25             : 
      26             : enum parity_t {
      27             :     NA = INT_MAX,
      28             :     EVEN = 1,
      29             :     ODD = -1,
      30             : };
      31             : 
      32             : struct Symmetry {
      33             :     parity_t inversion;
      34             :     parity_t reflection;
      35             :     parity_t permutation;
      36             :     int rotation;
      37             : 
      38             :     // Comparison operator that is needed if an object of type Symmetry is used as key for std::map
      39           4 :     friend bool operator<(const Symmetry &s1, const Symmetry &s2) {
      40           4 :         std::array<int, 5> syms1{{s1.inversion, s1.reflection, s1.permutation, s1.rotation}};
      41           4 :         std::array<int, 5> syms2{{s2.inversion, s2.reflection, s2.permutation, s2.rotation}};
      42             : 
      43           4 :         for (size_t i = 0; i < syms1.size(); ++i) {
      44           4 :             if (syms1[i] < syms2[i]) {
      45           4 :                 return true;
      46             :             }
      47           0 :             if (syms1[i] > syms2[i]) {
      48           0 :                 return false;
      49             :             }
      50             :         }
      51           0 :         return false;
      52             :     }
      53             : };
      54             : 
      55             : #endif

Generated by: LCOV version 1.14