IMP logo
IMP Reference Guide  2.22.0
The Integrative Modeling Platform
algebra_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/algebra_macros.h
3  * \brief Various helper macros.
4  *
5  * Copyright 2007-2024 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPALGEBRA_MACROS_H
10 #define IMPALGEBRA_MACROS_H
12 #include <boost/range/iterator_range.hpp>
13 
14 #ifdef SWIG
15 #define IMP_ALGEBRA_VECTOR_SWIG_METHODS(D) VectorD(const Floats &f);
16 #else
17 #define IMP_ALGEBRA_VECTOR_SWIG_METHODS(D) \
18  template <class R> \
19  VectorD &operator=(const R &o) { \
20  P::operator=(o); \
21  return *this; \
22  }
23 
24 #endif
25 
26 #define IMP_ALGEBRA_VECTOR_METHODS(D) \
27  typedef VectorBaseD<D> P; \
28  \
29  public: \
30  /** \brief Will accept a list of floats from Python. */ \
31  template <class Range> \
32  explicit VectorD(const Range &r) \
33  : P(r) {} \
34  template <int OD> \
35  VectorD(const VectorD<OD> &o) \
36  : P(o) { \
37  static_assert(OD == D || OD == -1 || D == -1, \
38  "VectorD size mismatch"); \
39  } \
40  IMP_ALGEBRA_VECTOR_SWIG_METHODS(D); \
41  /** The distance between b and e must be equal to D. \
42  */ \
43  template <class It> \
44  VectorD(It b, It e) \
45  : P(boost::make_iterator_range(b, e)) {} \
46  VectorD() {} \
47  VectorD get_unit_vector() const { return algebra::get_unit_vector(*this); } \
48  VectorD operator*(double s) const { \
49  VectorD ret(*this); \
50  ret *= s; \
51  return ret; \
52  } \
53  VectorD operator/(double s) const { \
54  VectorD ret(*this); \
55  ret /= s; \
56  return ret; \
57  } \
58  VectorD operator-() const { \
59  VectorD ret(*this); \
60  ret *= -1; \
61  return ret; \
62  } \
63  VectorD operator-(const VectorD &o) const { \
64  VectorD ret(*this); \
65  ret -= o; \
66  return ret; \
67  } \
68  VectorD operator+(VectorD ret) const { \
69  ret += *this; \
70  return ret; \
71  } \
72  VectorD &operator+=(const VectorD &o) { \
73  P::operator+=(o); \
74  return *this; \
75  } \
76  VectorD &operator-=(const VectorD &o) { \
77  P::operator-=(o); \
78  return *this; \
79  } \
80  VectorD &operator/=(double f) { \
81  P::operator/=(f); \
82  return *this; \
83  } \
84  VectorD &operator*=(double f) { \
85  P::operator*=(f); \
86  return *this; \
87  } \
88  /* for swig as it doesn't like using. */ \
89  double operator*(const VectorD &o) const { return P::operator*(o); }
90 
91 #endif /* IMPALGEBRA_MACROS_H */
Various important macros for implementing geometry.