implement object serialization for Vector class
This commit is contained in:
@@ -18,7 +18,14 @@
|
||||
<DeveloperDocu>This is the Vector export class</DeveloperDocu>
|
||||
<UserDocu>This class represents a 3D float vector</UserDocu>
|
||||
</Documentation>
|
||||
<Methode Name="add" Const="true">
|
||||
<Methode Name="__reduce__" Const="true">
|
||||
<Documentation>
|
||||
<UserDocu>__reduce__()
|
||||
Serialization of Vector objects
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="add" Const="true">
|
||||
<Documentation>
|
||||
<UserDocu>add(Vector)
|
||||
returns the sum of this and another vector
|
||||
@@ -32,7 +39,7 @@
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="negative" Const="true">
|
||||
<Methode Name="negative" Const="true">
|
||||
<Documentation>
|
||||
<UserDocu>negative()
|
||||
returns the negative (opposite) of this vector
|
||||
|
||||
@@ -88,6 +88,26 @@ int VectorPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyObject* VectorPy::__reduce__(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return 0;
|
||||
|
||||
Py::Tuple tuple(2);
|
||||
|
||||
union PyType_Object pyType = {&VectorPy::Type};
|
||||
Py::Object type(pyType.o);
|
||||
tuple.setItem(0, type);
|
||||
|
||||
Base::Vector3d v = this->value();
|
||||
Py::Tuple xyz(3);
|
||||
xyz.setItem(0, Py::Float(v.x));
|
||||
xyz.setItem(1, Py::Float(v.y));
|
||||
xyz.setItem(2, Py::Float(v.z));
|
||||
tuple.setItem(1, xyz);
|
||||
return Py::new_reference_to(tuple);
|
||||
}
|
||||
|
||||
PyObject* VectorPy::number_add_handler(PyObject *self, PyObject *other)
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(VectorPy::Type))) {
|
||||
|
||||
Reference in New Issue
Block a user