From 5a735ce65873e995c9d4dc60badff171f9b25a4a Mon Sep 17 00:00:00 2001 From: Niklaus Johner <nij2003@med.cornell.edu> Date: Thu, 2 May 2013 13:22:42 -0400 Subject: [PATCH] Made behavior of Vec3List more numpy like --- modules/geom/pymod/export_vec3.cc | 2 ++ modules/geom/src/vec3.hh | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/geom/pymod/export_vec3.cc b/modules/geom/pymod/export_vec3.cc index 1f1e20662..0df810154 100644 --- a/modules/geom/pymod/export_vec3.cc +++ b/modules/geom/pymod/export_vec3.cc @@ -108,6 +108,8 @@ void export_Vec3() .def(self + Real()) .def(Real() + self) .def(self - self) + .def(self == self) + .def(self != self) .add_property("center", &Vec3List::GetCenter) .add_property("inertia", &Vec3List::GetInertia) .add_property("principal_axes", &Vec3List::GetPrincipalAxes) diff --git a/modules/geom/src/vec3.hh b/modules/geom/src/vec3.hh index 647b4bdd1..58e63b892 100644 --- a/modules/geom/src/vec3.hh +++ b/modules/geom/src/vec3.hh @@ -228,9 +228,25 @@ public: base_type::operator=(rhs); return *this; } + //! comparable + bool operator==(const Vec3List& rhs) const + { + if (this->size()!=rhs.size()){ + throw std::length_error("Vec3List must have the same size"); + } + for (unsigned int i=0;i!=this->size();++i) { + if (((*this)[i])!=((rhs)[i])){ + return false; + } + } + return true; + } //! addable op Vec3List& operator+=(const Vec3List& rhs) { + if (this->size()!=rhs.size()){ + throw std::length_error("Vec3List must have the same size"); + } for (unsigned int i=0;i!=this->size();++i) { (*this)[i]+=(rhs)[i]; } @@ -246,7 +262,10 @@ public: //! subtractable op Vec3List& operator-=(const Vec3List& rhs) - { + { + if (this->size()!=rhs.size()){ + throw std::length_error("Vec3List must have the same size"); + } for (unsigned int i=0;i!=this->size();++i) { (*this)[i]-=(rhs)[i]; } -- GitLab