8 #ifndef _PyImathVec3Impl_h_
9 #define _PyImathVec3Impl_h_
18 #define HBOOST_BIND_GLOBAL_PLACEHOLDERS
19 #include <hboost/python.hpp>
20 #include <hboost/python/make_constructor.hpp>
21 #include <hboost/format.hpp>
30 using namespace hboost::python;
37 static Vec3<T> * Vec3_construct_default()
43 static Vec3<T> * Vec3_object_constructor1(
const object &obj)
46 extract<Vec3<int> > e1(obj);
47 extract<Vec3<float> > e2(obj);
48 extract<Vec3<double> > e3(obj);
49 extract<tuple> e4(obj);
50 extract<double> e5(obj);
51 extract<list> e6(obj);
53 if(e1.check()) { w = e1(); }
54 else if(
e2.check()) { w =
e2(); }
55 else if(e3.check()) { w = e3(); }
59 if(t.attr(
"__len__")() == 3)
61 w.
x = extract<T>(t[0]);
62 w.
y = extract<T>(t[1]);
63 w.
z = extract<T>(t[2]);
66 throw std::invalid_argument (
"tuple must have length of 3");
69 else if(e5.check()) {
T a = e5(); w.
setValue(a, a, a); }
73 if(l.attr(
"__len__")() == 3)
75 w.
x = extract<T>(l[0]);
76 w.
y = extract<T>(l[1]);
77 w.
z = extract<T>(l[2]);
80 throw std::invalid_argument (
"list must have length of 3");
83 throw std::invalid_argument (
"invalid parameters passed to Vec3 constructor");
93 static Vec3<T> * Vec3_object_constructor2(
const object &obj1,
const object &obj2,
const object &obj3)
95 extract<double>
e1(obj1);
96 extract<double>
e2(obj2);
97 extract<double> e3(obj3);
100 if(
e1.check()) { v->
x =
e1();}
101 else {
throw std::invalid_argument (
"invalid parameters passed to Vec3 constructor"); }
103 if(
e2.check()) { v->
y =
e2();}
104 else {
throw std::invalid_argument (
"invalid parameters passed to Vec3 constructor"); }
106 if(e3.check()) { v->
z = e3();}
107 else {
throw std::invalid_argument (
"invalid parameters passed to Vec3 constructor"); }
117 static std::string Vec3_str(
const Vec3<T> &v)
124 static std::string Vec3_repr(
const Vec3<T> &v)
132 static IMATH_NAMESPACE::Vec3<T>
133 Vec3_cross(
const IMATH_NAMESPACE::Vec3<T> &v,
const IMATH_NAMESPACE::Vec3<T> &other)
136 return v.cross(other);
140 static FixedArray<IMATH_NAMESPACE::Vec3<T> >
141 Vec3_cross_Vec3Array(
const IMATH_NAMESPACE::Vec3<T> &va,
const FixedArray<IMATH_NAMESPACE::Vec3<T> > &vb)
144 size_t len = vb.len();
145 FixedArray<IMATH_NAMESPACE::Vec3<T> >
f(len);
146 for (
size_t i = 0; i < len; ++i)
147 f[i] = va.cross(vb[i]);
153 Vec3_dot(
const IMATH_NAMESPACE::Vec3<T> &v,
const IMATH_NAMESPACE::Vec3<T> &other)
161 Vec3_dot_Vec3Array(
const IMATH_NAMESPACE::Vec3<T> &va,
const FixedArray<IMATH_NAMESPACE::Vec3<T> > &vb)
164 size_t len = vb.len();
165 FixedArray<T>
f(len);
166 for (
size_t i = 0; i < len; ++i)
167 f[i] = va.dot(vb[i]);
173 Vec3_length(
const IMATH_NAMESPACE::Vec3<T> &v)
181 Vec3_length2(
const IMATH_NAMESPACE::Vec3<T> &v)
189 Vec3_normalize(IMATH_NAMESPACE::Vec3<T> &v)
192 return v.normalize();
197 Vec3_normalizeExc(IMATH_NAMESPACE::Vec3<T> &v)
200 return v.normalizeExc();
205 Vec3_normalizeNonNull(IMATH_NAMESPACE::Vec3<T> &v)
208 return v.normalizeNonNull();
213 Vec3_normalized(
const IMATH_NAMESPACE::Vec3<T> &v)
216 return v.normalized();
221 Vec3_normalizedExc(
const IMATH_NAMESPACE::Vec3<T> &v)
224 return v.normalizedExc();
229 Vec3_normalizedNonNull(
const IMATH_NAMESPACE::Vec3<T> &v)
232 return v.normalizedNonNull();
240 return IMATH_NAMESPACE::closestVertex(v0, v1, v2, p);
245 Vec3_negate(IMATH_NAMESPACE::Vec3<T> &v)
256 return IMATH_NAMESPACE::orthogonal(v, v0);
264 return IMATH_NAMESPACE::project(v0, v);
272 return IMATH_NAMESPACE::reflect(v, v0);
308 template <
class T,
class U>
319 Vec3_mulT (
const Vec3<T> &v, T t)
326 static FixedArray<IMATH_NAMESPACE::Vec3<T> >
327 Vec3_mulTArray (
const Vec3<T> &v,
const FixedArray<T> &t)
330 size_t len = t.len();
331 FixedArray<IMATH_NAMESPACE::Vec3<T> > retval(len);
332 for (
size_t i=0; i<len; ++i) retval[i] = v*t[i];
337 static FixedArray<IMATH_NAMESPACE::Vec3<T> >
338 Vec3_rmulTArray (
const Vec3<T> &v,
const FixedArray<T> &t)
340 return Vec3_mulTArray(v,t);
343 template <
class T,
class S>
359 template <
class T,
class U>
369 Vec3_imulT(IMATH_NAMESPACE::Vec3<T> &v, T t)
375 template <
class T,
class U>
383 template <
class T,
class U>
393 Vec3_idivObj(IMATH_NAMESPACE::Vec3<T> &v,
const object &o)
403 extract<double> e(o);
407 throw std::invalid_argument (
"V3 division expects an argument"
408 "convertible to a V3");
414 Vec3_subT(
const Vec3<T> &v, T a)
422 template <
class T,
class BoostPyType>
424 Vec3_subTuple(
const Vec3<T> &v,
const BoostPyType &t)
429 if(t.attr(
"__len__")() == 3)
431 w.
x = v.
x - extract<T>(t[0]);
432 w.
y = v.
y - extract<T>(t[1]);
433 w.
z = v.
z - extract<T>(t[2]);
436 throw std::invalid_argument (
"tuple must have length of 3");
443 Vec3_rsubT(
const Vec3<T> &v, T a)
451 template <
class T,
class BoostPyType>
453 Vec3_rsubTuple(
const Vec3<T> &v,
const BoostPyType &t)
458 if(t.attr(
"__len__")() == 3)
460 w.
x = extract<T>(t[0]) - v.
x;
461 w.
y = extract<T>(t[1]) - v.
y;
462 w.
z = extract<T>(t[2]) - v.
z;
465 throw std::invalid_argument (
"tuple must have length of 3");
470 template <
class T,
class BoostPyType>
472 Vec3_addTuple(
const Vec3<T> &v,
const BoostPyType &t)
477 if(t.attr(
"__len__")() == 3)
479 w.
x = v.
x + extract<T>(t[0]);
480 w.
y = v.
y + extract<T>(t[1]);
481 w.
z = v.
z + extract<T>(t[2]);
484 throw std::invalid_argument (
"tuple must have length of 3");
491 Vec3_addT(
const Vec3<T> &v, T a)
499 template <
class T,
class U>
507 template <
class T,
class U>
515 template <
class T,
class U>
523 template <
class T,
class U>
533 mult(
const Vec3<T> &v, tuple t)
538 if(t.attr(
"__len__")() == 1){
539 w.
x = v.
x*extract<T>(t[0]);
540 w.
y = v.
y*extract<T>(t[0]);
541 w.
z = v.
z*extract<T>(t[0]);
543 else if(t.attr(
"__len__")() == 3){
544 w.
x = v.
x*extract<T>(t[0]);
545 w.
y = v.
y*extract<T>(t[1]);
546 w.
z = v.
z*extract<T>(t[2]);
549 throw std::invalid_argument (
"tuple must have length of 1 or 3");
554 template <
class T,
class U>
562 template <
class T,
class BoostPyType>
564 Vec3_divTuple(
const Vec3<T> &v,
const BoostPyType &t)
566 if(t.attr(
"__len__")() == 3)
568 T x = extract<T>(t[0]);
569 T y = extract<T>(t[1]);
570 T z = extract<T>(t[2]);
571 if(x !=
T(0) && y !=
T(0) && z !=
T(0))
574 throw std::domain_error (
"Division by zero");
577 throw std::invalid_argument (
"Vec3 expects tuple of length 3");
580 template <
class T,
class BoostPyType>
582 Vec3_rdivTuple(
const Vec3<T> &v,
const BoostPyType &t)
586 if(t.attr(
"__len__")() == 3)
588 T x = extract<T>(t[0]);
589 T y = extract<T>(t[1]);
590 T z = extract<T>(t[2]);
592 if(v.
x !=
T(0) && v.
y !=
T(0) && v.
z !=
T(0)){
596 throw std::domain_error (
"Division by zero");
599 throw std::invalid_argument (
"tuple must have length of 3");
606 Vec3_divT(
const Vec3<T> &v, T a)
614 throw std::domain_error (
"Division by zero");
621 Vec3_rdivT(
const Vec3<T> &v, T a)
625 if(v.
x !=
T(0) && v.
y !=
T(0) && v.
z !=
T(0)){
629 throw std::domain_error (
"Division by zero");
652 lessThan(
const Vec3<T> &v,
const object &obj)
654 extract<Vec3<T> >
e1(obj);
655 extract<tuple>
e2(obj);
665 T x = extract<T>(t[0]);
666 T y = extract<T>(t[1]);
667 T z = extract<T>(t[2]);
671 throw std::invalid_argument (
"invalid parameters passed to operator <");
673 bool isLessThan = (v.
x <= w.
x && v.
y <= w.
y && v.
z <= w.
z)
681 greaterThan(
const Vec3<T> &v,
const object &obj)
683 extract<Vec3<T> >
e1(obj);
684 extract<tuple>
e2(obj);
694 T x = extract<T>(t[0]);
695 T y = extract<T>(t[1]);
696 T z = extract<T>(t[2]);
700 throw std::invalid_argument (
"invalid parameters passed to operator >");
702 bool isGreaterThan = (v.
x >= w.
x && v.
y >= w.
y && v.
z >= w.
z)
705 return isGreaterThan;
710 lessThanEqual(
const Vec3<T> &v,
const object &obj)
712 extract<Vec3<T> >
e1(obj);
713 extract<tuple>
e2(obj);
723 T x = extract<T>(t[0]);
724 T y = extract<T>(t[1]);
725 T z = extract<T>(t[2]);
729 throw std::invalid_argument (
"invalid parameters passed to operator <=");
731 bool isLessThanEqual = (v.
x <= w.
x && v.
y <= w.
y && v.
z <= w.
z);
733 return isLessThanEqual;
738 greaterThanEqual(
const Vec3<T> &v,
const object &obj)
740 extract<Vec3<T> >
e1(obj);
741 extract<tuple>
e2(obj);
751 T x = extract<T>(t[0]);
752 T y = extract<T>(t[1]);
753 T z = extract<T>(t[2]);
757 throw std::invalid_argument (
"invalid parameters passed to operator >=");
759 bool isGreaterThanEqual = (v.
x >= w.
x && v.
y >= w.
y && v.
z >= w.
z);
761 return isGreaterThanEqual;
767 equalWithAbsErrorObj(
const Vec3<T> &v,
const object &obj1,
const object &obj2)
769 extract<Vec3<int> >
e1(obj1);
770 extract<Vec3<float> >
e2(obj1);
771 extract<Vec3<double> > e3(obj1);
773 extract<tuple>
e4(obj1);
774 extract<double> e5(obj2);
777 if(
e1.check()) { w =
e1(); }
778 else if(
e2.check()) { w =
e2(); }
779 else if(e3.check()) { w = e3(); }
783 if(t.attr(
"__len__")() == 3)
785 w.
x = extract<T>(t[0]);
786 w.
y = extract<T>(t[1]);
787 w.
z = extract<T>(t[2]);
790 throw std::invalid_argument (
"tuple of length 3 expected");
793 throw std::invalid_argument (
"invalid parameters passed to equalWithAbsError");
797 throw std::invalid_argument (
"invalid parameters passed to equalWithAbsError");
802 equalWithRelErrorObj(
const Vec3<T> &v,
const object &obj1,
const object &obj2)
804 extract<Vec3<int> >
e1(obj1);
805 extract<Vec3<float> >
e2(obj1);
806 extract<Vec3<double> > e3(obj1);
808 extract<tuple>
e4(obj1);
809 extract<double> e5(obj2);
812 if(
e1.check()) { w =
e1(); }
813 else if(
e2.check()) { w =
e2(); }
814 else if(e3.check()) { w = e3(); }
818 if(t.attr(
"__len__")() == 3)
820 w.
x = extract<T>(t[0]);
821 w.
y = extract<T>(t[1]);
822 w.
z = extract<T>(t[2]);
825 throw std::invalid_argument (
"tuple of length 3 expected");
828 throw std::invalid_argument (
"invalid parameters passed to equalWithRelError");
832 throw std::invalid_argument (
"invalid parameters passed to equalWithRelError");
842 if(t.attr(
"__len__")() == 3)
844 w.
x = extract<T>(t[0]);
845 w.
y = extract<T>(t[1]);
846 w.
z = extract<T>(t[2]);
851 throw std::invalid_argument (
"tuple of length 3 expected");
856 notequal(
const Vec3<T> &v,
const tuple &t)
859 if(t.attr(
"__len__")() == 3)
861 w.
x = extract<T>(t[0]);
862 w.
y = extract<T>(t[1]);
863 w.
z = extract<T>(t[2]);
868 throw std::invalid_argument (
"tuple of length 3 expected");
878 .def(
"length", &Vec3_length<T>,
"length() magnitude of the vector")
879 .def(
"normalize", &Vec3_normalize<T>,return_internal_reference<>(),
880 "v.normalize() destructively normalizes v and returns a reference to it")
881 .def(
"normalizeExc", &Vec3_normalizeExc<T>,return_internal_reference<>(),
882 "v.normalizeExc() destructively normalizes V and returns a reference to it, throwing an exception if length() == 0")
883 .def(
"normalizeNonNull", &Vec3_normalizeNonNull<T>,return_internal_reference<>(),
884 "v.normalizeNonNull() destructively normalizes V and returns a reference to it, faster if lngth() != 0")
885 .def(
"normalized", &Vec3_normalized<T>,
"v.normalized() returns a normalized copy of v")
886 .def(
"normalizedExc", &Vec3_normalizedExc<T>,
"v.normalizedExc() returns a normalized copy of v, throwing an exception if length() == 0")
887 .def(
"normalizedNonNull", &Vec3_normalizedNonNull<T>,
"v.normalizedNonNull() returns a normalized copy of v, faster if lngth() != 0")
888 .def(
"orthogonal", &orthogonal<T>)
889 .def(
"project", &project<T>)
890 .def(
"reflect", &reflect<T>)
909 .def(
"__init__",make_constructor(Vec3_construct_default<T>),
"initialize to (0,0,0)")
910 .def(
"__init__",make_constructor(Vec3_object_constructor1<T>))
911 .def(
"__init__",make_constructor(Vec3_object_constructor2<T>))
916 .staticmethod(
"baseTypeEpsilon")
917 .def(
"baseTypeMax", &
Vec3<T>::baseTypeMax,
"baseTypeMax() max value of the base type of the vector")
918 .staticmethod(
"baseTypeMax")
919 .def(
"baseTypeLowest", &
Vec3<T>::baseTypeLowest,
"baseTypeLowest() largest negative value of the base type of the vector")
920 .staticmethod(
"baseTypeLowest")
922 .staticmethod(
"baseTypeSmallest")
923 .def(
"cross", &Vec3_cross<T>,
"v1.cross(v2) right handed cross product")
924 .def(
"cross", &Vec3_cross_Vec3Array<T>,
"v1.cross(v2) right handed array cross product")
926 .staticmethod(
"dimensions")
927 .def(
"dot", &Vec3_dot<T>,
"v1.dot(v2) inner product of the two vectors")
928 .def(
"dot", &Vec3_dot_Vec3Array<T>,
"v1.dot(v2) array inner product")
931 "v1.equalWithAbsError(v2) true if the elements "
932 "of v1 and v2 are the same with an absolute error of no more than e, "
933 "i.e., abs(v1[i] - v2[i]) <= e")
934 .def(
"equalWithAbsError", &equalWithAbsErrorObj<T>)
937 "v1.equalWithAbsError(v2) true if the elements "
938 "of v1 and v2 are the same with an absolute error of no more than e, "
939 "i.e., abs(v1[i] - v2[i]) <= e * abs(v1[i])")
940 .def(
"equalWithRelError", &equalWithRelErrorObj<T>)
942 .def(
"length2", &Vec3_length2<T>,
"length2() square magnitude of the vector")
943 .def(
"__len__", Vec3_helper::len)
944 .def(
"__getitem__", Vec3_helper::getitem,return_value_policy<copy_non_const_reference>())
945 .def(
"__setitem__", Vec3_helper::setitem)
946 .def(
"closestVertex", &closestVertex<T>)
947 .def(
"negate", &Vec3_negate<T>, return_internal_reference<>())
948 .def(
"setValue", &setValue<T>)
949 .def(
"__neg__", &Vec3_neg<T>)
950 .def(
"__mul__", &Vec3_mul<T, int>)
951 .def(
"__mul__", &Vec3_mul<T, float>)
952 .def(
"__mul__", &Vec3_mul<T, double>)
953 .def(
"__mul__", &Vec3_mulT<T>)
954 .def(
"__mul__", &Vec3_mulTArray<T>)
955 .def(
"__rmul__", &Vec3_rmulT<T>)
956 .def(
"__rmul__", &Vec3_rmulTArray<T>)
957 .def(
"__imul__", &Vec3_imulV<T, int>,return_internal_reference<>())
958 .def(
"__imul__", &Vec3_imulV<T, float>,return_internal_reference<>())
959 .def(
"__imul__", &Vec3_imulV<T, double>,return_internal_reference<>())
960 .def(
"__imul__", &Vec3_imulT<T>,return_internal_reference<>())
961 .def(
"__div__", &Vec3_Vec3_divT<T>)
962 .def(
"__truediv__", &Vec3_Vec3_divT<T>)
963 .def(
"__mul__", &Vec3_mulM33<T, float>)
964 .def(
"__mul__", &Vec3_mulM33<T, double>)
965 .def(
"__mul__", &Vec3_mulM44<T, float>)
966 .def(
"__mul__", &Vec3_mulM44<T, double>)
967 .def(
"__mul__", &Vec3_Vec3_mulT<T>)
968 .def(
"__div__", &Vec3_div<T,int>)
969 .def(
"__div__", &Vec3_div<T,float>)
970 .def(
"__div__", &Vec3_div<T,double>)
971 .def(
"__div__", &Vec3_divTuple<T,tuple>)
972 .def(
"__div__", &Vec3_divTuple<T,list>)
973 .def(
"__div__", &Vec3_divT<T>)
974 .def(
"__truediv__", &Vec3_div<T,int>)
975 .def(
"__truediv__", &Vec3_div<T,float>)
976 .def(
"__truediv__", &Vec3_div<T,double>)
977 .def(
"__truediv__", &Vec3_divTuple<T,tuple>)
978 .def(
"__truediv__", &Vec3_divTuple<T,list>)
979 .def(
"__truediv__", &Vec3_divT<T>)
980 .def(
"__rdiv__", &Vec3_rdivTuple<T,tuple>)
981 .def(
"__rdiv__", &Vec3_rdivTuple<T,list>)
982 .def(
"__rdiv__", &Vec3_rdivT<T>)
983 .def(
"__rtruediv__", &Vec3_rdivTuple<T,tuple>)
984 .def(
"__rtruediv__", &Vec3_rdivTuple<T,list>)
985 .def(
"__rtruediv__", &Vec3_rdivT<T>)
986 .def(
"__idiv__", &Vec3_idivObj<T>,return_internal_reference<>())
987 .def(
"__itruediv__", &Vec3_idivObj<T>,return_internal_reference<>())
988 .def(
"__xor__", &Vec3_dot<T>)
989 .def(
"__mod__", &Vec3_cross<T>)
992 .def(
"__add__", &Vec3_add<T>)
993 .def(
"__add__", &Vec3_addV<T, int>)
994 .def(
"__add__", &Vec3_addV<T, float>)
995 .def(
"__add__", &Vec3_addV<T, double>)
996 .def(
"__add__", &Vec3_addT<T>)
997 .def(
"__add__", &Vec3_addTuple<T,tuple>)
998 .def(
"__add__", &Vec3_addTuple<T,list>)
999 .def(
"__radd__", &Vec3_addT<T>)
1000 .def(
"__radd__", &Vec3_addTuple<T,tuple>)
1001 .def(
"__radd__", &Vec3_addTuple<T,list>)
1002 .def(
"__radd__", &Vec3_add<T>)
1003 .def(
"__iadd__", &Vec3_iaddV<T, int>, return_internal_reference<>())
1004 .def(
"__iadd__", &Vec3_iaddV<T, float>, return_internal_reference<>())
1005 .def(
"__iadd__", &Vec3_iaddV<T, double>, return_internal_reference<>())
1006 .def(
"__sub__", &Vec3_sub<T>)
1007 .def(
"__sub__", &Vec3_subV<T, int>)
1008 .def(
"__sub__", &Vec3_subV<T, float>)
1009 .def(
"__sub__", &Vec3_subV<T, double>)
1010 .def(
"__sub__", &Vec3_subT<T>)
1011 .def(
"__sub__", &Vec3_subTuple<T,tuple>)
1012 .def(
"__sub__", &Vec3_subTuple<T,list>)
1013 .def(
"__rsub__", &Vec3_rsubT<T>)
1014 .def(
"__rsub__", &Vec3_rsubTuple<T,tuple>)
1015 .def(
"__rsub__", &Vec3_rsubTuple<T,list>)
1016 .def(
"__isub__", &Vec3_isubV<T, int>, return_internal_reference<>())
1017 .def(
"__isub__", &Vec3_isubV<T, float>, return_internal_reference<>())
1018 .def(
"__isub__", &Vec3_isubV<T, double>, return_internal_reference<>())
1019 .def(
"__mul__", &mult<T>)
1020 .def(
"__rmul__", &mult<T>)
1021 .def(
"__imul__", &Vec3_imulM44<T, float>, return_internal_reference<>())
1022 .def(
"__imul__", &Vec3_imulM44<T, double>, return_internal_reference<>())
1023 .def(
"__lt__", &lessThan<T>)
1024 .def(
"__gt__", &greaterThan<T>)
1025 .def(
"__le__", &lessThanEqual<T>)
1026 .def(
"__ge__", &greaterThanEqual<T>)
1027 .def(
"__eq__", &equal<T>)
1028 .def(
"__ne__", ¬equal<T>)
1030 .def(
"__str__",&Vec3_str<T>)
1031 .def(
"__repr__",&Vec3_repr<T>)
1034 register_Vec3_floatonly<T>(vec3_class);
1046 #endif // _PyImathVec3Impl_h_
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithRelError(const Vec3< T > &v, T e) const IMATH_NOEXCEPT
GLsizei const GLfloat * value
IMATH_CONSTEXPR14 Vec3< T > closestVertex(const Vec3< T > &v0, const Vec3< T > &v1, const Vec3< T > &v2, const Line3< T > &l) IMATH_NOEXCEPT
GLdouble GLdouble GLdouble z
GLboolean GLboolean GLboolean GLboolean a
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
void register_Vec3_floatonly(class_< Vec3< T >> &vec3_class)
GLfloat GLfloat GLfloat v2
hboost::python::class_< IMATH_NAMESPACE::Vec3< T > > register_Vec3()
IMATH_HOSTDEVICE void setValue(S a, S b, S c) IMATH_NOEXCEPT
Set the value.
GLboolean GLboolean GLboolean b
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 bool equalWithAbsError(const Vec3< T > &v, T e) const IMATH_NOEXCEPT
GLubyte GLubyte GLubyte GLubyte w
hboost::python::class_< T, X1, X2, X3 > & decoratecopy(hboost::python::class_< T, X1, X2, X3 > &cls)