Commit 4d9c6945 authored by Alexander Dielen's avatar Alexander Dielen

added missing vector functions

parent 6350c95d
...@@ -7,7 +7,12 @@ namespace py = pybind11; ...@@ -7,7 +7,12 @@ namespace py = pybind11;
PYBIND11_MODULE(openmesh, m) { PYBIND11_MODULE(openmesh, m) {
expose_vec<double, 3>(m, "Vec3d"); expose_vec<float, 2>(m, "Vec2f");
expose_vec<float, 3>(m, "Vec3f");
expose_vec<float, 4>(m, "Vec4f");
expose_vec<double, 2>(m, "Vec2d");
expose_vec<double, 3>(m, "Vec3d");
expose_vec<double, 4>(m, "Vec4d");
} }
......
...@@ -15,9 +15,7 @@ void set_item(Vector& _vec, int _index, Scalar _value) { ...@@ -15,9 +15,7 @@ void set_item(Vector& _vec, int _index, Scalar _value) {
_vec[_index] = _value; _vec[_index] = _value;
} }
else { else {
// TODO throw py::index_error();
// PyErr_SetString(PyExc_IndexError, "Index out of range.");
// throw_error_already_set();
} }
} }
...@@ -31,9 +29,7 @@ Scalar get_item(Vector& _vec, int _index) { ...@@ -31,9 +29,7 @@ Scalar get_item(Vector& _vec, int _index) {
return _vec[_index]; return _vec[_index];
} }
else { else {
// TODO throw py::index_error();
// PyErr_SetString(PyExc_IndexError, "Index out of range.");
// throw_error_already_set();
} }
return 0.0; return 0.0;
...@@ -124,6 +120,20 @@ void expose_vec(py::module& m, const char *_name) { ...@@ -124,6 +120,20 @@ void expose_vec(py::module& m, const char *_name) {
Vector& (Vector::*normalize )(void ) = &Vector::normalize; Vector& (Vector::*normalize )(void ) = &Vector::normalize;
Vector& (Vector::*normalize_cond)(void ) = &Vector::normalize_cond; Vector& (Vector::*normalize_cond)(void ) = &Vector::normalize_cond;
Vector& (Vector::*op_selfmul_scalar)(const Scalar&) = &Vector::operator*=;
Vector& (Vector::*op_selfmul_vector)(const Vector&) = &Vector::operator*=;
Vector& (Vector::*op_selfdiv_scalar)(const Scalar&) = &Vector::operator/=;
Vector& (Vector::*op_selfdiv_vector)(const Scalar&) = &Vector::operator/=;
Vector& (Vector::*op_selfadd_vector)(const Vector&) = &Vector::operator+=;
Vector& (Vector::*op_selfsub_vector)(const Vector&) = &Vector::operator-=;
Vector (Vector::*op_mul_scalar )(const Scalar&) const = &Vector::operator*;
Vector (Vector::*op_mul_vector )(const Vector&) const = &Vector::operator*;
Vector (Vector::*op_div_scalar )(const Scalar&) const = &Vector::operator/;
Vector (Vector::*op_div_vector )(const Vector&) const = &Vector::operator/;
Vector (Vector::*op_add_vector )(const Vector&) const = &Vector::operator+;
Vector (Vector::*op_sub_vector )(const Vector&) const = &Vector::operator-;
Vector (Vector::*op_unary_minus )(void ) const = &Vector::operator-;
#if (_MSC_VER >= 1800 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENMESH_VECTOR_LEGACY) #if (_MSC_VER >= 1800 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENMESH_VECTOR_LEGACY)
Vector (Vector::*normalized)() const = &Vector::normalized; Vector (Vector::*normalized)() const = &Vector::normalized;
#else #else
...@@ -136,24 +146,25 @@ void expose_vec(py::module& m, const char *_name) { ...@@ -136,24 +146,25 @@ void expose_vec(py::module& m, const char *_name) {
.def("__setitem__", &set_item<Vector, Scalar>) .def("__setitem__", &set_item<Vector, Scalar>)
.def("__getitem__", &get_item<Vector, Scalar>) .def("__getitem__", &get_item<Vector, Scalar>)
.def("__eq__", &Vector::operator==) .def("__eq__", &Vector::operator==)
// .def(self != self) .def("__ne__", &Vector::operator!=)
// .def(self *= Scalar()) .def("__lt__", &Vector::operator<)
// .def(self /= Scalar()) .def("__imul__", op_selfmul_scalar)
// .def(self * Scalar()) .def("__imul__", op_selfmul_vector)
// .def(Scalar() * self) .def("__itruediv__", op_selfdiv_scalar)
// .def(self / Scalar()) .def("__itruediv__", op_selfdiv_vector)
// .def(self *= self) .def("__iadd__", op_selfadd_vector)
// .def(self /= self) .def("__isub__", op_selfsub_vector)
// .def(self -= self) .def("__mul__", op_mul_scalar)
// .def(self += self) .def("__mul__", op_mul_vector)
// .def(self * self) .def("__rmul__", op_mul_scalar)
// .def(self / self) .def("__truediv__", op_div_scalar)
// .def(self + self) .def("__truediv__", op_div_vector)
// .def(self - self) .def("__add__", op_add_vector)
// .def("__neg__", &Vector::operator-) .def("__sub__", op_sub_vector)
// .def(self | self) .def("__neg__", op_unary_minus)
.def("__or__", dot)
.def("vectorize", &Vector::vectorize, py::return_value_policy::reference_internal) .def("vectorize", &Vector::vectorize, py::return_value_policy::reference_internal)
// .def(self < self)
.def("dot", dot) .def("dot", dot)
.def("norm", norm) .def("norm", norm)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment