Molassembler  1.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
AngleLookup.h
Go to the documentation of this file.
1 
18 #ifndef INCLUDE_SYMMETRIES_CONSTEXPR_ANGLES_H
19 #define INCLUDE_SYMMETRIES_CONSTEXPR_ANGLES_H
20 
22 
23 namespace Scine {
24 namespace Molassembler {
25 namespace Shapes {
26 namespace Detail {
27 
36 template<unsigned long size>
37 constexpr double makeElement(
38  const std::array<Temple::Vector, size>& positions,
39  const size_t i
40 ) {
41  // Get i-j matrix indices from the linear index
42  const auto indexPair = Temple::UpperTriangularMatrixImpl::index_conversion::toDoubleIndex<size>(i);
43 
44  // Calculate the angle
45  return Temple::angle(
46  positions[indexPair.first],
47  positions[indexPair.second]
48  );
49 }
50 
59 template<unsigned long size, size_t... Inds>
60 constexpr std::array<double, size * (size - 1) / 2> makeArrayImpl(
61  const std::array<Temple::Vector, size>& positions,
62  std::integer_sequence<size_t, Inds...> /* inds */
63 ) {
64  // Expand the parameter pack for each individual linear index
65  return {{ makeElement(positions, Inds)... }};
66 }
67 
78 template<unsigned long size>
79 constexpr std::array<double, size * (size - 1) / 2> makeArray(
80  const std::array<Temple::Vector, size>& positions
81 ) {
82  return makeArrayImpl(
83  positions,
84  std::make_index_sequence<size * (size - 1) / 2>{}
85  );
86 }
87 
88 } // namespace Detail
89 } // namespace Shapes
90 } // namespace Molassembler
91 } // namespace Scine
92 
93 #endif
unsigned size(const Shape shape)
Fetch the number of vertices of a shape.
PURITY_WEAK constexpr double angle(const Vector &a, const Vector &b)
Constexpr binary angle in radians calculation.
Definition: Vector.h:143
Matrix-like class that stores only upper triangular part.