Browse Source

python: don't define negation on unsigned vector types.

Thanks, MSVC.
appveyor-coverage
Vladimír Vondruš 7 years ago
parent
commit
4718de1ed3
  1. 14
      src/python/magnum/math.vector.h
  2. 6
      src/python/magnum/math.vectorfloat.cpp
  3. 8
      src/python/magnum/math.vectorintegral.cpp

14
src/python/magnum/math.vector.h

@ -93,7 +93,6 @@ template<class T, class ...Args> void everyVector(py::class_<T, Args...>& c) {
.def(py::init(), "Default constructor")
/* Operators */
.def(-py::self, "Negated vector")
.def(py::self += py::self, "Add and assign a vector")
.def(py::self + py::self, "Add a vector")
#ifdef __clang__
@ -124,6 +123,10 @@ template<class T, class ...Args> void everyVector(py::class_<T, Args...>& c) {
.def(typename T::Type{} / py::self, "Divide a vector with a scalar and invert");
}
template<class T, class ...Args> void everyVectorSigned(py::class_<T, Args...>& c) {
c.def(-py::self, "Negated vector");
}
/* Separate because it needs to be registered after the type conversion
constructors. Needs to be called also for subclasses. */
template<class T, class ...Args> void everyVectorBuffer(py::class_<T, Args...>& c) {
@ -272,10 +275,6 @@ template<class T> void vector2(py::class_<Math::Vector2<T>>& c) {
.def_static("y_scale", &Math::Vector2<T>::yScale,
"Scaling vector in a direction of Y axis (height)", py::arg("scale"))
/* Methods */
.def("perpendicular", &Math::Vector2<T>::perpendicular,
"Perpendicular vector")
/* Properties */
.def_property("x",
static_cast<T(Math::Vector2<T>::*)() const>(&Math::Vector2<T>::x),
@ -287,6 +286,11 @@ template<class T> void vector2(py::class_<Math::Vector2<T>>& c) {
"Y component");
}
template<class T> void vector2Signed(py::class_<Math::Vector2<T>>& c) {
/* Cast needed because these are enabled only for signed types */
c.def("perpendicular", static_cast<Math::Vector2<T>(Math::Vector2<T>::*)() const>(&Math::Vector2<T>::perpendicular), "Perpendicular vector");
}
template<class T> void vector3(py::class_<Math::Vector3<T>>& c) {
py::implicitly_convertible<const std::tuple<T, T, T>&, Math::Vector3<T>>();

6
src/python/magnum/math.vectorfloat.cpp

@ -59,19 +59,23 @@ template<class T> void vectorsFloat(py::module& m, py::class_<Math::Vector2<T>>&
.def("cross", static_cast<T(*)(const Math::Vector2<T>&, const Math::Vector2<T>&)>(Math::cross),
"2D cross product");
everyVector(vector2_);
everyVectorSigned(vector2_);
vector<Math::Vector2<T>>(m, vector2_);
vectorFloat<Math::Vector2<T>>(m, vector2_);
vector2<T>(vector2_);
vector2Signed<T>(vector2_);
vector3_
.def("cross", static_cast<Math::Vector3<T>(*)(const Math::Vector3<T>&, const Math::Vector3<T>&)>(Math::cross),
"Cross product");
everyVector(vector3_);
everyVectorSigned(vector3_);
vector<Math::Vector3<T>>(m, vector3_);
vectorFloat<Math::Vector3<T>>(m, vector3_);
vector3<T>(vector3_);
everyVector(vector4_);
everyVectorSigned(vector4_);
vector<Math::Vector4<T>>(m, vector4_);
vectorFloat<Math::Vector4<T>>(m, vector4_);
vector4<T>(vector4_);
@ -132,9 +136,11 @@ void mathVectorFloat(py::module& root, py::module& m) {
vectorsFloat<Float>(m, vector2, vector3, vector4);
vectorsFloat<Double>(m, vector2d, vector3d, vector4d);
everyVector(color3_);
everyVectorSigned(color3_);
color(color3_);
color3(color3_);
everyVector(color4_);
everyVectorSigned(color4_);
color(color4_);
color4(color4_);
}

8
src/python/magnum/math.vectorintegral.cpp

@ -98,6 +98,13 @@ template<class T> void vectorsIntegral(py::module& m, py::class_<Math::Vector2<T
vector4<T>(vector4_);
}
template<class T> void vectorsIntegralSigned(py::class_<Math::Vector2<T>>& vector2_, py::class_<Math::Vector3<T>>& vector3_, py::class_<Math::Vector4<T>>& vector4_) {
everyVectorSigned(vector2_);
everyVectorSigned(vector3_);
everyVectorSigned(vector4_);
vector2Signed<T>(vector2_);
}
}
void mathVectorIntegral(py::module& root, py::module& m) {
@ -131,6 +138,7 @@ void mathVectorIntegral(py::module& root, py::module& m) {
/* Now register the generic from-list constructors and everything else */
vectorsIntegral<Int>(m, vector2i, vector3i, vector4i);
vectorsIntegralSigned<Int>(vector2i, vector3i, vector4i);
vectorsIntegral<UnsignedInt>(m, vector2ui, vector3ui, vector4ui);
}

Loading…
Cancel
Save