yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #04274
[Branch ~yade-dev/yade/trunk] Rev 2199: 1. Add docs for kineticEnergy
------------------------------------------------------------
revno: 2199
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Tue 2010-05-04 23:57:09 +0200
message:
1. Add docs for kineticEnergy
2. Complete wrapper for Eigen in Python (will be renamed from miniWm3Wrap to yade.math or similar later), passes scripts/regression-test.py now
modified:
SConstruct
debian/control-template
debian/rules
lib/base/Math.hpp
py/_utils.cpp
py/miniWm3Wrap/manualWrap.cpp
--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription
=== modified file 'SConstruct'
--- SConstruct 2010-05-03 13:58:09 +0000
+++ SConstruct 2010-05-04 21:57:09 +0000
@@ -139,7 +139,7 @@
BoolVariable('optimize','Turn on heavy optimizations',defOptions['optimize']),
ListVariable('exclude','Yade components that will not be built','none',names=['gui','extra','common','dem','lattice','snow']),
EnumVariable('PGO','Whether to "gen"erate or "use" Profile-Guided Optimization','',['','gen','use'],{'no':'','0':'','false':''},1),
- ListVariable('features','Optional features that are turned on','log4cxx,opengl,gts,openmp,vtk',names=['opengl','log4cxx','cgal','openmp','gts','vtk','python','eigen','nowm3','eigen-compat','gl2ps','boost-serialization','never_use_this_one']),
+ ListVariable('features','Optional features that are turned on','log4cxx,opengl,gts,openmp,vtk',names=['opengl','log4cxx','cgal','openmp','gts','vtk','python','eigen','nowm3','gl2ps','boost-serialization','never_use_this_one']),
('jobs','Number of jobs to run at the same time (same as -j, but saved)',2,None,int),
#('extraModules', 'Extra directories with their own SConscript files (must be in-tree) (whitespace separated)',None,None,Split),
('buildPrefix','Where to create build-[version][variant] directory for intermediary files','..'),
=== modified file 'debian/control-template'
--- debian/control-template 2010-01-09 17:26:41 +0000
+++ debian/control-template 2010-05-04 21:57:09 +0000
@@ -2,7 +2,7 @@
Section: x11
Priority: optional
Maintainer: Václav Šmilauer <eudoxos@xxxxxxxx>
-Build-Depends: debhelper (>= 5), scons, libqt3-mt-dev, qt3-dev-tools, freeglut3-dev, libboost-dev (>=1.34), libboost-date-time-dev (>=1.34), libboost-filesystem-dev (>=1.34), libboost-thread-dev (>=1.34), libboost-regex-dev (>=1.34), libboost-python-dev (>=1.34), libboost-iostreams-dev (>=1.34), libboost-program-options-dev, libboost-serialization-dev, liblog4cxx9-dev | liblog4cxx10-dev, docbook-to-man, ipython, libsqlite3-dev, libgts-dev, python-numpy, g++(>4.0), libvtk5-dev, libgl1-mesa-swx11-dev, gdb, ipython, python-matplotlib, python-tk
+Build-Depends: debhelper (>= 5), scons, libqt3-mt-dev, qt3-dev-tools, freeglut3-dev, libboost-dev (>=1.34), libboost-date-time-dev (>=1.34), libboost-filesystem-dev (>=1.34), libboost-thread-dev (>=1.34), libboost-regex-dev (>=1.34), libboost-python-dev (>=1.34), libboost-iostreams-dev (>=1.34), libboost-program-options-dev, libboost-serialization-dev, liblog4cxx9-dev | liblog4cxx10-dev, docbook-to-man, ipython, libsqlite3-dev, libgts-dev, python-numpy, g++(>4.0), libvtk5-dev, libgl1-mesa-swx11-dev, gdb, ipython, python-matplotlib, python-tk, libeigen2-dev
Standards-Version: 3.7.2
Package: yade@_VERSION@
=== modified file 'debian/rules'
--- debian/rules 2010-04-01 06:53:09 +0000
+++ debian/rules 2010-05-04 21:57:09 +0000
@@ -60,7 +60,7 @@
### (a) use fakeroot-tcp instead of fakeroot
### (b) use just 1 job
#debug build
- NO_SCONS_GET_RECENT= scons buildPrefix=debian runtimePREFIX=/usr version=${VERSION} brief=0 chunkSize=4 linkStrategy=monolithic features=vtk,gts,log4cxx,opengl,openmp exclude=snow PREFIX=debian/yade${_VERSION}-dbg/usr variant=-dbg optimize=0 march= debug=1 CPPPATH=/usr/include/vtk-5.0:/usr/include/vtk-5.2:/usr/include/vtk-5.4 jobs=1
+ NO_SCONS_GET_RECENT= scons buildPrefix=debian runtimePREFIX=/usr version=${VERSION} brief=0 chunkSize=4 linkStrategy=monolithic features=vtk,gts,log4cxx,opengl,openmp,eigen exclude=snow PREFIX=debian/yade${_VERSION}-dbg/usr variant=-dbg optimize=0 march= debug=1 CPPPATH=/usr/include/vtk-5.0:/usr/include/vtk-5.2:/usr/include/vtk-5.4 jobs=1
#optimized build
NO_SCONS_GET_RECENT= scons PREFIX=debian/yade${_VERSION}/usr variant='' optimize=1 debug=0
#install platform-independent files (docs, scripts, examples)
=== modified file 'lib/base/Math.hpp'
--- lib/base/Math.hpp 2010-05-04 15:52:56 +0000
+++ lib/base/Math.hpp 2010-05-04 21:57:09 +0000
@@ -30,6 +30,7 @@
#define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
#include<Eigen/Core>
#include<Eigen/Geometry>
+ #include<Eigen/Array>
#include<Eigen/QR>
#include<Eigen/LU>
#include<float.h>
@@ -75,6 +76,12 @@
template<typename Scalar> MATRIX3_TEMPLATE(Scalar) matrixFromEulerAnglesXYZ(Scalar x, Scalar y, Scalar z){ MATRIX3_TEMPLATE(Scalar) m; m=AngleAxis<Scalar>(x,VECTOR3_TEMPLATE(Scalar)::UnitX())*AngleAxis<Scalar>(y,VECTOR3_TEMPLATE(Scalar)::UnitY())*AngleAxis<Scalar>(z,VECTOR3_TEMPLATE(Scalar)::UnitZ()); return m;}
template<typename Scalar> bool operator==(const Quaternion<Scalar>& u, const Quaternion<Scalar>& v){ return u.x()==v.x() && u.y()==v.y() && u.z()==v.z() && u.w()==v.w(); }
template<typename Scalar> bool operator!=(const Quaternion<Scalar>& u, const Quaternion<Scalar>& v){ return !(u==v); }
+ template<typename Scalar> bool operator==(const MATRIX3_TEMPLATE(Scalar)& m, const MATRIX3_TEMPLATE(Scalar)& n){ for(int i=0;i<3;i++)for(int j=0;j<3;j++)if(m(i,j)!=n(i,j)) return false; return true; }
+ template<typename Scalar> bool operator!=(const MATRIX3_TEMPLATE(Scalar)& m, const MATRIX3_TEMPLATE(Scalar)& n){ return !(m==n); }
+ template<typename Scalar> bool operator==(const VECTOR3_TEMPLATE(Scalar)& u, const VECTOR3_TEMPLATE(Scalar)& v){ return u.x()==v.x() && u.y()==v.y() && u.z()==v.z(); }
+ template<typename Scalar> bool operator!=(const VECTOR3_TEMPLATE(Scalar)& u, const VECTOR3_TEMPLATE(Scalar)& v){ return !(u==v); }
+ template<typename Scalar> bool operator==(const VECTOR2_TEMPLATE(Scalar)& u, const VECTOR2_TEMPLATE(Scalar)& v){ return u.x()==v.x() && u.y()==v.y(); }
+ template<typename Scalar> bool operator!=(const VECTOR2_TEMPLATE(Scalar)& u, const VECTOR2_TEMPLATE(Scalar)& v){ return !(u==v); }
template<typename Scalar> Quaternion<Scalar> operator*(Scalar f, const Quaternion<Scalar>& q){ return Quaternion<Scalar>(q.coeffs()*f); }
template<typename Scalar> Quaternion<Scalar> operator+(Quaternion<Scalar> q1, const Quaternion<Scalar>& q2){ return Quaternion<Scalar>(q1.coeffs()+q2.coeffs()); } /* replace all those by standard math functions
this is a non-templated version, to avoid compilation because of static constants;
=== modified file 'py/_utils.cpp'
--- py/_utils.cpp 2010-05-04 13:56:05 +0000
+++ py/_utils.cpp 2010-05-04 21:57:09 +0000
@@ -431,7 +431,7 @@
py::def("inscribedCircleCenter",inscribedCircleCenter,(py::arg("v1"),py::arg("v2"),py::arg("v3")),"Return center of inscribed circle for triangle given by its vertices *v1*, *v2*, *v3*.");
py::def("getViscoelasticFromSpheresInteraction",getViscoelasticFromSpheresInteraction);
py::def("unbalancedForce",&Shop::unbalancedForce,unbalancedForce_overloads(py::args("useMaxForce")));
- py::def("kineticEnergy",Shop__kineticEnergy);
+ py::def("kineticEnergy",Shop__kineticEnergy,"Compute overall kinetic energy of the simulation as\n\n.. math:: \\sum\\frac{1}{2}\\left(m_i\\vec{v}_i^2+\\vec{\\omega}(\\mat{I}\\vec{\\omega}^T)\\right).\n\n.. warning::\n\n\tNo transformation of inertia tensor (in local frame) $\\mat{I}$ is done, although it is multiplied by angular velocity $\\vec{\\omega}$ (in global frame); the value will not be accurate for aspherical particles.\n");
py::def("sumForces",sumForces);
py::def("sumTorques",sumTorques);
py::def("sumFacetNormalForces",sumFacetNormalForces,(py::arg("axis")=-1));
=== modified file 'py/miniWm3Wrap/manualWrap.cpp'
--- py/miniWm3Wrap/manualWrap.cpp 2010-05-04 13:56:05 +0000
+++ py/miniWm3Wrap/manualWrap.cpp 2010-05-04 21:57:09 +0000
@@ -12,308 +12,290 @@
#define IDX_CHECK(i,MAX){ if(i<0 || i>=MAX) { PyErr_SetString(PyExc_IndexError, ("Index out of range 0.." + boost::lexical_cast<std::string>(MAX-1)).c_str()); bp::throw_error_already_set(); } }
#define IDX2_CHECKED_TUPLE_INTS(tuple,max2,arr2) {int l=bp::len(tuple); if(l!=2) { PyErr_SetString(PyExc_IndexError,"Index must be integer or a 2-tuple"); bp::throw_error_already_set(); } for(int _i=0; _i<2; _i++) { bp::extract<int> val(tuple[_i]); if(!val.check()) throw std::runtime_error("Unable to convert "+boost::lexical_cast<std::string>(_i)+"-th index to int."); int v=val(); IDX_CHECK(v,max2[_i]); arr2[_i]=v; } }
-void Vector2_set_item(Vector2r & self, int idx, Real value){ IDX_CHECK(idx,2); self[idx]=value; }
-void Vector3_set_item(Vector3r & self, int idx, Real value){ IDX_CHECK(idx,3); self[idx]=value; }
-void Quaternion_set_item(Quaternionr & self, int idx, Real value){ IDX_CHECK(idx,4); if(idx==0) self.w()=value; else if(idx==1) self.x()=value; else if(idx==2) self.y()=value; else if(idx==3) self.z()=value; }
-void Matrix3_set_item(Matrix3r & self, bp::tuple _idx, Real value){ int idx[2]; int mx[2]={3,3}; IDX2_CHECKED_TUPLE_INTS(_idx,mx,idx); self(idx[0],idx[1])=value; }
-void Matrix3_set_item_linear(Matrix3r & self, int idx, Real value){ IDX_CHECK(idx,9); self(idx/3,idx%3)=value; }
-
-Real Vector2_get_item(const Vector2r & self, int idx){ IDX_CHECK(idx,2); return self[idx]; }
-Real Vector3_get_item(const Vector3r & self, int idx){ IDX_CHECK(idx,3); return self[idx]; }
-Real Quaternion_get_item(const Quaternionr & self, int idx){ IDX_CHECK(idx,4); if(idx==0) return self.w(); if(idx==1) return self.x(); if(idx==2) return self.y(); return self.z(); }
-Real Matrix3_get_item(Matrix3r & self, bp::tuple _idx){ int idx[2]; int mx[2]={3,3}; IDX2_CHECKED_TUPLE_INTS(_idx,mx,idx); return self(idx[0],idx[1]); }
-Real Matrix3_get_item_linear(Matrix3r & self, int idx){ IDX_CHECK(idx,9); return self(idx/3,idx%3); }
-
-std::string Vector2_str(const Vector2r & self){ return std::string("Vector2(")+boost::lexical_cast<std::string>(self[0])+","+boost::lexical_cast<std::string>(self[1])+")";}
-std::string Vector3_str(const Vector3r & self){ return std::string("Vector3(")+boost::lexical_cast<std::string>(self[0])+","+boost::lexical_cast<std::string>(self[1])+","+boost::lexical_cast<std::string>(self[2])+")";}
-std::string Quaternion_str(const Quaternionr & self){ AngleAxisr aa(angleAxisFromQuat(self)); return std::string("Quaternion((")+boost::lexical_cast<std::string>(aa.axis()[0])+","+boost::lexical_cast<std::string>(aa.axis()[1])+","+boost::lexical_cast<std::string>(aa.axis()[2])+"),"+boost::lexical_cast<std::string>(aa.angle())+")";}
-std::string Matrix3_str(const Matrix3r & self){ std::ostringstream oss; oss<<"Matrix3("; for(int i=0; i<3; i++) for(int j=0; j<3; j++) oss<<self(i,j)<<((i==2 && j==2)?")":",")<<((i<2 && j==2)?" ":""); return oss.str(); }
-
-int Vector2_len(){return 2;}
-int Vector3_len(){return 3;}
-int Quaternion_len(){return 4;}
-int Matrix3_len(){return 9;}
+void Vector3r_set_item(Vector3r & self, int idx, Real value){ IDX_CHECK(idx,3); self[idx]=value; }
+void Vector3i_set_item(Vector3i & self, int idx, int value){ IDX_CHECK(idx,3); self[idx]=value; }
+void Vector2r_set_item(Vector2r & self, int idx, Real value){ IDX_CHECK(idx,2); self[idx]=value; }
+void Vector2i_set_item(Vector2i & self, int idx, int value){ IDX_CHECK(idx,2); self[idx]=value; }
+
+void Quaternionr_set_item(Quaternionr & self, int idx, Real value){ IDX_CHECK(idx,4); if(idx==0) self.w()=value; else if(idx==1) self.x()=value; else if(idx==2) self.y()=value; else if(idx==3) self.z()=value; }
+void Matrix3r_set_item(Matrix3r & self, bp::tuple _idx, Real value){ int idx[2]; int mx[2]={3,3}; IDX2_CHECKED_TUPLE_INTS(_idx,mx,idx); self(idx[0],idx[1])=value; }
+void Matrix3r_set_item_linear(Matrix3r & self, int idx, Real value){ IDX_CHECK(idx,9); self(idx/3,idx%3)=value; }
+
+Real Vector3r_get_item(const Vector3r & self, int idx){ IDX_CHECK(idx,3); return self[idx]; }
+int Vector3i_get_item(const Vector3r & self, int idx){ IDX_CHECK(idx,3); return self[idx]; }
+Real Vector2r_get_item(const Vector2r & self, int idx){ IDX_CHECK(idx,2); return self[idx]; }
+int Vector2i_get_item(const Vector2r & self, int idx){ IDX_CHECK(idx,2); return self[idx]; }
+
+Real Quaternionr_get_item(const Quaternionr & self, int idx){ IDX_CHECK(idx,4); if(idx==0) return self.w(); if(idx==1) return self.x(); if(idx==2) return self.y(); return self.z(); }
+Real Matrix3r_get_item(Matrix3r & self, bp::tuple _idx){ int idx[2]; int mx[2]={3,3}; IDX2_CHECKED_TUPLE_INTS(_idx,mx,idx); return self(idx[0],idx[1]); }
+Real Matrix3r_get_item_linear(Matrix3r & self, int idx){ IDX_CHECK(idx,9); return self(idx/3,idx%3); }
+
+std::string Vector3r_str(const Vector3r & self){ return std::string("Vector3(")+boost::lexical_cast<std::string>(self[0])+","+boost::lexical_cast<std::string>(self[1])+","+boost::lexical_cast<std::string>(self[2])+")";}
+std::string Vector3i_str(const Vector3i & self){ return std::string("Vector3i(")+boost::lexical_cast<std::string>(self[0])+","+boost::lexical_cast<std::string>(self[1])+","+boost::lexical_cast<std::string>(self[2])+")";}
+std::string Vector2r_str(const Vector2r & self){ return std::string("Vector2(")+boost::lexical_cast<std::string>(self[0])+","+boost::lexical_cast<std::string>(self[1])+")";}
+std::string Vector2i_str(const Vector2i & self){ return std::string("Vector2i(")+boost::lexical_cast<std::string>(self[0])+","+boost::lexical_cast<std::string>(self[1])+")";}
+std::string Quaternionr_str(const Quaternionr & self){ AngleAxisr aa(angleAxisFromQuat(self)); return std::string("Quaternion((")+boost::lexical_cast<std::string>(aa.axis()[0])+","+boost::lexical_cast<std::string>(aa.axis()[1])+","+boost::lexical_cast<std::string>(aa.axis()[2])+"),"+boost::lexical_cast<std::string>(aa.angle())+")";}
+std::string Matrix3r_str(const Matrix3r & self){ std::ostringstream oss; oss<<"Matrix3("; for(int i=0; i<3; i++) for(int j=0; j<3; j++) oss<<self(i,j)<<((i==2 && j==2)?")":",")<<((i<2 && j==2)?" ":""); return oss.str(); }
+
+int Vector3r_len(){return 3;}
+int Vector3i_len(){return 3;}
+int Vector2r_len(){return 2;}
+int Vector2i_len(){return 2;}
+int Quaternionr_len(){return 4;}
+int Matrix3r_len(){return 9;}
#undef IDX_CHECK
-#if 0
- // workarounds for static methods; disabled for now, see comment in miniWm3Wrap-generate.py
- #define _WORKAROUND(clss,member) clss clss##_##member(const clss& self){return clss::member;}
- _WORKAROUND(Vector2r,ONE); _WORKAROUND(Vector2r,UNIT_X); _WORKAROUND(Vector2r,UNIT_Y); _WORKAROUND(Vector2r,ZERO);
- _WORKAROUND(Vector3r,ONE); _WORKAROUND(Vector3r,UNIT_X); _WORKAROUND(Vector3r,UNIT_Y); _WORKAROUND(Vector3r,UNIT_Z); _WORKAROUND(Vector3r,ZERO);
- _WORKAROUND(Quaternionr,IDENTITY); _WORKAROUND(Quaternionr,ZERO);
- _WORKAROUND(Matrix3r,IDENTITY); _WORKAROUND(Matrix3r,ZERO);
- #undef _WORKAROUND
-#endif
-
-// automagic converter from tuple to Vector3r
+// automagic converters from tuple to Vector{2,3}{r,i}
struct custom_Vector3r_from_tuple{
- custom_Vector3r_from_tuple(){
- bp::converter::registry::push_back(&convertible,&construct,bp::type_id<Vector3r>());
- }
- static void* convertible(PyObject* obj_ptr){
- if(!PySequence_Check(obj_ptr) || PySequence_Size(obj_ptr)!=3) return 0;
- return obj_ptr;
- }
+ custom_Vector3r_from_tuple(){ bp::converter::registry::push_back(&convertible,&construct,bp::type_id<Vector3r>()); }
+ static void* convertible(PyObject* obj_ptr){ if(!PySequence_Check(obj_ptr) || PySequence_Size(obj_ptr)!=3) return 0; return obj_ptr; }
static void construct(PyObject* obj_ptr, bp::converter::rvalue_from_python_stage1_data* data){
void* storage=((bp::converter::rvalue_from_python_storage<Vector3r>*)(data))->storage.bytes;
new (storage) Vector3r(bp::extract<Real>(PySequence_GetItem(obj_ptr,0)),bp::extract<Real>(PySequence_GetItem(obj_ptr,1)),bp::extract<Real>(PySequence_GetItem(obj_ptr,2)));
data->convertible=storage;
}
};
-
-
-//static bp::tuple Quaternion_ToAxisAngle(const Quaternionr& q){
-// AngleAxisr aa(angleAxisFromQuat(q));
-// return bp::make_tuple(aa.axis(),aa.angle());
-//}
+struct custom_Vector3i_from_tuple{
+ custom_Vector3i_from_tuple(){ bp::converter::registry::push_back(&convertible,&construct,bp::type_id<Vector3i>()); }
+ static void* convertible(PyObject* obj_ptr){ if(!PySequence_Check(obj_ptr) || PySequence_Size(obj_ptr)!=3) return 0; return obj_ptr; }
+ static void construct(PyObject* obj_ptr, bp::converter::rvalue_from_python_stage1_data* data){
+ void* storage=((bp::converter::rvalue_from_python_storage<Vector3i>*)(data))->storage.bytes;
+ new (storage) Vector3i(bp::extract<int>(PySequence_GetItem(obj_ptr,0)),bp::extract<int>(PySequence_GetItem(obj_ptr,1)),bp::extract<int>(PySequence_GetItem(obj_ptr,2)));
+ data->convertible=storage;
+ }
+};
+struct custom_Vector2r_from_tuple{
+ custom_Vector2r_from_tuple(){ bp::converter::registry::push_back(&convertible,&construct,bp::type_id<Vector2r>()); }
+ static void* convertible(PyObject* obj_ptr){ if(!PySequence_Check(obj_ptr) || PySequence_Size(obj_ptr)!=2) return 0; return obj_ptr; }
+ static void construct(PyObject* obj_ptr, bp::converter::rvalue_from_python_stage1_data* data){
+ void* storage=((bp::converter::rvalue_from_python_storage<Vector2r>*)(data))->storage.bytes;
+ new (storage) Vector2r(bp::extract<Real>(PySequence_GetItem(obj_ptr,0)),bp::extract<Real>(PySequence_GetItem(obj_ptr,1)));
+ data->convertible=storage;
+ }
+};
+struct custom_Vector2i_from_tuple{
+ custom_Vector2i_from_tuple(){ bp::converter::registry::push_back(&convertible,&construct,bp::type_id<Vector2i>()); }
+ static void* convertible(PyObject* obj_ptr){ if(!PySequence_Check(obj_ptr) || PySequence_Size(obj_ptr)!=2) return 0; return obj_ptr; }
+ static void construct(PyObject* obj_ptr, bp::converter::rvalue_from_python_stage1_data* data){
+ void* storage=((bp::converter::rvalue_from_python_storage<Vector2i>*)(data))->storage.bytes;
+ new (storage) Vector2i(bp::extract<int>(PySequence_GetItem(obj_ptr,0)),bp::extract<int>(PySequence_GetItem(obj_ptr,1)));
+ data->convertible=storage;
+ }
+};
+
+static Matrix3r* Matrix3r_fromElements(Real m00, Real m01, Real m02, Real m10, Real m11, Real m12, Real m20, Real m21, Real m22){ Matrix3r* m(new Matrix3r); (*m)<<m00,m01,m02,m10,m11,m12,m20,m21,m22; return m; }
static Quaternionr Quaternionr_setFromTwoVectors(Quaternionr& q, const Vector3r& u, const Vector3r& v){ return q.setFromTwoVectors(u,v); }
+static Quaternionr* Quaternionr_fromAxisAngle(const Vector3r& axis, const Real angle){ return new Quaternionr(AngleAxisr(angle,axis)); }
+static Quaternionr* Quaternionr_fromAngleAxis(const Real angle, const Vector3r& axis){ return new Quaternionr(AngleAxisr(angle,axis)); }
+static bp::tuple Quaternionr_toAxisAngle(const Quaternionr& self){ AngleAxisr aa(self); return bp::make_tuple(aa.axis(),aa.angle());}
+static bp::tuple Quaternionr_toAngleAxis(const Quaternionr& self){ AngleAxisr aa(self); return bp::make_tuple(aa.angle(),aa.axis());}
+static void Matrix3r_fromAxisAngle(Matrix3r& self, const Vector3r& axis, const Real angle){ self=AngleAxisr(angle,axis).toRotationMatrix(); }
+
static Real Vector3r_dot(const Vector3r& self, const Vector3r& v){ return self.dot(v); }
+static Real Vector3i_dot(const Vector3i& self, const Vector3i& v){ return self.dot(v); }
static Real Vector2r_dot(const Vector2r& self, const Vector2r& v){ return self.dot(v); }
+static Real Vector2i_dot(const Vector2i& self, const Vector2i& v){ return self.dot(v); }
static Vector3r Vector3r_cross(const Vector3r& self, const Vector3r& v){ return self.cross(v); }
+static Vector3i Vector3i_cross(const Vector3i& self, const Vector3i& v){ return self.cross(v); }
+static bool Quaternionr__eq__(const Quaternionr& q1, const Quaternionr& q2){ return q1==q2; }
+static bool Quaternionr__neq__(const Quaternionr& q1, const Quaternionr& q2){ return q1!=q2; }
+
#define EIG_WRAP_METH1(klass,meth) static klass klass##_##meth(const klass& self){ return self.meth(); }
-#define EIG_WRAP_METH0(klass,meth) static klass klass##_##meth(){ return klass().meth(); }
+//#define EIG_WRAP_METH0(klass,meth) static klass klass##_##meth(){ return klass().meth(); }
+#define EIG_WRAP_METH0(klass,meth) static const klass klass##_##meth=klass().meth();
EIG_WRAP_METH1(Matrix3r,transpose);
EIG_WRAP_METH1(Matrix3r,inverse);
+
EIG_WRAP_METH0(Matrix3r,Zero);
EIG_WRAP_METH0(Matrix3r,Identity);
+EIG_WRAP_METH0(Vector3r,Zero); EIG_WRAP_METH0(Vector3r,UnitX); EIG_WRAP_METH0(Vector3r,UnitY); EIG_WRAP_METH0(Vector3r,UnitZ); EIG_WRAP_METH0(Vector3r,Ones);
+EIG_WRAP_METH0(Vector3i,Zero); EIG_WRAP_METH0(Vector3i,UnitX); EIG_WRAP_METH0(Vector3i,UnitY); EIG_WRAP_METH0(Vector3i,UnitZ); EIG_WRAP_METH0(Vector3i,Ones);
+EIG_WRAP_METH0(Vector2r,Zero); EIG_WRAP_METH0(Vector2r,UnitX); EIG_WRAP_METH0(Vector2r,UnitY); EIG_WRAP_METH0(Vector2r,Ones);
+EIG_WRAP_METH0(Vector2i,Zero); EIG_WRAP_METH0(Vector2i,UnitX); EIG_WRAP_METH0(Vector2i,UnitY); EIG_WRAP_METH0(Vector2i,Ones);
EIG_WRAP_METH0(Quaternionr,Identity);
-EIG_WRAP_METH1(Quaternionr,inverse);
-EIG_WRAP_METH1(Quaternionr,conjugate);
-EIG_WRAP_METH0(Vector3r,Zero);
-EIG_WRAP_METH0(Vector3r,UnitX);
-EIG_WRAP_METH0(Vector3r,UnitY);
-EIG_WRAP_METH0(Vector3r,UnitZ);
-EIG_WRAP_METH0(Vector3r,Ones);
-EIG_WRAP_METH0(Vector2r,Zero);
-EIG_WRAP_METH0(Vector2r,UnitX);
-EIG_WRAP_METH0(Vector2r,UnitY);
-EIG_WRAP_METH0(Vector2r,Ones);
#define EIG_OP1(klass,op,sym) typeof((sym klass()).eval()) klass##op(const klass& self){ return (sym self).eval();}
#define EIG_OP2(klass,op,sym,klass2) typeof((klass() sym klass2()).eval()) klass##op##klass2(const klass& self, const klass2& other){ return (self sym other).eval(); }
#define EIG_OP2_INPLACE(klass,op,sym,klass2) void klass##op##klass2(klass& self, const klass2& other){ self sym other; }
-EIG_OP2(Matrix3r,__add__,+,Matrix3r)
-EIG_OP2(Matrix3r,__sub__,-,Matrix3r)
-EIG_OP2(Matrix3r,__mul__,*,Real)
-EIG_OP2(Matrix3r,__rmul__,*,Real)
-//EIG_OP2(Matrix3r,__mul__,*,Matrix3r)
-EIG_OP2(Matrix3r,__div__,/,Real)
-EIG_OP2_INPLACE(Matrix3r,__iadd__,+=,Matrix3r)
-EIG_OP2_INPLACE(Matrix3r,__isub__,-=,Matrix3r)
-//EIG_OP2_INPLACE(Matrix3r,__imul__,*=,Matrix3r)
-EIG_OP2_INPLACE(Matrix3r,__imul__,*=,Real)
-EIG_OP2_INPLACE(Matrix3r,__idiv__,/=,Real)
-
-//EIG_OP2(Matrix3r,__eq__,==,Matrix3r)
-//EIG_OP2(Matrix3r,__ne__,!=,Matrix3r)
-EIG_OP2(Vector3r,__add__,+,Vector3r)
-EIG_OP2(Vector3r,__sub__,-,Vector3r)
-EIG_OP2(Vector3r,__mul__,*,Real)
-EIG_OP2(Vector3r,__rmul__,*,Real)
-//EIG_OP2(Vector3r,__mul__,*,Real)
-EIG_OP2(Vector3r,__div__,/,Real)
-EIG_OP2_INPLACE(Vector3r,__iadd__,+,Vector3r)
-EIG_OP2_INPLACE(Vector3r,__isub__,-,Vector3r)
-
-Quaternionr Quaternionr__mul__Quaternionr(const Quaternionr& self, const Quaternionr& other){ return self*other; }
-//EIG_OP2(Quaternionr,__mul__,*,Quaternionr)
-EIG_OP2_INPLACE(Quaternionr,__imul__,*=,Quaternionr)
+
EIG_OP1(Matrix3r,__neg__,-)
-EIG_OP1(Vector3r,__neg__,-)
+EIG_OP2(Matrix3r,__add__,+,Matrix3r) EIG_OP2_INPLACE(Matrix3r,__iadd__,+=,Matrix3r)
+EIG_OP2(Matrix3r,__sub__,-,Matrix3r) EIG_OP2_INPLACE(Matrix3r,__isub__,-=,Matrix3r)
+EIG_OP2(Matrix3r,__mul__,*,Real) EIG_OP2(Matrix3r,__rmul__,*,Real) EIG_OP2_INPLACE(Matrix3r,__imul__,*=,Real)
+EIG_OP2(Matrix3r,__mul__,*,Vector3r) EIG_OP2(Matrix3r,__rmul__,*,Vector3r)
+EIG_OP2(Matrix3r,__mul__,*,Matrix3r)
+EIG_OP2(Matrix3r,__div__,/,Real) EIG_OP2_INPLACE(Matrix3r,__idiv__,/=,Real)
+
+EIG_OP1(Vector3r,__neg__,-);
+EIG_OP2(Vector3r,__add__,+,Vector3r); EIG_OP2_INPLACE(Vector3r,__iadd__,+,Vector3r)
+EIG_OP2(Vector3r,__sub__,-,Vector3r); EIG_OP2_INPLACE(Vector3r,__isub__,-,Vector3r)
+EIG_OP2(Vector3r,__mul__,*,Real) EIG_OP2(Vector3r,__rmul__,*,Real)
+EIG_OP2(Vector3r,__div__,/,Real) EIG_OP2_INPLACE(Vector3r,__idiv__,/=,Real)
+
+EIG_OP1(Vector3i,__neg__,-);
+EIG_OP2(Vector3i,__add__,+,Vector3i); EIG_OP2_INPLACE(Vector3i,__iadd__,+,Vector3i)
+EIG_OP2(Vector3i,__sub__,-,Vector3i); EIG_OP2_INPLACE(Vector3i,__isub__,-,Vector3i)
+EIG_OP2(Vector3i,__mul__,*,int) EIG_OP2(Vector3i,__rmul__,*,int)
+
+EIG_OP1(Vector2r,__neg__,-);
+EIG_OP2(Vector2r,__add__,+,Vector2r); EIG_OP2_INPLACE(Vector2r,__iadd__,+,Vector2r)
+EIG_OP2(Vector2r,__sub__,-,Vector2r); EIG_OP2_INPLACE(Vector2r,__isub__,-,Vector2r)
+EIG_OP2(Vector2r,__mul__,*,Real) EIG_OP2(Vector2r,__rmul__,*,Real)
+EIG_OP2(Vector2r,__div__,/,Real) EIG_OP2_INPLACE(Vector2r,__idiv__,/=,Real)
+
+EIG_OP1(Vector2i,__neg__,-);
+EIG_OP2(Vector2i,__add__,+,Vector2i); EIG_OP2_INPLACE(Vector2i,__iadd__,+,Vector2i)
+EIG_OP2(Vector2i,__sub__,-,Vector2i); EIG_OP2_INPLACE(Vector2i,__isub__,-,Vector2i)
+EIG_OP2(Vector2i,__mul__,*,int) EIG_OP2(Vector2i,__rmul__,*,int)
+
BOOST_PYTHON_MODULE(miniWm3Wrap){
bp::class_<Matrix3r >("Matrix3",bp::init<>())
.def(bp::init<Matrix3r const &>((bp::arg("m"))))
- //.def(bp::init<Real,Real,Real,Real,Real,Real,Real,Real,Real>((bp::arg("n00"),bp::arg("n01"),bp::arg("n02"),bp::arg("n10"),bp::arg("n11"),bp::arg("n12"),bp::arg("n20"),bp::arg("n21"),bp::arg("n22"))))
- // .def(bp::init<const Vector3r&, const Vector3r&, const Vector3r&, bool>((bp::arg("v0"),bp::arg("v1"),bp::arg("v2"),bp::arg("columns"))))
- //.def(bp::init<Real,Real,Real>((bp::arg("n00"),bp::arg("n11"),bp::arg("n22"))))
- //.def("__init__",&matrixFromElements)
- //.def(bp::init<Vector3r>((bp::arg("diag"))))
+ .def("__init__",bp::make_constructor(&Matrix3r_fromElements)) //,(bp::arg("m00"),bp::arg("m01"),bp::arg("m02"),bp::arg("m10"),bp::arg("m11"),bp::arg("m12"),bp::arg("m20"),bp::arg("m21"),bp::arg("m22"))))
+ //
.def("determinant",&Matrix3r::determinant)
.def("inverse",&Matrix3r_inverse)
.def("transpose",&Matrix3r_transpose)
- //.def("__mul__", &Matrix3r__mul__Matrix3r)
- .def("__add__", &Matrix3r__add__Matrix3r)
- .def("__sub__", &Matrix3r__sub__Matrix3r)
- .def("__mul__", &Matrix3r__mul__Real)
- .def("__rmul__",&Matrix3r__rmul__Real)
- .def("__div__", &Matrix3r__div__Real)
- .def("__iadd__",&Matrix3r__iadd__Matrix3r)
- .def("__isub__",&Matrix3r__isub__Matrix3r)
- //.def("__imul__",&Matrix3r__imul__Matrix3r)
- .def("__imul__",&Matrix3r__imul__Real)
- .def("__idiv__",&Matrix3r__idiv__Real)
+ //
.def("__neg__",&Matrix3r__neg__)
-#if 0
- .def(bp::self * bp::self)
- //.def(bp::self *= bp::self)
- .def(bp::self + bp::self)
- .def(bp::self += bp::self)
- .def(bp::self - bp::self)
- .def(bp::self -= bp::self)
- .def(bp::self * bp::other<Real>())
- .def(bp::other<Real>() * bp::self)
- .def(bp::self *= bp::other<Real>())
- .def(bp::self / bp::other<Real>())
- .def(bp::self /= bp::other<Real>())
- //.def(bp::self == bp::self)
- //.def(bp::self != bp::self)
- .def(-bp::self)
-#endif
- .def("__len__",&::Matrix3_len).staticmethod("__len__")
- .def("__setitem__",&::Matrix3_set_item)
- .def("__getitem__",&::Matrix3_get_item)
- .def("__str__",&::Matrix3_str)
- .def("__repr__",&::Matrix3_str)
+ .def("__add__",&Matrix3r__add__Matrix3r).def("__iadd__",&Matrix3r__iadd__Matrix3r)
+ .def("__sub__",&Matrix3r__sub__Matrix3r).def("__isub__",&Matrix3r__isub__Matrix3r)
+ .def("__mul__",&Matrix3r__mul__Real).def("__rmul__",&Matrix3r__rmul__Real).def("__imul__",&Matrix3r__imul__Real)
+ .def("__mul__",&Matrix3r__mul__Vector3r).def("__rmul__",&Matrix3r__rmul__Vector3r)
+ .def("__mul__",&Matrix3r__mul__Matrix3r)
+ .def("__div__",&Matrix3r__div__Real).def("__idiv__",&Matrix3r__idiv__Real)
+ .def(bp::self == bp::self)
+ .def(bp::self != bp::self)
+ //
+ .def("__len__",&::Matrix3r_len).staticmethod("__len__").def("__setitem__",&::Matrix3r_set_item).def("__getitem__",&::Matrix3r_get_item).def("__str__",&::Matrix3r_str).def("__repr__",&::Matrix3r_str)
/* extras for matrices */
- .def("__setitem__",&::Matrix3_set_item_linear)
- .def("__getitem__",&::Matrix3_get_item_linear)
- .def_readonly("Identity",Matrix3r_Identity())
- .def_readonly("Zero",Matrix3r_Zero())
+ .def("__setitem__",&::Matrix3r_set_item_linear).def("__getitem__",&::Matrix3r_get_item_linear)
+ .def_readonly("Identity",&Matrix3r_Identity).def_readonly("Zero",&Matrix3r_Zero)
// wm3 compat
- .def_readonly("IDENTITY",Matrix3r_Identity())
- .def_readonly("ZERO",Matrix3r_Zero())
- .def("Determinant",&Matrix3r::determinant)
- .def("Inverse",&Matrix3r_inverse)
- .def("Transpose",&Matrix3r_transpose)
+ .def_readonly("IDENTITY",&Matrix3r_Identity).def_readonly("ZERO",&Matrix3r_Zero).def("Determinant",&Matrix3r::determinant).def("Inverse",&Matrix3r_inverse).def("Transpose",&Matrix3r_transpose)
+ .def("FromAxisAngle",&Matrix3r_fromAxisAngle)
;
bp::class_<Quaternionr>("Quaternion",bp::init<>())
- //.def(bp::init<Vector3r,Real>((bp::arg("axis"),bp::arg("angle"))))
- //.def(bp::init<Matrix3r>((bp::arg("rotMatrix"))))
+ .def("__init__",bp::make_constructor(&Quaternionr_fromAxisAngle))
+ .def("__init__",bp::make_constructor(&Quaternionr_fromAngleAxis))
.def(bp::init<Quaternionr>((bp::arg("other"))))
.def("setFromTwoVectors",&Quaternionr_setFromTwoVectors,((bp::arg("v1"),bp::arg("v2"))))
- .def("conjugate",&Quaternionr_conjugate)
- //.def("FromAxisAngle",&Quaternionr::FromAxisAngle,((bp::arg("axis"),bp::arg("angle"))),bp::return_self<>())
+ .def("conjugate",&Quaternionr::conjugate)
+ .def("toAxisAngle",&Quaternionr_toAxisAngle).def("toAngleAxis",&Quaternionr_toAxisAngle)
//.def("rotate",&Quaternionr::Rotate,((bp::arg("v"))))
- .def("inverse",&Quaternionr_inverse)
+ .def("inverse",&Quaternionr::inverse)
.def("norm",&Quaternionr::norm)
.def("normalize",&Quaternionr::normalize)
- .def("__mul__",&Quaternionr__mul__Quaternionr)
- .def("__imul__",&Quaternionr__imul__Quaternionr)
- //.def("ToRotationMatrix",&Quaternionr::ToRotationMatrix)
- //.def("ToAxisAngle",Quaternion_ToAxisAngle)
- //.def(bp::self != bp::self)
- //.def(bp::self == bp::self)
- //.def(bp::self * bp::self)
- //.def(bp::self * bp::other<Real>())
- //.def(bp::other<Real>() * bp::self)
- //.def(bp::self * bp::other<Vector3r>())
- //.def(bp::self *= bp::other<Real>())
- //.def(bp::self + bp::self)
- //.def(bp::self += bp::self)
- //.def(bp::self - bp::self)
- //.def(-bp::self)
- //.def(bp::self -= bp::self)
- //.def(bp::self / bp::other<Real>())
- //.def(bp::self /= bp::other<Real>())
- .def("__len__",&::Quaternion_len).staticmethod("__len__")
- .def("__setitem__",&::Quaternion_set_item)
- .def("__getitem__",&::Quaternion_get_item)
- .def("__str__",&::Quaternion_str)
- .def("__repr__",&::Quaternion_str)
- .def_readonly("Identity",Quaternionr_Identity())
- .def_readonly("IDENTITY",Quaternionr_Identity())
+ .def(bp::self * bp::self)
+ .def(bp::self *= bp::self)
+ .def(bp::self * bp::other<Vector3r>())
+ .def("__eq__",&Quaternionr__eq__).def("__neq__",&Quaternionr__neq__)
+ //.def(bp::self != bp::self).def(bp::self == bp::self) // these don't work... (?)
+ //
+ .def("__len__",&::Quaternionr_len).staticmethod("__len__")
+ .def("__setitem__",&::Quaternionr_set_item).def("__getitem__",&::Quaternionr_get_item)
+ .def("__str__",&::Quaternionr_str).def("__repr__",&::Quaternionr_str)
+ .def_readonly("Identity",&Quaternionr_Identity)
// wm3 compat
- .def("Align",&Quaternionr_setFromTwoVectors,((bp::arg("v1"),bp::arg("v2"))))
- .def("Conjugate",&Quaternionr_conjugate)
- //.def("FromAxisAngle",&Quaternionr::FromAxisAngle,((bp::arg("axis"),bp::arg("angle"))),bp::return_self<>())
+ .def("Align",&Quaternionr_setFromTwoVectors,((bp::arg("v1"),bp::arg("v2")))).def("Conjugate",&Quaternionr::conjugate).def("Inverse",&Quaternionr::inverse).def("Length",&Quaternionr::norm).def("Normalize",&Quaternionr::normalize).def_readonly("IDENTITY",&Quaternionr_Identity)
+ .def("ToAxisAngle",&Quaternionr_toAxisAngle).def("ToAngleAxis",&Quaternionr_toAxisAngle)
//.def("Rotate",&Quaternionr::rotate,((bp::arg("v"))))
- .def("Inverse",&Quaternionr_inverse)
- .def("Length",&Quaternionr::norm)
- .def("Normalize",&Quaternionr::normalize)
;
+ bp::class_<Vector3r>("Vector3",bp::init<>())
+ .def(bp::init<Vector3r>((bp::arg("other"))))
+ .def(bp::init<Real,Real,Real>((bp::arg("x"),bp::arg("y"),bp::arg("z"))))
+ // properties
+ .def_readonly("Ones",&Vector3r_Ones).def_readonly("Zero",&Vector3r_Zero)
+ .def_readonly("UnitX",&Vector3r_UnitX).def_readonly("UnitY",&Vector3r_UnitY).def_readonly("UnitZ",&Vector3r_UnitZ)
+ // methods
+ .def("dot",&Vector3r_dot).def("cross",&Vector3r_cross)
+ .def("norm",&Vector3r::norm).def("squaredNorm",&Vector3r::squaredNorm).def("normalize",&Vector3r::normalize)
+ // operators
+ .def("__neg__",&Vector3r__neg__) // -v
+ .def("__add__",&Vector3r__add__Vector3r).def("__iadd__",&Vector3r__iadd__Vector3r) // +, +=
+ .def("__sub__",&Vector3r__sub__Vector3r).def("__isub__",&Vector3r__isub__Vector3r) // -, -=
+ .def("__mul__",&Vector3r__mul__Real).def("__rmul__",&Vector3r__rmul__Real) // f*v, v*f
+ .def("__div__",&Vector3r__div__Real).def("__idiv__",&Vector3r__idiv__Real) // v/f, v/=f
+ .def(bp::self != bp::self).def(bp::self == bp::self)
+ // specials
+ .def("__len__",&::Vector3r_len).staticmethod("__len__")
+ .def("__setitem__",&::Vector3r_set_item).def("__getitem__",&::Vector3r_get_item)
+ .def("__str__",&::Vector3r_str).def("__repr__",&::Vector3r_str)
+ // wm3 compat
+ .def("Dot",&Vector3r_dot).def("Cross",&Vector3r_cross).def("Length",&Vector3r::norm).def("SquaredLength",&Vector3r::squaredNorm).def("Normalize",&Vector3r::normalize)
+ .def_readonly("ONE",&Vector3r_Ones).def_readonly("ZERO",&Vector3r_Zero).def_readonly("UNIT_X",&Vector3r_UnitX).def_readonly("UNIT_Y",&Vector3r_UnitY).def_readonly("UNIT_Z",&Vector3r_UnitZ)
+ ;
+ bp::class_<Vector3i>("Vector3i",bp::init<>())
+ .def(bp::init<Vector3i>((bp::arg("other"))))
+ .def(bp::init<int,int,int>((bp::arg("x"),bp::arg("y"),bp::arg("z"))))
+ // properties
+ .def_readonly("Ones",&Vector3i_Ones).def_readonly("Zero",&Vector3i_Zero)
+ .def_readonly("UnitX",&Vector3i_UnitX).def_readonly("UnitY",&Vector3i_UnitY).def_readonly("UnitZ",&Vector3i_UnitZ)
+ // methods
+ .def("dot",&Vector3i_dot).def("cross",&Vector3i_cross)
+ .def("norm",&Vector3i::norm).def("squaredNorm",&Vector3i::squaredNorm)
+ // operators
+ .def("__neg__",&Vector3i__neg__) // -v
+ .def("__add__",&Vector3i__add__Vector3i).def("__iadd__",&Vector3i__iadd__Vector3i) // +, +=
+ .def("__sub__",&Vector3i__sub__Vector3i).def("__isub__",&Vector3i__isub__Vector3i) // -, -=
+ .def("__mul__",&Vector3i__mul__int).def("__rmul__",&Vector3i__rmul__int) // f*v, v*f
+ .def(bp::self != bp::self).def(bp::self == bp::self)
+ // specials
+ .def("__len__",&::Vector3i_len).staticmethod("__len__")
+ .def("__setitem__",&::Vector3i_set_item).def("__getitem__",&::Vector3i_get_item)
+ .def("__str__",&::Vector3i_str).def("__repr__",&::Vector3i_str)
+ // wm3 compat
+ .def("Dot",&Vector3i_dot).def("Cross",&Vector3i_cross).def("Length",&Vector3i::norm).def("SquaredLength",&Vector3r::squaredNorm)
+ .def_readonly("ONE",&Vector3i_Ones).def_readonly("ZERO",&Vector3i_Zero).def_readonly("UNIT_X",&Vector3i_UnitX).def_readonly("UNIT_Y",&Vector3i_UnitY).def_readonly("UNIT_Z",&Vector3i_UnitZ)
+ ;
bp::class_<Vector2r>("Vector2",bp::init<>())
.def(bp::init<Vector2r>((bp::arg("other"))))
.def(bp::init<Real,Real>((bp::arg("x"),bp::arg("y"))))
+ // properties
+ .def_readonly("Ones",&Vector2r_Ones).def_readonly("Zero",&Vector2r_Zero)
+ .def_readonly("UnitX",&Vector2r_UnitX).def_readonly("UnitY",&Vector2r_UnitY)
+ // methods
.def("dot",&Vector2r_dot)
- .def("norm",&Vector2r::norm)
- .def("squaredNorm",&Vector2r::squaredNorm)
- .def("normalize",&Vector2r::normalize)
- //
- #if 0
- .def(bp::self != bp::self)
- .def(bp::self == bp::self)
- .def(bp::self * bp::other<Real>())
- .def(bp::other<Real>() * bp::self)
- .def(bp::self *= bp::other<Real>())
- .def(bp::self + bp::self)
- .def(bp::self += bp::self)
- .def(bp::self - bp::self)
- .def(bp::self -= bp::self)
- .def(-bp::self)
- .def(bp::self / bp::other<Real>())
- .def(bp::self /= bp::other<Real>())
- #endif
- .def("__len__",&::Vector2_len).staticmethod("__len__")
- .def("__setitem__",&::Vector2_set_item)
- .def("__getitem__",&::Vector2_get_item)
- .def("__str__",&::Vector2_str)
- .def("__repr__",&::Vector2_str)
- .def_readonly("Ones",Vector2r_Ones())
- .def_readonly("UnitX",Vector2r_UnitX())
- .def_readonly("UnitY",Vector2r_UnitY())
- .def_readonly("Zero",Vector2r_Zero())
- // wm3 compat
- .def("Dot",&Vector2r_dot)
- .def("Length",&Vector2r::norm)
- .def("SquaredLength",&Vector2r::squaredNorm)
- .def("Normalize",&Vector2r::normalize)
- .def_readonly("ONE",Vector2r_Ones())
- .def_readonly("UNIT_X",Vector2r_UnitX())
- .def_readonly("UNIT_Y",Vector2r_UnitY())
- .def_readonly("ZERO",Vector2r_Zero())
- ;
- bp::class_<Vector3r>("Vector3",bp::init<>())
- .def(bp::init<Vector3r>((bp::arg("other"))))
- .def(bp::init<Real,Real,Real>((bp::arg("x"),bp::arg("y"),bp::arg("z"))))
- .def("dot",&Vector3r_dot)
- .def("cross",&Vector3r_cross)
- .def("norm",&Vector3r::norm)
- .def("squaredNorm",&Vector3r::squaredNorm)
- .def("normalize",&Vector3r::normalize)
- .def("__neg__",&Matrix3r__neg__)
- .def("__add__",&Vector3r__add__Vector3r)
- .def("__sub__",&Vector3r__sub__Vector3r)
- .def("__iadd__",&Vector3r__iadd__Vector3r)
- .def("__isub__",&Vector3r__isub__Vector3r)
- .def("__mul__",&Vector3r__mul__Real)
- .def("__div__",&Vector3r__div__Real)
- .def("__rmul__",&Vector3r__rmul__Real)
- #if 0
- .def(bp::self != bp::self)
- .def(bp::self == bp::self)
- .def(bp::self * bp::other<Real>())
- .def(bp::other<Real>() * bp::self)
- .def(bp::self *= bp::other<Real>())
- .def(bp::self + bp::self)
- .def(bp::self += bp::self)
- .def(bp::self - bp::self)
- .def(bp::self -= bp::self)
- .def(-bp::self)
- .def(bp::self / bp::other<Real>())
- .def(bp::self /= bp::other<Real>())
- #endif
- .def("__len__",&::Vector3_len).staticmethod("__len__")
- .def("__setitem__",&::Vector3_set_item)
- .def("__getitem__",&::Vector3_get_item)
- .def("__str__",&::Vector3_str)
- .def("__repr__",&::Vector3_str)
- .def_readonly("Ones",Vector3r_Ones())
- .def_readonly("UnitX",Vector3r_UnitX())
- .def_readonly("UnitY",Vector3r_UnitY())
- .def_readonly("UnitZ",Vector3r_UnitZ())
- .def_readonly("Zero",Vector3r_Zero())
- // wm3 compat
- .def("Dot",&Vector3r_dot)
- .def("Length",&Vector3r::norm)
- .def("SquaredLength",&Vector3r::squaredNorm)
- .def("Normalize",&Vector3r::normalize)
- .def_readonly("ONE",Vector3r_Ones())
- .def_readonly("UNIT_X",Vector3r_UnitX())
- .def_readonly("UNIT_Y",Vector3r_UnitY())
- .def_readonly("UNIT_Z",Vector3r_UnitZ())
- .def_readonly("ZERO",Vector3r_Zero())
+ .def("norm",&Vector2r::norm).def("squaredNorm",&Vector2r::squaredNorm).def("normalize",&Vector2r::normalize)
+ // operators
+ .def("__neg__",&Vector2r__neg__) // -v
+ .def("__add__",&Vector2r__add__Vector2r).def("__iadd__",&Vector2r__iadd__Vector2r) // +, +=
+ .def("__sub__",&Vector2r__sub__Vector2r).def("__isub__",&Vector2r__isub__Vector2r) // -, -=
+ .def("__mul__",&Vector2r__mul__Real).def("__rmul__",&Vector2r__rmul__Real) // f*v, v*f
+ .def("__div__",&Vector2r__div__Real).def("__idiv__",&Vector2r__idiv__Real) // v/f, v/=f
+ .def(bp::self != bp::self).def(bp::self == bp::self)
+ // specials
+ .def("__len__",&::Vector2r_len).staticmethod("__len__")
+ .def("__setitem__",&::Vector2r_set_item).def("__getitem__",&::Vector2r_get_item)
+ .def("__str__",&::Vector2r_str).def("__repr__",&::Vector2r_str)
+ // wm3 compat
+ .def("Dot",&Vector2r_dot).def("Length",&Vector2r::norm).def("SquaredLength",&Vector2r::squaredNorm).def("Normalize",&Vector2r::normalize)
+ .def_readonly("ONE",&Vector2r_Ones).def_readonly("ZERO",&Vector2r_Zero).def_readonly("UNIT_X",&Vector2r_UnitX).def_readonly("UNIT_Y",&Vector2r_UnitY)
+ ;
+ bp::class_<Vector2i>("Vector2i",bp::init<>())
+ .def(bp::init<Vector2i>((bp::arg("other"))))
+ .def(bp::init<int,int>((bp::arg("x"),bp::arg("y"))))
+ // properties
+ .def_readonly("Ones",&Vector2i_Ones).def_readonly("Zero",&Vector2i_Zero)
+ .def_readonly("UnitX",&Vector2i_UnitX).def_readonly("UnitY",&Vector2i_UnitY)
+ // methods
+ .def("dot",&Vector2i_dot)
+ .def("norm",&Vector2i::norm).def("squaredNorm",&Vector2i::squaredNorm).def("normalize",&Vector2i::normalize)
+ // operators
+ .def("__neg__",&Vector2i__neg__) // -v
+ .def("__add__",&Vector2i__add__Vector2i).def("__iadd__",&Vector2i__iadd__Vector2i) // +, +=
+ .def("__sub__",&Vector2i__sub__Vector2i).def("__isub__",&Vector2i__isub__Vector2i) // -, -=
+ .def("__mul__",&Vector2i__mul__int).def("__rmul__",&Vector2i__rmul__int) // f*v, v*f
+ .def(bp::self != bp::self).def(bp::self == bp::self)
+ // specials
+ .def("__len__",&::Vector2i_len).staticmethod("__len__")
+ .def("__setitem__",&::Vector2i_set_item).def("__getitem__",&::Vector2i_get_item)
+ .def("__str__",&::Vector2i_str).def("__repr__",&::Vector2i_str)
+ // wm3 compat
+ .def("Dot",&Vector2i_dot).def("Length",&Vector2i::norm).def("SquaredLength",&Vector2i::squaredNorm).def("Normalize",&Vector2i::normalize)
+ .def_readonly("ONE",&Vector2i_Ones).def_readonly("ZERO",&Vector2i_Zero).def_readonly("UNIT_X",&Vector2i_UnitX).def_readonly("UNIT_Y",&Vector2i_UnitY)
;
};