Skip to content
Snippets Groups Projects
Commit 23d1c577 authored by Niklaus Johner's avatar Niklaus Johner
Browse files

Added operators for geom::Vec3List

parent 6fd32068
No related branches found
No related tags found
No related merge requests found
...@@ -95,6 +95,19 @@ void export_Vec3() ...@@ -95,6 +95,19 @@ void export_Vec3()
class_<Vec3List>("Vec3List", init<>()) class_<Vec3List>("Vec3List", init<>())
.def(vector_indexing_suite<Vec3List>()) .def(vector_indexing_suite<Vec3List>())
.def(geom::VectorAdditions<Vec3List>()) .def(geom::VectorAdditions<Vec3List>())
.def(self *= Real())
.def(self /= Real())
.def(self += Real())
.def(self += self)
.def(self -= self)
//.def(-self)
.def(self * Real())
.def(Real() * self)
.def(self / Real())
.def(self + self)
.def(self + Real())
.def(Real() + self)
.def(self - self)
.add_property("center", &Vec3List::GetCenter) .add_property("center", &Vec3List::GetCenter)
.add_property("inertia", &Vec3List::GetInertia) .add_property("inertia", &Vec3List::GetInertia)
.add_property("principal_axes", &Vec3List::GetPrincipalAxes) .add_property("principal_axes", &Vec3List::GetPrincipalAxes)
......
...@@ -207,7 +207,13 @@ namespace geom { ...@@ -207,7 +207,13 @@ namespace geom {
// TODO: move to separate file // TODO: move to separate file
class Mat3; class Mat3;
class DLLEXPORT_OST_GEOM Vec3List : public std::vector<Vec3> { class DLLEXPORT_OST_GEOM Vec3List :
public std::vector<Vec3>,
private boost::equality_comparable<Vec3List>,
private boost::additive<Vec3List>,
private boost::additive<Vec3List, Real>,
private boost::multiplicative<Vec3List, Real>
{
public: public:
typedef std::vector<Vec3> base_type; typedef std::vector<Vec3> base_type;
Vec3List() : base_type() {} Vec3List() : base_type() {}
...@@ -222,7 +228,67 @@ public: ...@@ -222,7 +228,67 @@ public:
base_type::operator=(rhs); base_type::operator=(rhs);
return *this; return *this;
} }
//! addable op
Vec3List& operator+=(const Vec3List& rhs)
{
for (unsigned int i=0;i!=this->size();++i) {
(*this)[i]+=(rhs)[i];
}
return *this;
}
Vec3List& operator+=(Real d)
{
for (unsigned int i=0;i!=this->size();++i) {
(*this)[i]+=d;
}
return *this;
}
//! subtractable op
Vec3List& operator-=(const Vec3List& rhs)
{
for (unsigned int i=0;i!=this->size();++i) {
(*this)[i]-=(rhs)[i];
}
return *this;
}
Vec3List& operator-=(Real d)
{
for (unsigned int i=0;i!=this->size();++i) {
(*this)[i]-=d;
}
return *this;
}
//! negateable
//Vec3List3 operator-() const
//{
// geom::Vec3List vl;
// for (unsigned int i=0;i!=this->size();++i) {
// geom::Vec3 v=(*this)[i];
// vl.push_back(-v);
// }
// return vl;
//}
//! multipliable
Vec3List& operator*=(Real d)
{
for (unsigned int i=0;i!=this->size();++i) {
(*this)[i]*=d;
}
return *this;
}
//! dividable
Vec3List& operator/=(Real d)
{
for (unsigned int i=0;i!=this->size();++i) {
(*this)[i]/=d;
}
return *this;
}
// TODO: move some or all of these to stand-alone functions // TODO: move some or all of these to stand-alone functions
Mat3 GetInertia() const; Mat3 GetInertia() const;
Vec3 GetCenter() const; Vec3 GetCenter() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment