diff --git a/modules/algebra/include/VectorBaseD.h b/modules/algebra/include/VectorBaseD.h index 41f9d409a4..ec880a1753 100644 --- a/modules/algebra/include/VectorBaseD.h +++ b/modules/algebra/include/VectorBaseD.h @@ -27,15 +27,19 @@ #if IMP_HAS_CHECKS >= IMP_INTERNAL #define IMP_ALGEBRA_VECTOR_CHECK check_vector() +#define IMP_ALGEBRA_VECTOR_CHECK_OTHER(o) o.check_vector() #else #define IMP_ALGEBRA_VECTOR_CHECK +#define IMP_ALGEBRA_VECTOR_CHECK_OTHER(o) #endif +/* Should only need to check for "compatible" (same dimension) vectors + when using variable-dimension vectors; otherwise, it is checked at + compile time */ #if IMP_HAS_CHECKS >= IMP_USAGE #define IMP_ALGEBRA_VECTOR_CHECK_INDEX(i) check_index(i) #define IMP_ALGEBRA_VECTOR_CHECK_COMPATIBLE(o) \ - check_compatible_vector(o); \ - o.check_vector() + if (D == -1) { check_compatible_vector(o); } #else #define IMP_ALGEBRA_VECTOR_CHECK_INDEX(i) #define IMP_ALGEBRA_VECTOR_CHECK_COMPATIBLE(o) @@ -128,9 +132,10 @@ class VectorBaseD : public GeometricPrimitiveD { //! Default constructor VectorBaseD() {} - double get_scalar_product(const VectorBaseD &o) const { - IMP_ALGEBRA_VECTOR_CHECK_COMPATIBLE(o); + double get_scalar_product(const VectorBaseD &o) const { IMP_ALGEBRA_VECTOR_CHECK; + IMP_ALGEBRA_VECTOR_CHECK_OTHER(o); + IMP_ALGEBRA_VECTOR_CHECK_COMPATIBLE(o); double ret = 0; for (unsigned int i = 0; i < get_dimension(); ++i) { ret += operator[](i) * o.operator[](i); @@ -158,8 +163,9 @@ class VectorBaseD : public GeometricPrimitiveD { } VectorBaseD &operator+=(const VectorBaseD &o) { - IMP_ALGEBRA_VECTOR_CHECK_COMPATIBLE(o); IMP_ALGEBRA_VECTOR_CHECK; + IMP_ALGEBRA_VECTOR_CHECK_OTHER(o); + IMP_ALGEBRA_VECTOR_CHECK_COMPATIBLE(o); for (unsigned int i = 0; i < get_dimension(); ++i) { operator[](i) += o[i]; } @@ -167,8 +173,9 @@ class VectorBaseD : public GeometricPrimitiveD { } VectorBaseD &operator-=(const VectorBaseD &o) { - IMP_ALGEBRA_VECTOR_CHECK_COMPATIBLE(o); IMP_ALGEBRA_VECTOR_CHECK; + IMP_ALGEBRA_VECTOR_CHECK_OTHER(o); + IMP_ALGEBRA_VECTOR_CHECK_COMPATIBLE(o); for (unsigned int i = 0; i < get_dimension(); ++i) { operator[](i) -= o[i]; } diff --git a/modules/algebra/include/VectorD.h b/modules/algebra/include/VectorD.h index de5f12ce38..e4712e47ca 100644 --- a/modules/algebra/include/VectorD.h +++ b/modules/algebra/include/VectorD.h @@ -26,22 +26,6 @@ #include #include -#if IMP_HAS_CHECKS >= IMP_INTERNAL -#define IMP_ALGEBRA_VECTOR_CHECK check_vector() -#else -#define IMP_ALGEBRA_VECTOR_CHECK -#endif - -#if IMP_HAS_CHECKS >= IMP_USAGE -#define IMP_ALGEBRA_VECTOR_CHECK_INDEX(i) check_index(i) -#define IMP_ALGEBRA_VECTOR_CHECK_COMPATIBLE(o) \ - check_compatible_vector(o); \ - o.check_vector() -#else -#define IMP_ALGEBRA_VECTOR_CHECK_INDEX(i) -#define IMP_ALGEBRA_VECTOR_CHECK_COMPATIBLE(o) -#endif - IMPALGEBRA_BEGIN_NAMESPACE //! A Cartesian vector in D-dimensions. /** Store a vector of Cartesian coordinates. It supports all expected