/* Provide our own implementations for some operators */ %ignore IMP::algebra::VectorD::operator[]; %ignore IMP::algebra::VectorD::operator+=; %ignore IMP::algebra::VectorD::operator*=; %ignore IMP::algebra::VectorD::operator/=; %ignore IMP::algebra::VectorD::operator-=; /* Make sure that we return the original Python object from C++ inplace operators (not a new Python proxy around the same C++ object) */ namespace IMP { namespace algebra { %feature("shadow") VectorD::__iadd__(const IMP::algebra::VectorD &) %{ def __iadd__(self, *args): $action(self, *args) return self %} %feature("shadow") VectorD::__imul__(double) %{ def __imul__(self, *args): $action(self, *args) return self %} %feature("shadow") VectorD::__idiv__(double) %{ def __idiv__(self, *args): $action(self, *args) return self %} %feature("shadow") VectorD::__isub__(const IMP::algebra::VectorD &) %{ def __isub__(self, *args): $action(self, *args) return self %} } } %extend IMP::algebra::VectorD { double __getitem__(unsigned int index) const { if (index >= D) throw IMP::IndexException(""); return self->operator[](index); } void __setitem__(unsigned int index, double val) { self->operator[](index) = val; } /* Ignore C++ return value from inplace operators, so that SWIG does not generate a new SWIG wrapper for the return value (see above). */ void __iadd__(const IMP::algebra::VectorD &o) { self->operator+=(o); } void __imul__(double f) { self->operator*=(f); } void __idiv__(double f) { self->operator/=(f); } void __isub__(const IMP::algebra::VectorD &o) { self->operator-=(o); } unsigned int __len__() {return D;} const IMP::algebra::VectorD __rmul__(double f) const {return self->operator*(f);} }; %include "IMP/algebra/VectorD.h" %include "IMP/algebra/Vector2D.h" %include "IMP/algebra/Vector3D.h" namespace IMP { namespace algebra { %template(Vector2D) VectorD<2>; %template(Vector3D) VectorD<3>; %template(Vector4D) VectorD<4>; %template(get_distance) get_distance<3>; %template(get_squared_distance) get_squared_distance<3>; %template(get_distance) get_distance<4>; %template(get_squared_distance) get_squared_distance<4>; %template(get_distance) get_distance<2>; %template(get_squared_distance) get_squared_distance<2>; %template(Vector4Ds) ::std::vector >; %template(Vector3Ds) ::std::vector >; %template(Vector2Ds) ::std::vector >; } }