| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup pymathutils | 
					
						
							| 
									
										
										
										
											2011-02-27 20:10:08 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 04:15:25 +00:00
										 |  |  | #include <Python.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 12:05:27 +00:00
										 |  |  | #include "mathutils.h"
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 15:44:54 +10:00
										 |  |  | #include "../generic/py_capi_utils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #ifndef MATH_STANDALONE
 | 
					
						
							|  |  |  | #  include "BLI_dynstr.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Higher dimensions are supported, for many common operations | 
					
						
							|  |  |  |  * (dealing with vector/matrix multiply or handling as 3D locations) | 
					
						
							|  |  |  |  * stack memory is used with a fixed size - defined here. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | #define MAX_DIMENSIONS 4
 | 
					
						
							| 
									
										
										
										
											2011-01-07 19:18:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /* Swizzle axes get packed into a single value that is used as a closure. Each
 | 
					
						
							| 
									
										
										
										
											2012-03-03 20:36:09 +00:00
										 |  |  |  * axis uses SWIZZLE_BITS_PER_AXIS bits. The first bit (SWIZZLE_VALID_AXIS) is | 
					
						
							|  |  |  |  * used as a sentinel: if it is unset, the axis is not valid. */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | #define SWIZZLE_BITS_PER_AXIS 3
 | 
					
						
							|  |  |  | #define SWIZZLE_VALID_AXIS 0x4
 | 
					
						
							|  |  |  | #define SWIZZLE_AXIS 0x3
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Vector_copy(VectorObject *self); | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  | static PyObject *Vector_deepcopy(VectorObject *self, PyObject *args); | 
					
						
							| 
									
										
										
										
											2019-08-01 18:34:52 +10:00
										 |  |  | static PyObject *Vector_to_tuple_ex(VectorObject *self, int ndigits); | 
					
						
							| 
									
										
										
										
											2020-09-04 20:59:13 +02:00
										 |  |  | static int row_vector_multiplication(float r_vec[MAX_DIMENSIONS], | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |                                      VectorObject *vec, | 
					
						
							|  |  |  |                                      MatrixObject *mat); | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Supports 2D, 3D, and 4D vector objects both int and float values | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |  * accepted. Mixed float and int values accepted. Ints are parsed to float | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-06-26 14:49:49 +00:00
										 |  |  | static PyObject *Vector_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   float *vec = NULL; | 
					
						
							|  |  |  |   int size = 3; /* default to a 3D vector */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 14:49:49 +00:00
										 |  |  |   if (kwds && PyDict_Size(kwds)) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                     "Vector(): " | 
					
						
							|  |  |  |                     "takes no keyword args"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 08:50:06 +00:00
										 |  |  |   switch (PyTuple_GET_SIZE(args)) { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     case 0: | 
					
						
							|  |  |  |       vec = PyMem_Malloc(size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |       if (vec == NULL) { | 
					
						
							|  |  |  |         PyErr_SetString(PyExc_MemoryError, | 
					
						
							|  |  |  |                         "Vector(): " | 
					
						
							|  |  |  |                         "problem allocating pointer space"); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 17:08:29 +10:00
										 |  |  |       copy_vn_fl(vec, size, 0.0f); | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |       break; | 
					
						
							|  |  |  |     case 1: | 
					
						
							|  |  |  |       if ((size = mathutils_array_parse_alloc( | 
					
						
							|  |  |  |                &vec, 2, PyTuple_GET_ITEM(args, 0), "mathutils.Vector()")) == -1) { | 
					
						
							|  |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                       "mathutils.Vector(): " | 
					
						
							| 
									
										
										
										
											2013-04-07 15:09:06 +00:00
										 |  |  |                       "more than a single arg given"); | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-06-26 16:58:58 +00:00
										 |  |  |   return Vector_CreatePyObject_alloc(vec, size, type); | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-22 14:51:20 +10:00
										 |  |  | static PyObject *vec__apply_to_copy(PyObject *(*vec_func)(VectorObject *), VectorObject *self) | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   PyObject *ret = Vector_copy(self); | 
					
						
							| 
									
										
										
										
											2020-06-22 14:51:20 +10:00
										 |  |  |   PyObject *ret_dummy = vec_func((VectorObject *)ret); | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (ret_dummy) { | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  |     Py_DECREF(ret_dummy); | 
					
						
							|  |  |  |     return (PyObject *)ret; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   /* error */ | 
					
						
							|  |  |  |   Py_DECREF(ret); | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | /*-----------------------CLASS-METHODS----------------------------*/ | 
					
						
							|  |  |  | PyDoc_STRVAR(C_Vector_Fill_doc, | 
					
						
							|  |  |  |              ".. classmethod:: Fill(size, fill=0.0)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Create a vector of length size with all values set to fill.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg size: The length of the vector to be created.\n" | 
					
						
							|  |  |  |              "   :type size: int\n" | 
					
						
							|  |  |  |              "   :arg fill: The value used to fill the vector.\n" | 
					
						
							|  |  |  |              "   :type fill: float\n"); | 
					
						
							|  |  |  | static PyObject *C_Vector_Fill(PyObject *cls, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float *vec; | 
					
						
							|  |  |  |   int size; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   float fill = 0.0f; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "i|f:Vector.Fill", &size, &fill)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (size < 2) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_RuntimeError, "Vector(): invalid size"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   vec = PyMem_Malloc(size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (vec == NULL) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |                     "Vector.Fill(): " | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |                     "problem allocating pointer space"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 17:08:29 +10:00
										 |  |  |   copy_vn_fl(vec, size, fill); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return Vector_CreatePyObject_alloc(vec, size, (PyTypeObject *)cls); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(C_Vector_Range_doc, | 
					
						
							|  |  |  |              ".. classmethod:: Range(start=0, stop, step=1)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Create a filled with a range of values.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg start: The start of the range used to fill the vector.\n" | 
					
						
							|  |  |  |              "   :type start: int\n" | 
					
						
							|  |  |  |              "   :arg stop: The end of the range used to fill the vector.\n" | 
					
						
							|  |  |  |              "   :type stop: int\n" | 
					
						
							|  |  |  |              "   :arg step: The step between successive values in the vector.\n" | 
					
						
							|  |  |  |              "   :type step: int\n"); | 
					
						
							|  |  |  | static PyObject *C_Vector_Range(PyObject *cls, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float *vec; | 
					
						
							|  |  |  |   int stop, size; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   int start = 0; | 
					
						
							|  |  |  |   int step = 1; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, "i|ii:Vector.Range", &start, &stop, &step)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 08:50:06 +00:00
										 |  |  |   switch (PyTuple_GET_SIZE(args)) { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     case 1: | 
					
						
							|  |  |  |       size = start; | 
					
						
							|  |  |  |       start = 0; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case 2: | 
					
						
							|  |  |  |       if (start >= stop) { | 
					
						
							|  |  |  |         PyErr_SetString(PyExc_RuntimeError, | 
					
						
							|  |  |  |                         "Start value is larger " | 
					
						
							|  |  |  |                         "than the stop value"); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |       size = stop - start; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       if (start >= stop) { | 
					
						
							|  |  |  |         PyErr_SetString(PyExc_RuntimeError, | 
					
						
							|  |  |  |                         "Start value is larger " | 
					
						
							|  |  |  |                         "than the stop value"); | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |       size = (stop - start); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |       if ((size % step) != 0) { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |         size += step; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |       size /= step; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |       break; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-02 01:07:04 +00:00
										 |  |  |   if (size < 2) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_RuntimeError, "Vector(): invalid size"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   vec = PyMem_Malloc(size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   if (vec == NULL) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |                     "Vector.Range(): " | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |                     "problem allocating pointer space"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   range_vn_fl(vec, size, (float)start, (float)step); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   return Vector_CreatePyObject_alloc(vec, size, (PyTypeObject *)cls); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(C_Vector_Linspace_doc, | 
					
						
							|  |  |  |              ".. classmethod:: Linspace(start, stop, size)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Create a vector of the specified size which is filled with linearly spaced " | 
					
						
							|  |  |  |              "values between start and stop values.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg start: The start of the range used to fill the vector.\n" | 
					
						
							|  |  |  |              "   :type start: int\n" | 
					
						
							|  |  |  |              "   :arg stop: The end of the range used to fill the vector.\n" | 
					
						
							|  |  |  |              "   :type stop: int\n" | 
					
						
							|  |  |  |              "   :arg size: The size of the vector to be created.\n" | 
					
						
							|  |  |  |              "   :type size: int\n"); | 
					
						
							|  |  |  | static PyObject *C_Vector_Linspace(PyObject *cls, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float *vec; | 
					
						
							|  |  |  |   int size; | 
					
						
							|  |  |  |   float start, end, step; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "ffi:Vector.Linspace", &start, &end, &size)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (size < 2) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_RuntimeError, "Vector.Linspace(): invalid size"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  |   step = (end - start) / (float)(size - 1); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   vec = PyMem_Malloc(size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (vec == NULL) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |                     "Vector.Linspace(): " | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |                     "problem allocating pointer space"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   range_vn_fl(vec, size, start, step); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return Vector_CreatePyObject_alloc(vec, size, (PyTypeObject *)cls); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     C_Vector_Repeat_doc, | 
					
						
							|  |  |  |     ".. classmethod:: Repeat(vector, size)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Create a vector by repeating the values in vector until the required size is reached.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg tuple: The vector to draw values from.\n" | 
					
						
							|  |  |  |     "   :type tuple: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg size: The size of the vector to be created.\n" | 
					
						
							|  |  |  |     "   :type size: int\n"); | 
					
						
							|  |  |  | static PyObject *C_Vector_Repeat(PyObject *cls, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float *vec; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   float *iter_vec = NULL; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   int i, size, value_size; | 
					
						
							|  |  |  |   PyObject *value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "Oi:Vector.Repeat", &value, &size)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (size < 2) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_RuntimeError, "Vector.Repeat(): invalid size"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:42:35 +00:00
										 |  |  |   if ((value_size = mathutils_array_parse_alloc( | 
					
						
							|  |  |  |            &iter_vec, 2, value, "Vector.Repeat(vector, size), invalid 'vector' arg")) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (iter_vec == NULL) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |                     "Vector.Repeat(): " | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |                     "problem allocating pointer space"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   vec = PyMem_Malloc(size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (vec == NULL) { | 
					
						
							| 
									
										
										
										
											2012-06-26 16:58:58 +00:00
										 |  |  |     PyMem_Free(iter_vec); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |                     "Vector.Repeat(): " | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |                     "problem allocating pointer space"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   i = 0; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   while (i < size) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     vec[i] = iter_vec[i % value_size]; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     i++; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   PyMem_Free(iter_vec); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return Vector_CreatePyObject_alloc(vec, size, (PyTypeObject *)cls); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*-----------------------------METHODS---------------------------- */ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_zero_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. method:: zero()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Set all values to zero.\n"); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Vector_zero(VectorObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_Prepare_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 17:08:29 +10:00
										 |  |  |   copy_vn_fl(self->vec, self->size, 0.0f); | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_WriteCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-28 18:42:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_normalize_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. method:: normalize()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Normalize the vector, making the length of the vector always 1.0.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2012-01-03 14:34:41 +00:00
										 |  |  |              "   .. warning:: Normalizing a vector where all values are zero has no effect.\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  |              "   .. note:: Normalize works for vectors of all sizes,\n" | 
					
						
							|  |  |  |              "      however 4D Vectors w axis is left untouched.\n"); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Vector_normalize(VectorObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 16:10:13 +10:00
										 |  |  |   const int size = (self->size == 4 ? 3 : self->size); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 02:12:02 +11:00
										 |  |  |   normalize_vn(self->vec, size); | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							| 
									
										
										
										
											2015-01-30 02:12:02 +11:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_normalized_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              ".. method:: normalized()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return a new, normalized vector.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: a normalized copy of the vector\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`Vector`\n"); | 
					
						
							|  |  |  | static PyObject *Vector_normalized(VectorObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-22 14:51:20 +10:00
										 |  |  |   return vec__apply_to_copy(Vector_normalize, self); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | PyDoc_STRVAR(Vector_resize_doc, | 
					
						
							|  |  |  |              ".. method:: resize(size=3)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Resize the vector to have size number of elements.\n"); | 
					
						
							|  |  |  | static PyObject *Vector_resize(VectorObject *self, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int size; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   if (self->flag & BASE_MATH_FLAG_IS_WRAP) { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                     "Vector.resize(): " | 
					
						
							|  |  |  |                     "cannot resize wrapped data - only python vectors"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (self->cb_user) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                     "Vector.resize(): " | 
					
						
							|  |  |  |                     "cannot resize a vector that has an owner"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 15:44:54 +10:00
										 |  |  |   if ((size = PyC_Long_AsI32(value)) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                     "Vector.resize(size): " | 
					
						
							|  |  |  |                     "expected size argument to be an integer"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   if (size < 2) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_RuntimeError, "Vector.resize(): invalid size"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   self->vec = PyMem_Realloc(self->vec, (size * sizeof(float))); | 
					
						
							|  |  |  |   if (self->vec == NULL) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |                     "Vector.resize(): " | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |                     "problem allocating pointer space"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   /* If the vector has increased in length, set all new elements to 0.0f */ | 
					
						
							|  |  |  |   if (size > self->size) { | 
					
						
							| 
									
										
										
										
											2015-05-05 17:08:29 +10:00
										 |  |  |     copy_vn_fl(self->vec + self->size, size - self->size, 0.0f); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   self->size = size; | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(Vector_resized_doc, | 
					
						
							|  |  |  |              ".. method:: resized(size=3)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return a resized copy of the vector with size number of elements.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: a new vector\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`Vector`\n"); | 
					
						
							|  |  |  | static PyObject *Vector_resized(VectorObject *self, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int size; | 
					
						
							|  |  |  |   float *vec; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 08:50:06 +00:00
										 |  |  |   if ((size = PyLong_AsLong(value)) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (size < 2) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_RuntimeError, "Vector.resized(): invalid size"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   vec = PyMem_Malloc(size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (vec == NULL) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |                     "Vector.resized(): " | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |                     "problem allocating pointer space"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-05 17:08:29 +10:00
										 |  |  |   copy_vn_fl(vec, size, 0.0f); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   memcpy(vec, self->vec, self->size * sizeof(float)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return Vector_CreatePyObject_alloc(vec, size, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_resize_2d_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              ".. method:: resize_2d()\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Resize the vector to 2D  (x, y).\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Vector_resize_2d(VectorObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   if (self->flag & BASE_MATH_FLAG_IS_WRAP) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                     "Vector.resize_2d(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "cannot resize wrapped data - only python vectors"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (self->cb_user) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                     "Vector.resize_2d(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "cannot resize a vector that has an owner"); | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 13:29:21 +10:00
										 |  |  |   self->vec = PyMem_Realloc(self->vec, sizeof(float[2])); | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (self->vec == NULL) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                     "Vector.resize_2d(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "problem allocating pointer space"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   self->size = 2; | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_resize_3d_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              ".. method:: resize_3d()\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Resize the vector to 3D  (x, y, z).\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Vector_resize_3d(VectorObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   if (self->flag & BASE_MATH_FLAG_IS_WRAP) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                     "Vector.resize_3d(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "cannot resize wrapped data - only python vectors"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (self->cb_user) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                     "Vector.resize_3d(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "cannot resize a vector that has an owner"); | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 13:29:21 +10:00
										 |  |  |   self->vec = PyMem_Realloc(self->vec, sizeof(float[3])); | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (self->vec == NULL) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                     "Vector.resize_3d(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "problem allocating pointer space"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (self->size == 2) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     self->vec[2] = 0.0f; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   self->size = 3; | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_resize_4d_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              ".. method:: resize_4d()\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Resize the vector to 4D (x, y, z, w).\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | static PyObject *Vector_resize_4d(VectorObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   if (self->flag & BASE_MATH_FLAG_IS_WRAP) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                     "Vector.resize_4d(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "cannot resize wrapped data - only python vectors"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (self->cb_user) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                     "Vector.resize_4d(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "cannot resize a vector that has an owner"); | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 13:29:21 +10:00
										 |  |  |   self->vec = PyMem_Realloc(self->vec, sizeof(float[4])); | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (self->vec == NULL) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                     "Vector.resize_4d(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "problem allocating pointer space"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (self->size == 2) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     self->vec[2] = 0.0f; | 
					
						
							|  |  |  |     self->vec[3] = 1.0f; | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   else if (self->size == 3) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     self->vec[3] = 1.0f; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   self->size = 4; | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_to_2d_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              ".. method:: to_2d()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return a 2d copy of the vector.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: a new vector\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`Vector`\n"); | 
					
						
							|  |  |  | static PyObject *Vector_to_2d(VectorObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Vector_CreatePyObject(self->vec, 2, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_to_3d_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              ".. method:: to_3d()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return a 3d copy of the vector.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: a new vector\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`Vector`\n"); | 
					
						
							|  |  |  | static PyObject *Vector_to_3d(VectorObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   float tvec[3] = {0.0f}; | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   memcpy(tvec, self->vec, sizeof(float) * MIN2(self->size, 3)); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Vector_CreatePyObject(tvec, 3, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_to_4d_doc, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |              ".. method:: to_4d()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return a 4d copy of the vector.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: a new vector\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`Vector`\n"); | 
					
						
							|  |  |  | static PyObject *Vector_to_4d(VectorObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   float tvec[4] = {0.0f, 0.0f, 0.0f, 1.0f}; | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   memcpy(tvec, self->vec, sizeof(float) * MIN2(self->size, 4)); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Vector_CreatePyObject(tvec, 4, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-11-29 22:42:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_to_tuple_doc, | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  |              ".. method:: to_tuple(precision=-1)\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return this vector as a tuple with.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  |              "   :arg precision: The number to round the value to in [-1, 21].\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "   :type precision: int\n" | 
					
						
							|  |  |  |              "   :return: the values of the vector rounded by *precision*\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |              "   :rtype: tuple\n"); | 
					
						
							| 
									
										
										
										
											2021-07-03 23:08:40 +10:00
										 |  |  | /* NOTE: BaseMath_ReadCallback must be called beforehand. */ | 
					
						
							| 
									
										
										
										
											2019-08-01 18:34:52 +10:00
										 |  |  | static PyObject *Vector_to_tuple_ex(VectorObject *self, int ndigits) | 
					
						
							| 
									
										
										
										
											2009-11-29 22:42:33 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   PyObject *ret; | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  |   int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   ret = PyTuple_New(self->size); | 
					
						
							| 
									
										
										
										
											2009-11-29 22:42:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (ndigits >= 0) { | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     for (i = 0; i < self->size; i++) { | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  |       PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(double_round((double)self->vec[i], ndigits))); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     for (i = 0; i < self->size; i++) { | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  |       PyTuple_SET_ITEM(ret, i, PyFloat_FromDouble(self->vec[i])); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Vector_to_tuple(VectorObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   int ndigits = 0; | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "|i:to_tuple", &ndigits)) { | 
					
						
							| 
									
										
										
										
											2010-05-30 01:42:04 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-05-30 01:42:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (ndigits > 22 || ndigits < 0) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                     "Vector.to_tuple(ndigits): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "ndigits must be between 0 and 21"); | 
					
						
							| 
									
										
										
										
											2009-11-29 22:42:33 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (PyTuple_GET_SIZE(args) == 0) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     ndigits = -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-11-30 22:32:04 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-11-30 22:32:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-01 18:34:52 +10:00
										 |  |  |   return Vector_to_tuple_ex(self, ndigits); | 
					
						
							| 
									
										
										
										
											2009-11-29 22:42:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_to_track_quat_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. method:: to_track_quat(track, up)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return a quaternion rotation from the vector and the track and up axis.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg track: Track axis in ['X', 'Y', 'Z', '-X', '-Y', '-Z'].\n" | 
					
						
							|  |  |  |              "   :type track: string\n" | 
					
						
							|  |  |  |              "   :arg up: Up axis in ['X', 'Y', 'Z'].\n" | 
					
						
							|  |  |  |              "   :type up: string\n" | 
					
						
							| 
									
										
										
										
											2010-05-17 07:33:37 +00:00
										 |  |  |              "   :return: rotation from the vector and the track and up axis.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |              "   :rtype: :class:`Quaternion`\n"); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  | static PyObject *Vector_to_track_quat(VectorObject *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   float vec[3], quat[4]; | 
					
						
							| 
									
										
										
										
											2019-09-23 09:46:31 +02:00
										 |  |  |   const char *strack = NULL; | 
					
						
							|  |  |  |   const char *sup = NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   short track = 2, up = 1; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "|ss:to_track_quat", &strack, &sup)) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   if (self->size != 3) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                     "Vector.to_track_quat(): " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "only for 3D vectors"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   if (strack) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     const char *axis_err_msg = "only X, -X, Y, -Y, Z or -Z for track axis"; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     if (strlen(strack) == 2) { | 
					
						
							|  |  |  |       if (strack[0] == '-') { | 
					
						
							| 
									
										
										
										
											2011-12-18 08:50:06 +00:00
										 |  |  |         switch (strack[1]) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |           case 'X': | 
					
						
							|  |  |  |             track = 3; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |           case 'Y': | 
					
						
							|  |  |  |             track = 4; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |           case 'Z': | 
					
						
							|  |  |  |             track = 5; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |           default: | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |             PyErr_SetString(PyExc_ValueError, axis_err_msg); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |             return NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |         PyErr_SetString(PyExc_ValueError, axis_err_msg); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |         return NULL; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (strlen(strack) == 1) { | 
					
						
							| 
									
										
										
										
											2011-12-18 08:50:06 +00:00
										 |  |  |       switch (strack[0]) { | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  |         case '-': | 
					
						
							|  |  |  |         case 'X': | 
					
						
							|  |  |  |           track = 0; | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case 'Y': | 
					
						
							|  |  |  |           track = 1; | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case 'Z': | 
					
						
							|  |  |  |           track = 2; | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |           PyErr_SetString(PyExc_ValueError, axis_err_msg); | 
					
						
							|  |  |  |           return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     else { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |       PyErr_SetString(PyExc_ValueError, axis_err_msg); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   if (sup) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     const char *axis_err_msg = "only X, Y or Z for up axis"; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     if (strlen(sup) == 1) { | 
					
						
							| 
									
										
										
										
											2011-12-18 08:50:06 +00:00
										 |  |  |       switch (*sup) { | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  |         case 'X': | 
					
						
							|  |  |  |           up = 0; | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case 'Y': | 
					
						
							|  |  |  |           up = 1; | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case 'Z': | 
					
						
							|  |  |  |           up = 2; | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |           PyErr_SetString(PyExc_ValueError, axis_err_msg); | 
					
						
							|  |  |  |           return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     else { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |       PyErr_SetString(PyExc_ValueError, axis_err_msg); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   if (track == up) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, "Can't have the same axis for track and up"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-17 00:54:22 +10:00
										 |  |  |   /* Flip vector around, since #vec_to_quat expect a vector from target to tracking object
 | 
					
						
							|  |  |  |    * and the python function expects the inverse (a vector to the target). */ | 
					
						
							| 
									
										
										
										
											2010-11-28 06:03:30 +00:00
										 |  |  |   negate_v3_v3(vec, self->vec); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   vec_to_quat(quat, vec, track, up); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Quaternion_CreatePyObject(quat, NULL); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-18 00:37:43 +11:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     Vector_orthogonal_doc, | 
					
						
							|  |  |  |     ".. method:: orthogonal()\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Return a perpendicular vector.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :return: a new vector 90 degrees from this vector.\n" | 
					
						
							|  |  |  |     "   :rtype: :class:`Vector`\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   .. note:: the axis is undefined, only use when any orthogonal vector is acceptable.\n"); | 
					
						
							|  |  |  | static PyObject *Vector_orthogonal(VectorObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float vec[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-23 23:08:55 +09:00
										 |  |  |   if (self->size > 3) { | 
					
						
							| 
									
										
										
										
											2014-03-18 00:37:43 +11:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                     "Vector.orthogonal(): " | 
					
						
							| 
									
										
										
										
											2014-07-23 23:08:55 +09:00
										 |  |  |                     "Vector must be 3D or 2D"); | 
					
						
							| 
									
										
										
										
											2014-03-18 00:37:43 +11:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2014-03-18 00:37:43 +11:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-03-18 00:37:43 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (self->size == 3) { | 
					
						
							| 
									
										
										
										
											2014-07-23 23:08:55 +09:00
										 |  |  |     ortho_v3_v3(vec, self->vec); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2014-07-23 23:08:55 +09:00
										 |  |  |     ortho_v2_v2(vec, self->vec); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-03-18 00:37:43 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Vector_CreatePyObject(vec, self->size, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2014-03-18 00:37:43 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Vector.reflect(mirror): return a reflected vector on the mirror normal. | 
					
						
							|  |  |  |  * <pre> | 
					
						
							| 
									
										
										
										
											2018-09-02 18:28:27 +10:00
										 |  |  |  * vec - ((2 * dot(vec, mirror)) * mirror) | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  * </pre> | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_reflect_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. method:: reflect(mirror)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return the reflection vector from the *mirror* argument.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg mirror: This vector could be a normal from the reflecting surface.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "   :type mirror: :class:`Vector`\n" | 
					
						
							|  |  |  |              "   :return: The reflected vector matching the size of this vector.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |              "   :rtype: :class:`Vector`\n"); | 
					
						
							|  |  |  | static PyObject *Vector_reflect(VectorObject *self, PyObject *value) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |   int value_size; | 
					
						
							| 
									
										
										
										
											2009-09-08 03:25:00 +00:00
										 |  |  |   float mirror[3], vec[3]; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |   float reflect[3] = {0.0f}; | 
					
						
							|  |  |  |   float tvec[MAX_DIMENSIONS]; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if ((value_size = mathutils_array_parse( | 
					
						
							|  |  |  |            tvec, 2, 4, value, "Vector.reflect(other), invalid 'other' arg")) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   if (self->size < 2 || self->size > 4) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, "Vector must be 2D, 3D or 4D"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |   mirror[0] = tvec[0]; | 
					
						
							|  |  |  |   mirror[1] = tvec[1]; | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   mirror[2] = (value_size > 2) ? tvec[2] : 0.0f; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   vec[0] = self->vec[0]; | 
					
						
							|  |  |  |   vec[1] = self->vec[1]; | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   vec[2] = (value_size > 2) ? self->vec[2] : 0.0f; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-22 11:10:24 +00:00
										 |  |  |   normalize_v3(mirror); | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  |   reflect_v3_v3v3(reflect, vec, mirror); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Vector_CreatePyObject(reflect, self->size, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_cross_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. method:: cross(other)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return the cross product of this vector and another.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg other: The other vector to perform the cross product with.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "   :type other: :class:`Vector`\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "   :return: The cross product.\n" | 
					
						
							| 
									
										
										
										
											2014-02-05 23:32:51 +11:00
										 |  |  |              "   :rtype: :class:`Vector` or float when 2D vectors are used\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2014-02-05 23:32:51 +11:00
										 |  |  |              "   .. note:: both vectors must be 2D or 3D\n"); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Vector_cross(VectorObject *self, PyObject *value) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-05 23:32:51 +11:00
										 |  |  |   PyObject *ret; | 
					
						
							|  |  |  |   float tvec[3]; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-05 23:32:51 +11:00
										 |  |  |   if (self->size > 3) { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, "Vector must be 2D or 3D"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (mathutils_array_parse( | 
					
						
							|  |  |  |           tvec, self->size, self->size, value, "Vector.cross(other), invalid 'other' arg") == -1) { | 
					
						
							| 
									
										
										
										
											2014-02-05 23:32:51 +11:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-02-05 23:32:51 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (self->size == 3) { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     ret = Vector_CreatePyObject(NULL, 3, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2014-02-05 23:32:51 +11:00
										 |  |  |     cross_v3_v3v3(((VectorObject *)ret)->vec, self->vec, tvec); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     /* size == 2 */ | 
					
						
							|  |  |  |     ret = PyFloat_FromDouble(cross_v2v2(self->vec, tvec)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return ret; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_dot_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. method:: dot(other)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return the dot product of this vector and another.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg other: The other vector to perform the dot product with.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "   :type other: :class:`Vector`\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "   :return: The dot product.\n" | 
					
						
							| 
									
										
										
										
											2020-05-04 14:33:48 +02:00
										 |  |  |              "   :rtype: float\n"); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Vector_dot(VectorObject *self, PyObject *value) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   float *tvec; | 
					
						
							| 
									
										
										
										
											2012-06-26 16:58:58 +00:00
										 |  |  |   PyObject *ret; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   if (mathutils_array_parse_alloc( | 
					
						
							|  |  |  |           &tvec, self->size, value, "Vector.dot(other), invalid 'other' arg") == -1) { | 
					
						
							| 
									
										
										
										
											2012-06-26 16:58:58 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 16:58:58 +00:00
										 |  |  |   ret = PyFloat_FromDouble(dot_vn_vn(self->vec, tvec, self->size)); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   PyMem_Free(tvec); | 
					
						
							| 
									
										
										
										
											2012-06-26 16:58:58 +00:00
										 |  |  |   return ret; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     Vector_angle_doc, | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |     ".. function:: angle(other, fallback=None)\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     "\n" | 
					
						
							|  |  |  |     "   Return the angle between two vectors.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2010-05-30 01:42:04 +00:00
										 |  |  |     "   :arg other: another vector to compare the angle with\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |     "   :type other: :class:`Vector`\n" | 
					
						
							| 
									
										
										
										
											2015-03-06 18:50:58 +11:00
										 |  |  |     "   :arg fallback: return this when the angle can't be calculated (zero length vector),\n" | 
					
						
							|  |  |  |     "      (instead of raising a :exc:`ValueError`).\n" | 
					
						
							| 
									
										
										
										
											2010-08-16 12:14:09 +00:00
										 |  |  |     "   :type fallback: any\n" | 
					
						
							|  |  |  |     "   :return: angle in radians or fallback when given\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     "   :rtype: float\n"); | 
					
						
							| 
									
										
										
										
											2010-05-30 01:42:04 +00:00
										 |  |  | static PyObject *Vector_angle(VectorObject *self, PyObject *args) | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   const int size = MIN2(self->size, 3); /* 4D angle makes no sense */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |   float tvec[MAX_DIMENSIONS]; | 
					
						
							|  |  |  |   PyObject *value; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   double dot = 0.0f, dot_self = 0.0f, dot_other = 0.0f; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |   int x; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   PyObject *fallback = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "O|O:angle", &value, &fallback)) { | 
					
						
							| 
									
										
										
										
											2010-05-30 01:42:04 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-29 19:40:27 +00:00
										 |  |  |   /* don't use clamped size, rule of thumb is vector sizes must match,
 | 
					
						
							|  |  |  |    * even though n this case 'w' is ignored */ | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (mathutils_array_parse( | 
					
						
							|  |  |  |           tvec, self->size, self->size, value, "Vector.angle(other), invalid 'other' arg") == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   if (self->size > 4) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, "Vector must be 2D, 3D or 4D"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   for (x = 0; x < size; x++) { | 
					
						
							| 
									
										
										
										
											2011-11-29 19:40:27 +00:00
										 |  |  |     dot_self += (double)self->vec[x] * (double)self->vec[x]; | 
					
						
							|  |  |  |     dot_other += (double)tvec[x] * (double)tvec[x]; | 
					
						
							|  |  |  |     dot += (double)self->vec[x] * (double)tvec[x]; | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-29 19:40:27 +00:00
										 |  |  |   if (!dot_self || !dot_other) { | 
					
						
							| 
									
										
										
										
											2010-05-30 01:42:04 +00:00
										 |  |  |     /* avoid exception */ | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |     if (fallback) { | 
					
						
							| 
									
										
										
										
											2010-05-30 01:42:04 +00:00
										 |  |  |       Py_INCREF(fallback); | 
					
						
							|  |  |  |       return fallback; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  |                     "Vector.angle(other): " | 
					
						
							|  |  |  |                     "zero length vectors have no valid angle"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-29 19:40:27 +00:00
										 |  |  |   return PyFloat_FromDouble(saacos(dot / (sqrt(dot_self) * sqrt(dot_other)))); | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-14 06:14:15 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     Vector_angle_signed_doc, | 
					
						
							|  |  |  |     ".. function:: angle_signed(other, fallback)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Return the signed angle between two 2D vectors (clockwise is positive).\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg other: another vector to compare the angle with\n" | 
					
						
							|  |  |  |     "   :type other: :class:`Vector`\n" | 
					
						
							| 
									
										
										
										
											2015-03-06 18:50:58 +11:00
										 |  |  |     "   :arg fallback: return this when the angle can't be calculated (zero length vector),\n" | 
					
						
							|  |  |  |     "      (instead of raising a :exc:`ValueError`).\n" | 
					
						
							| 
									
										
										
										
											2012-03-14 06:14:15 +00:00
										 |  |  |     "   :type fallback: any\n" | 
					
						
							|  |  |  |     "   :return: angle in radians or fallback when given\n" | 
					
						
							|  |  |  |     "   :rtype: float\n"); | 
					
						
							|  |  |  | static PyObject *Vector_angle_signed(VectorObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float tvec[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   PyObject *value; | 
					
						
							|  |  |  |   PyObject *fallback = NULL; | 
					
						
							| 
									
										
										
										
											2012-03-14 06:14:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "O|O:angle_signed", &value, &fallback)) { | 
					
						
							| 
									
										
										
										
											2012-03-14 06:14:15 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-14 06:14:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2012-03-14 06:14:15 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-14 06:14:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (mathutils_array_parse( | 
					
						
							|  |  |  |           tvec, 2, 2, value, "Vector.angle_signed(other), invalid 'other' arg") == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (self->size != 2) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, "Vector must be 2D"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (is_zero_v2(self->vec) || is_zero_v2(tvec)) { | 
					
						
							|  |  |  |     /* avoid exception */ | 
					
						
							|  |  |  |     if (fallback) { | 
					
						
							|  |  |  |       Py_INCREF(fallback); | 
					
						
							|  |  |  |       return fallback; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  |                     "Vector.angle_signed(other): " | 
					
						
							|  |  |  |                     "zero length vectors have no valid angle"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-14 06:14:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return PyFloat_FromDouble(angle_signed_v2v2(self->vec, tvec)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_rotation_difference_doc, | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |              ".. function:: rotation_difference(other)\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 15:29:21 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  |              "   Returns a quaternion representing the rotational difference between this\n" | 
					
						
							|  |  |  |              "   vector and another.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 15:29:21 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg other: second vector.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "   :type other: :class:`Vector`\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 15:29:21 +00:00
										 |  |  |              "   :return: the rotational difference between the two vectors.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "   :rtype: :class:`Quaternion`\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |              "   .. note:: 2D vectors raise an :exc:`AttributeError`.\n"); | 
					
						
							| 
									
										
										
										
											2011-04-04 05:17:23 +00:00
										 |  |  | static PyObject *Vector_rotation_difference(VectorObject *self, PyObject *value) | 
					
						
							| 
									
										
										
										
											2010-01-27 15:29:21 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |   float quat[4], vec_a[3], vec_b[3]; | 
					
						
							| 
									
										
										
										
											2010-01-27 15:29:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   if (self->size < 3 || self->size > 4) { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                     "vec.difference(value): " | 
					
						
							|  |  |  |                     "expects both vectors to be size 3 or 4"); | 
					
						
							| 
									
										
										
										
											2010-01-27 15:29:21 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2010-01-27 15:29:21 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-01-27 15:29:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (mathutils_array_parse( | 
					
						
							|  |  |  |           vec_b, 3, MAX_DIMENSIONS, value, "Vector.difference(other), invalid 'other' arg") == | 
					
						
							|  |  |  |       -1) { | 
					
						
							| 
									
										
										
										
											2010-01-27 15:29:21 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-01-27 15:29:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |   normalize_v3_v3(vec_a, self->vec); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |   normalize_v3(vec_b); | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   rotation_between_vecs_to_quat(quat, vec_a, vec_b); | 
					
						
							| 
									
										
										
										
											2010-01-27 15:29:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Quaternion_CreatePyObject(quat, NULL); | 
					
						
							| 
									
										
										
										
											2010-01-27 15:29:21 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_project_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. function:: project(other)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return the projection of this vector onto the *other*.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2010-08-16 12:14:09 +00:00
										 |  |  |              "   :arg other: second vector.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "   :type other: :class:`Vector`\n" | 
					
						
							| 
									
										
										
										
											2010-08-16 12:14:09 +00:00
										 |  |  |              "   :return: the parallel projection vector\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |              "   :rtype: :class:`Vector`\n"); | 
					
						
							|  |  |  | static PyObject *Vector_project(VectorObject *self, PyObject *value) | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   const int size = self->size; | 
					
						
							| 
									
										
										
										
											2018-07-27 17:40:01 +10:00
										 |  |  |   float *tvec; | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |   double dot = 0.0f, dot2 = 0.0f; | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |   int x; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-27 17:40:01 +10:00
										 |  |  |   if (mathutils_array_parse_alloc( | 
					
						
							|  |  |  |           &tvec, size, value, "Vector.project(other), invalid 'other' arg") == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |   /* get dot products */ | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   for (x = 0; x < size; x++) { | 
					
						
							| 
									
										
										
										
											2011-03-28 17:08:33 +00:00
										 |  |  |     dot += (double)(self->vec[x] * tvec[x]); | 
					
						
							|  |  |  |     dot2 += (double)(tvec[x] * tvec[x]); | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |   /* projection */ | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |   dot /= dot2; | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   for (x = 0; x < size; x++) { | 
					
						
							| 
									
										
										
										
											2018-07-27 17:40:01 +10:00
										 |  |  |     tvec[x] *= (float)dot; | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-07-27 17:40:01 +10:00
										 |  |  |   return Vector_CreatePyObject_alloc(tvec, size, Py_TYPE(self)); | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_lerp_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. function:: lerp(other, factor)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Returns the interpolation of two vectors.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg other: value to interpolate with.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "   :type other: :class:`Vector`\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "   :arg factor: The interpolation value in [0.0, 1.0].\n" | 
					
						
							|  |  |  |              "   :type factor: float\n" | 
					
						
							| 
									
										
										
										
											2014-01-09 21:48:41 +11:00
										 |  |  |              "   :return: The interpolated vector.\n" | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |              "   :rtype: :class:`Vector`\n"); | 
					
						
							|  |  |  | static PyObject *Vector_lerp(VectorObject *self, PyObject *args) | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   const int size = self->size; | 
					
						
							|  |  |  |   PyObject *value = NULL; | 
					
						
							| 
									
										
										
										
											2015-02-15 11:31:39 +11:00
										 |  |  |   float fac; | 
					
						
							|  |  |  |   float *tvec; | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "Of:lerp", &value, &fac)) { | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-05-30 01:42:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 16:58:58 +00:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 16:58:58 +00:00
										 |  |  |   if (mathutils_array_parse_alloc(&tvec, size, value, "Vector.lerp(other), invalid 'other' arg") == | 
					
						
							|  |  |  |       -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 11:31:39 +11:00
										 |  |  |   interp_vn_vn(tvec, self->vec, 1.0f - fac, size); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 11:31:39 +11:00
										 |  |  |   return Vector_CreatePyObject_alloc(tvec, size, Py_TYPE(self)); | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  | PyDoc_STRVAR(Vector_slerp_doc, | 
					
						
							|  |  |  |              ".. function:: slerp(other, factor, fallback=None)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2014-04-18 20:44:50 +10:00
										 |  |  |              "   Returns the interpolation of two non-zero vectors (spherical coordinates).\n" | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg other: value to interpolate with.\n" | 
					
						
							|  |  |  |              "   :type other: :class:`Vector`\n" | 
					
						
							| 
									
										
										
										
											2014-04-18 20:44:50 +10:00
										 |  |  |              "   :arg factor: The interpolation value typically in [0.0, 1.0].\n" | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |              "   :type factor: float\n" | 
					
						
							| 
									
										
										
										
											2015-03-06 18:50:58 +11:00
										 |  |  |              "   :arg fallback: return this when the vector can't be calculated (zero length " | 
					
						
							|  |  |  |              "vector or direct opposites),\n" | 
					
						
							|  |  |  |              "      (instead of raising a :exc:`ValueError`).\n" | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |              "   :type fallback: any\n" | 
					
						
							|  |  |  |              "   :return: The interpolated vector.\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`Vector`\n"); | 
					
						
							|  |  |  | static PyObject *Vector_slerp(VectorObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const int size = self->size; | 
					
						
							|  |  |  |   PyObject *value = NULL; | 
					
						
							|  |  |  |   float fac, cosom, w[2]; | 
					
						
							| 
									
										
										
										
											2014-04-18 20:44:50 +10:00
										 |  |  |   float self_vec[3], other_vec[3], ret_vec[3]; | 
					
						
							|  |  |  |   float self_len_sq, other_len_sq; | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |   int x; | 
					
						
							|  |  |  |   PyObject *fallback = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "Of|O:slerp", &value, &fac, &fallback)) { | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |   if (self->size > 3) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, "Vector must be 2D or 3D"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-18 20:44:50 +10:00
										 |  |  |   if (mathutils_array_parse( | 
					
						
							|  |  |  |           other_vec, size, size, value, "Vector.slerp(other), invalid 'other' arg") == -1) { | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-18 20:44:50 +10:00
										 |  |  |   self_len_sq = normalize_vn_vn(self_vec, self->vec, size); | 
					
						
							|  |  |  |   other_len_sq = normalize_vn(other_vec, size); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |   /* use fallbacks for zero length vectors */ | 
					
						
							| 
									
										
										
										
											2014-04-18 20:44:50 +10:00
										 |  |  |   if (UNLIKELY((self_len_sq < FLT_EPSILON) || (other_len_sq < FLT_EPSILON))) { | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |     /* avoid exception */ | 
					
						
							|  |  |  |     if (fallback) { | 
					
						
							|  |  |  |       Py_INCREF(fallback); | 
					
						
							|  |  |  |       return fallback; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  |                     "Vector.slerp(): " | 
					
						
							|  |  |  |                     "zero length vectors unsupported"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |   /* We have sane state, execute slerp */ | 
					
						
							| 
									
										
										
										
											2014-04-18 20:44:50 +10:00
										 |  |  |   cosom = (float)dot_vn_vn(self_vec, other_vec, size); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |   /* direct opposite, can't slerp */ | 
					
						
							|  |  |  |   if (UNLIKELY(cosom < (-1.0f + FLT_EPSILON))) { | 
					
						
							|  |  |  |     /* avoid exception */ | 
					
						
							|  |  |  |     if (fallback) { | 
					
						
							|  |  |  |       Py_INCREF(fallback); | 
					
						
							|  |  |  |       return fallback; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  |                     "Vector.slerp(): " | 
					
						
							|  |  |  |                     "opposite vectors unsupported"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |   interp_dot_slerp(fac, cosom, w); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |   for (x = 0; x < size; x++) { | 
					
						
							| 
									
										
										
										
											2014-04-18 20:44:50 +10:00
										 |  |  |     ret_vec[x] = (w[0] * self_vec[x]) + (w[1] * other_vec[x]); | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Vector_CreatePyObject(ret_vec, size, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 13:57:32 +11:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     Vector_rotate_doc, | 
					
						
							|  |  |  |     ".. function:: rotate(other)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Rotate the vector by a rotation value.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   .. note:: 2D vectors are a special case that can only be rotated by a 2x2 matrix.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg other: rotation component of mathutils value\n" | 
					
						
							|  |  |  |     "   :type other: :class:`Euler`, :class:`Quaternion` or :class:`Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  | static PyObject *Vector_rotate(VectorObject *self, PyObject *value) | 
					
						
							| 
									
										
										
										
											2010-09-29 05:15:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-09-29 05:15:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 13:57:32 +11:00
										 |  |  |   if (self->size == 2) { | 
					
						
							|  |  |  |     /* Special case for 2D Vector with 2x2 matrix, so we avoid resizing it to a 3x3. */ | 
					
						
							|  |  |  |     float other_rmat[2][2]; | 
					
						
							|  |  |  |     MatrixObject *pymat; | 
					
						
							|  |  |  |     if (!Matrix_Parse2x2(value, &pymat)) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     normalize_m2_m2(other_rmat, (const float(*)[2])pymat->matrix); | 
					
						
							|  |  |  |     /* Equivalent to a rotation along the Z axis. */ | 
					
						
							|  |  |  |     mul_m2_v2(other_rmat, self->vec); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-02-20 13:57:32 +11:00
										 |  |  |   else { | 
					
						
							|  |  |  |     float other_rmat[3][3]; | 
					
						
							| 
									
										
										
										
											2010-09-29 05:15:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 13:57:32 +11:00
										 |  |  |     if (mathutils_any_to_rotmat(other_rmat, value, "Vector.rotate(value)") == -1) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-09-29 05:15:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 13:57:32 +11:00
										 |  |  |     mul_m3_v3(other_rmat, self->vec); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-09-29 05:15:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(self); | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2010-09-29 05:15:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_copy_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. function:: copy()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Returns a copy of this vector.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: A copy of the vector.\n" | 
					
						
							| 
									
										
										
										
											2010-01-27 21:33:39 +00:00
										 |  |  |              "   :rtype: :class:`Vector`\n" | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2011-05-26 19:13:01 +00:00
										 |  |  |              "   .. note:: use this to get a copy of a wrapped vector with\n" | 
					
						
							|  |  |  |              "      no reference to the original data.\n"); | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | static PyObject *Vector_copy(VectorObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Vector_CreatePyObject(self->vec, self->size, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  | static PyObject *Vector_deepcopy(VectorObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-06-26 09:26:52 +02:00
										 |  |  |   if (!PyC_CheckArgs_DeepCopy(args)) { | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2018-06-26 09:26:52 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  |   return Vector_copy(self); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | static PyObject *Vector_repr(VectorObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  |   PyObject *ret, *tuple; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-04-19 22:02:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-01 18:34:52 +10:00
										 |  |  |   tuple = Vector_to_tuple_ex(self, -1); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   ret = PyUnicode_FromFormat("Vector(%R)", tuple); | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  |   Py_DECREF(tuple); | 
					
						
							| 
									
										
										
										
											2010-04-19 22:02:53 +00:00
										 |  |  |   return ret; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-04-19 22:02:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #ifndef MATH_STANDALONE
 | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | static PyObject *Vector_str(VectorObject *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DynStr *ds; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   ds = BLI_dynstr_new(); | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   BLI_dynstr_append(ds, "<Vector ("); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; i < self->size; i++) { | 
					
						
							|  |  |  |     BLI_dynstr_appendf(ds, i ? ", %.4f" : "%.4f", self->vec[i]); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   BLI_dynstr_append(ds, ")>"); | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return mathutils_dynstr_to_py(ds); /* frees ds */ | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | /* Sequence Protocol */ | 
					
						
							|  |  |  | /* sequence length len(vector) */ | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | static int Vector_len(VectorObject *self) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   return self->size; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | /* sequence accessor (get): vector[index] */ | 
					
						
							| 
									
										
										
										
											2014-01-28 03:52:21 +11:00
										 |  |  | static PyObject *vector_item_internal(VectorObject *self, int i, const bool is_attr) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (i < 0) { | 
					
						
							|  |  |  |     i = self->size - i; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (i < 0 || i >= self->size) { | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  |     if (is_attr) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |       PyErr_Format(PyExc_AttributeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                    "Vector.%c: unavailable on %dd vector", | 
					
						
							| 
									
										
										
										
											2019-07-04 21:10:06 +10:00
										 |  |  |                    *(((const char *)"xyzw") + i), | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                    self->size); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       PyErr_SetString(PyExc_IndexError, "vector[index]: out of range"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadIndexCallback(self, i) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   return PyFloat_FromDouble(self->vec[i]); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-03-17 04:43:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Vector_item(VectorObject *self, int i) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-14 00:30:56 +00:00
										 |  |  |   return vector_item_internal(self, i, false); | 
					
						
							| 
									
										
										
										
											2011-03-17 04:43:58 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | /* sequence accessor (set): vector[index] = value */ | 
					
						
							| 
									
										
										
										
											2014-01-28 03:52:21 +11:00
										 |  |  | static int vector_ass_item_internal(VectorObject *self, int i, PyObject *value, const bool is_attr) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  |   float scalar; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_Prepare_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-10 14:41:19 +10:00
										 |  |  |   if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { | 
					
						
							|  |  |  |     /* parsed item not a number */ | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                     "vector[index] = x: " | 
					
						
							| 
									
										
										
										
											2014-01-30 16:45:20 +11:00
										 |  |  |                     "assigned value not a number"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (i < 0) { | 
					
						
							|  |  |  |     i = self->size - i; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (i < 0 || i >= self->size) { | 
					
						
							|  |  |  |     if (is_attr) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |       PyErr_Format(PyExc_AttributeError, | 
					
						
							| 
									
										
										
										
											2011-09-19 15:13:16 +00:00
										 |  |  |                    "Vector.%c = x: unavailable on %dd vector", | 
					
						
							| 
									
										
										
										
											2019-07-04 21:10:06 +10:00
										 |  |  |                    *(((const char *)"xyzw") + i), | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                    self->size); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       PyErr_SetString(PyExc_IndexError, | 
					
						
							|  |  |  |                       "vector[index] = x: " | 
					
						
							|  |  |  |                       "assignment index out of range"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-18 23:12:29 +00:00
										 |  |  |   self->vec[i] = scalar; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_WriteIndexCallback(self, i) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-17 04:43:58 +00:00
										 |  |  | static int Vector_ass_item(VectorObject *self, int i, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-14 00:30:56 +00:00
										 |  |  |   return vector_ass_item_internal(self, i, value, false); | 
					
						
							| 
									
										
										
										
											2011-03-17 04:43:58 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | /* sequence slice (get): vector[a:b] */ | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | static PyObject *Vector_slice(VectorObject *self, int begin, int end) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  |   PyObject *tuple; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   int count; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   CLAMP(begin, 0, self->size); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (end < 0) { | 
					
						
							|  |  |  |     end = self->size + end + 1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   CLAMP(end, 0, self->size); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   begin = MIN2(begin, end); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   tuple = PyTuple_New(end - begin); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   for (count = begin; count < end; count++) { | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  |     PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->vec[count])); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-24 03:51:34 +00:00
										 |  |  |   return tuple; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | /* sequence slice (set): vector[a:b] = value */ | 
					
						
							| 
									
										
										
										
											2011-06-02 08:29:16 +00:00
										 |  |  | static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *seq) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   int size = 0; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   float *vec = NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-01-13 21:44:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   CLAMP(begin, 0, self->size); | 
					
						
							|  |  |  |   CLAMP(end, 0, self->size); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   begin = MIN2(begin, end); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-13 21:44:18 +00:00
										 |  |  |   size = (end - begin); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   if (mathutils_array_parse_alloc(&vec, size, seq, "vector[begin:end] = [...]") == -1) { | 
					
						
							| 
									
										
										
										
											2012-06-26 16:58:58 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (vec == NULL) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |                     "vec[:] = seq: " | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |                     "problem allocating pointer space"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   /* Parsed well - now set in vector. */ | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   memcpy(self->vec + begin, vec, size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2011-01-13 21:44:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 16:58:58 +00:00
										 |  |  |   PyMem_Free(vec); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_WriteCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-01-13 21:44:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Numeric Protocols */ | 
					
						
							|  |  |  | /* addition: obj + obj */ | 
					
						
							| 
									
										
										
										
											2011-06-02 08:29:16 +00:00
										 |  |  | static PyObject *Vector_add(PyObject *v1, PyObject *v2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   VectorObject *vec1 = NULL, *vec2 = NULL; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   float *vec = NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |   if (!VectorObject_Check(v1) || !VectorObject_Check(v2)) { | 
					
						
							| 
									
										
										
										
											2011-11-13 09:20:04 +00:00
										 |  |  |     PyErr_Format(PyExc_AttributeError, | 
					
						
							|  |  |  |                  "Vector addition: (%s + %s) " | 
					
						
							|  |  |  |                  "invalid type for this operation", | 
					
						
							|  |  |  |                  Py_TYPE(v1)->tp_name, | 
					
						
							|  |  |  |                  Py_TYPE(v2)->tp_name); | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   vec1 = (VectorObject *)v1; | 
					
						
							|  |  |  |   vec2 = (VectorObject *)v2; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) { | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   /* VECTOR + VECTOR. */ | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (vec1->size != vec2->size) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                     "Vector addition: " | 
					
						
							|  |  |  |                     "vectors must have the same dimensions for this operation"); | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   vec = PyMem_Malloc(vec1->size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   if (vec == NULL) { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							|  |  |  |                     "Vector(): " | 
					
						
							|  |  |  |                     "problem allocating pointer space"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |   add_vn_vnvn(vec, vec1->vec, vec2->vec, vec1->size); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   return Vector_CreatePyObject_alloc(vec, vec1->size, Py_TYPE(v1)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | /* addition in-place: obj += obj */ | 
					
						
							| 
									
										
										
										
											2011-06-02 08:29:16 +00:00
										 |  |  | static PyObject *Vector_iadd(PyObject *v1, PyObject *v2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   VectorObject *vec1 = NULL, *vec2 = NULL; | 
					
						
							| 
									
										
										
										
											2009-11-26 16:19:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!VectorObject_Check(v1) || !VectorObject_Check(v2)) { | 
					
						
							| 
									
										
										
										
											2011-11-13 09:20:04 +00:00
										 |  |  |     PyErr_Format(PyExc_AttributeError, | 
					
						
							|  |  |  |                  "Vector addition: (%s += %s) " | 
					
						
							|  |  |  |                  "invalid type for this operation", | 
					
						
							|  |  |  |                  Py_TYPE(v1)->tp_name, | 
					
						
							|  |  |  |                  Py_TYPE(v2)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-11-26 16:19:20 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   vec1 = (VectorObject *)v1; | 
					
						
							|  |  |  |   vec2 = (VectorObject *)v2; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (vec1->size != vec2->size) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                     "Vector addition: " | 
					
						
							|  |  |  |                     "vectors must have the same dimensions for this operation"); | 
					
						
							| 
									
										
										
										
											2009-11-26 16:19:20 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) { | 
					
						
							| 
									
										
										
										
											2009-11-26 16:19:20 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-11-26 16:19:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |   add_vn_vn(vec1->vec, vec2->vec, vec1->size); | 
					
						
							| 
									
										
										
										
											2009-11-26 16:19:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(vec1); | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |   Py_INCREF(v1); | 
					
						
							| 
									
										
										
										
											2009-11-26 16:19:20 +00:00
										 |  |  |   return v1; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | /* subtraction: obj - obj */ | 
					
						
							| 
									
										
										
										
											2011-06-02 08:29:16 +00:00
										 |  |  | static PyObject *Vector_sub(PyObject *v1, PyObject *v2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   VectorObject *vec1 = NULL, *vec2 = NULL; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   float *vec; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!VectorObject_Check(v1) || !VectorObject_Check(v2)) { | 
					
						
							| 
									
										
										
										
											2011-11-13 09:20:04 +00:00
										 |  |  |     PyErr_Format(PyExc_AttributeError, | 
					
						
							|  |  |  |                  "Vector subtraction: (%s - %s) " | 
					
						
							|  |  |  |                  "invalid type for this operation", | 
					
						
							|  |  |  |                  Py_TYPE(v1)->tp_name, | 
					
						
							|  |  |  |                  Py_TYPE(v2)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   vec1 = (VectorObject *)v1; | 
					
						
							|  |  |  |   vec2 = (VectorObject *)v2; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (vec1->size != vec2->size) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                     "Vector subtraction: " | 
					
						
							|  |  |  |                     "vectors must have the same dimensions for this operation"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   vec = PyMem_Malloc(vec1->size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   if (vec == NULL) { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							|  |  |  |                     "Vector(): " | 
					
						
							|  |  |  |                     "problem allocating pointer space"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |   sub_vn_vnvn(vec, vec1->vec, vec2->vec, vec1->size); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   return Vector_CreatePyObject_alloc(vec, vec1->size, Py_TYPE(v1)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | /* subtraction in-place: obj -= obj */ | 
					
						
							| 
									
										
										
										
											2011-06-02 08:29:16 +00:00
										 |  |  | static PyObject *Vector_isub(PyObject *v1, PyObject *v2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   VectorObject *vec1 = NULL, *vec2 = NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!VectorObject_Check(v1) || !VectorObject_Check(v2)) { | 
					
						
							| 
									
										
										
										
											2011-11-13 09:20:04 +00:00
										 |  |  |     PyErr_Format(PyExc_AttributeError, | 
					
						
							|  |  |  |                  "Vector subtraction: (%s -= %s) " | 
					
						
							|  |  |  |                  "invalid type for this operation", | 
					
						
							|  |  |  |                  Py_TYPE(v1)->tp_name, | 
					
						
							|  |  |  |                  Py_TYPE(v2)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   vec1 = (VectorObject *)v1; | 
					
						
							|  |  |  |   vec2 = (VectorObject *)v2; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (vec1->size != vec2->size) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                     "Vector subtraction: " | 
					
						
							|  |  |  |                     "vectors must have the same dimensions for this operation"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |   sub_vn_vn(vec1->vec, vec2->vec, vec1->size); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(vec1); | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |   Py_INCREF(v1); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   return v1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*------------------------obj * obj------------------------------
 | 
					
						
							| 
									
										
										
										
											2012-09-26 20:05:38 +00:00
										 |  |  |  * multiplication */ | 
					
						
							| 
									
										
										
										
											2010-11-12 01:38:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2018-09-02 18:28:27 +10:00
										 |  |  |  * Column vector multiplication (Matrix * Vector). | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  * <pre> | 
					
						
							| 
									
										
										
										
											2012-01-03 14:34:41 +00:00
										 |  |  |  * [1][4][7]   [a] | 
					
						
							|  |  |  |  * [2][5][8] * [b] | 
					
						
							|  |  |  |  * [3][6][9]   [c] | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  * </pre> | 
					
						
							| 
									
										
										
										
											2010-11-12 01:38:18 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  * \note Vector/Matrix multiplication is not commutative. | 
					
						
							|  |  |  |  * \note Assume read callbacks have been done first. | 
					
						
							| 
									
										
										
										
											2010-11-12 01:38:18 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | int column_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat) | 
					
						
							| 
									
										
										
										
											2010-11-12 01:38:18 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |   float vec_cpy[MAX_DIMENSIONS]; | 
					
						
							| 
									
										
										
										
											2011-12-20 11:37:55 +00:00
										 |  |  |   int row, col, z = 0; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (mat->num_col != vec->size) { | 
					
						
							|  |  |  |     if (mat->num_col == 4 && vec->size == 3) { | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |       vec_cpy[3] = 1.0f; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2012-02-11 14:27:36 +00:00
										 |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                       "matrix * vector: " | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |                       "len(matrix.col) and len(vector) must be the same, " | 
					
						
							| 
									
										
										
										
											2012-01-03 14:34:41 +00:00
										 |  |  |                       "except for 4x4 matrix * 3D vector."); | 
					
						
							| 
									
										
										
										
											2010-11-12 01:38:18 +00:00
										 |  |  |       return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |   memcpy(vec_cpy, vec->vec, vec->size * sizeof(float)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 11:37:55 +00:00
										 |  |  |   r_vec[3] = 1.0f; | 
					
						
							| 
									
										
										
										
											2010-11-12 01:38:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 11:37:55 +00:00
										 |  |  |   for (row = 0; row < mat->num_row; row++) { | 
					
						
							| 
									
										
										
										
											2011-12-26 00:42:35 +00:00
										 |  |  |     double dot = 0.0f; | 
					
						
							| 
									
										
										
										
											2011-12-20 11:37:55 +00:00
										 |  |  |     for (col = 0; col < mat->num_col; col++) { | 
					
						
							|  |  |  |       dot += (double)(MATRIX_ITEM(mat, row, col) * vec_cpy[col]); | 
					
						
							| 
									
										
										
										
											2010-11-12 01:38:18 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-12-20 11:37:55 +00:00
										 |  |  |     r_vec[z++] = (float)dot; | 
					
						
							| 
									
										
										
										
											2010-11-12 01:38:18 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-12 01:38:18 +00:00
										 |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  | static PyObject *vector_mul_float(VectorObject *vec, const float scalar) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   float *tvec = PyMem_Malloc(vec->size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   if (tvec == NULL) { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							|  |  |  |                     "vec * float: " | 
					
						
							|  |  |  |                     "problem allocating pointer space"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |   mul_vn_vn_fl(tvec, vec->vec, vec->size, scalar); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   return Vector_CreatePyObject_alloc(tvec, vec->size, Py_TYPE(vec)); | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-07-14 22:45:33 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | static PyObject *vector_mul_vec(VectorObject *vec1, VectorObject *vec2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float *tvec = PyMem_Malloc(vec1->size * sizeof(float)); | 
					
						
							|  |  |  |   if (tvec == NULL) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                     "vec * vec: " | 
					
						
							|  |  |  |                     "problem allocating pointer space"); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   mul_vn_vnvn(tvec, vec1->vec, vec2->vec, vec1->size); | 
					
						
							|  |  |  |   return Vector_CreatePyObject_alloc(tvec, vec1->size, Py_TYPE(vec1)); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-07-14 22:45:33 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-02 08:29:16 +00:00
										 |  |  | static PyObject *Vector_mul(PyObject *v1, PyObject *v2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   VectorObject *vec1 = NULL, *vec2 = NULL; | 
					
						
							| 
									
										
										
										
											2009-06-18 23:12:29 +00:00
										 |  |  |   float scalar; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   if (VectorObject_Check(v1)) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     vec1 = (VectorObject *)v1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(vec1) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   if (VectorObject_Check(v2)) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     vec2 = (VectorObject *)v2; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(vec2) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-21 11:03:37 +11:00
										 |  |  |   /* Intentionally don't support (Quaternion) here, uses reverse order instead. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   /* make sure v1 is always the vector */ | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   if (vec1 && vec2) { | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |     if (vec1->size != vec2->size) { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                       "Vector multiplication: " | 
					
						
							|  |  |  |                       "vectors must have the same dimensions for this operation"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     /* element-wise product */ | 
					
						
							|  |  |  |     return vector_mul_vec(vec1, vec2); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (vec1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* VEC * FLOAT */ | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  |       return vector_mul_float(vec1, scalar); | 
					
						
							| 
									
										
										
										
											2010-08-02 00:08:01 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  |   else if (vec2) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     if (((scalar = PyFloat_AsDouble(v1)) == -1.0f && PyErr_Occurred()) == 0) { /* FLOAT * VEC */ | 
					
						
							| 
									
										
										
										
											2011-01-09 09:16:04 +00:00
										 |  |  |       return vector_mul_float(vec2, scalar); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-06-18 23:12:29 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |   PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                "Element-wise multiplication: " | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  |                Py_TYPE(v1)->tp_name, | 
					
						
							|  |  |  |                Py_TYPE(v2)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-26 20:05:38 +00:00
										 |  |  | /* multiplication in-place: obj *= obj */ | 
					
						
							| 
									
										
										
										
											2011-06-02 08:29:16 +00:00
										 |  |  | static PyObject *Vector_imul(PyObject *v1, PyObject *v2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   VectorObject *vec1 = NULL, *vec2 = NULL; | 
					
						
							| 
									
										
										
										
											2009-06-18 23:12:29 +00:00
										 |  |  |   float scalar; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   if (VectorObject_Check(v1)) { | 
					
						
							|  |  |  |     vec1 = (VectorObject *)v1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(vec1) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (VectorObject_Check(v2)) { | 
					
						
							|  |  |  |     vec2 = (VectorObject *)v2; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(vec2) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(vec1) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-21 11:03:37 +11:00
										 |  |  |   /* Intentionally don't support (Quaternion, Matrix) here, uses reverse order instead. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   if (vec1 && vec2) { | 
					
						
							|  |  |  |     if (vec1->size != vec2->size) { | 
					
						
							|  |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                       "Vector multiplication: " | 
					
						
							|  |  |  |                       "vectors must have the same dimensions for this operation"); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-14 22:45:33 +10:00
										 |  |  |     /* Element-wise product in-place. */ | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     mul_vn_vn(vec1->vec, vec2->vec, vec1->size); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (vec1 && (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == | 
					
						
							|  |  |  |                     0)) { /* VEC *= FLOAT */ | 
					
						
							|  |  |  |     mul_vn_fl(vec1->vec, vec1->size, scalar); | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2011-11-13 09:20:04 +00:00
										 |  |  |     PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2019-08-04 12:51:44 +10:00
										 |  |  |                  "In place element-wise multiplication: " | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                  "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  |                  Py_TYPE(v1)->tp_name, | 
					
						
							|  |  |  |                  Py_TYPE(v2)->tp_name); | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-18 23:12:29 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   (void)BaseMath_WriteCallback(vec1); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   Py_INCREF(v1); | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |   return v1; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  | static PyObject *Vector_matmul(PyObject *v1, PyObject *v2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   VectorObject *vec1 = NULL, *vec2 = NULL; | 
					
						
							|  |  |  |   int vec_size; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   if (VectorObject_Check(v1)) { | 
					
						
							|  |  |  |     vec1 = (VectorObject *)v1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(vec1) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (VectorObject_Check(v2)) { | 
					
						
							|  |  |  |     vec2 = (VectorObject *)v2; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (BaseMath_ReadCallback(vec2) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   /* Intentionally don't support (Quaternion) here, uses reverse order instead. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   /* make sure v1 is always the vector */ | 
					
						
							|  |  |  |   if (vec1 && vec2) { | 
					
						
							|  |  |  |     if (vec1->size != vec2->size) { | 
					
						
							|  |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                       "Vector multiplication: " | 
					
						
							|  |  |  |                       "vectors must have the same dimensions for this operation"); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |     /* Dot product. */ | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     return PyFloat_FromDouble(dot_vn_vn(vec1->vec, vec2->vec, vec1->size)); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (vec1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     if (MatrixObject_Check(v2)) { | 
					
						
							|  |  |  |       /* VEC @ MATRIX */ | 
					
						
							|  |  |  |       float tvec[MAX_DIMENSIONS]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |       if (BaseMath_ReadCallback((MatrixObject *)v2) == -1) { | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       if (row_vector_multiplication(tvec, vec1, (MatrixObject *)v2) == -1) { | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       if (((MatrixObject *)v2)->num_row == 4 && vec1->size == 3) { | 
					
						
							|  |  |  |         vec_size = 3; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         vec_size = ((MatrixObject *)v2)->num_col; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |       return Vector_CreatePyObject(tvec, vec_size, Py_TYPE(vec1)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                "Vector multiplication: " | 
					
						
							|  |  |  |                "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  |                Py_TYPE(v1)->tp_name, | 
					
						
							|  |  |  |                Py_TYPE(v2)->tp_name); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Vector_imatmul(PyObject *v1, PyObject *v2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2019-08-04 12:51:44 +10:00
										 |  |  |                "In place vector multiplication: " | 
					
						
							| 
									
										
										
										
											2018-08-22 10:10:12 +10:00
										 |  |  |                "not supported between '%.200s' and '%.200s' types", | 
					
						
							|  |  |  |                Py_TYPE(v1)->tp_name, | 
					
						
							|  |  |  |                Py_TYPE(v2)->tp_name); | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |   return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | /* divid: obj / obj */ | 
					
						
							| 
									
										
										
										
											2011-06-02 08:29:16 +00:00
										 |  |  | static PyObject *Vector_div(PyObject *v1, PyObject *v2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   float *vec = NULL, scalar; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   VectorObject *vec1 = NULL; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (!VectorObject_Check(v1)) { /* not a vector */ | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                     "Vector division: " | 
					
						
							|  |  |  |                     "Vector must be divided by a float"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   vec1 = (VectorObject *)v1; /* vector */ | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(vec1) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-10 14:41:19 +10:00
										 |  |  |   if ((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) { | 
					
						
							|  |  |  |     /* parsed item not a number */ | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                     "Vector division: " | 
					
						
							|  |  |  |                     "Vector must be divided by a float"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   if (scalar == 0.0f) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_ZeroDivisionError, | 
					
						
							|  |  |  |                     "Vector division: " | 
					
						
							|  |  |  |                     "divide by zero error"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   vec = PyMem_Malloc(vec1->size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   if (vec == NULL) { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							|  |  |  |                     "vec / value: " | 
					
						
							|  |  |  |                     "problem allocating pointer space"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   mul_vn_vn_fl(vec, vec1->vec, vec1->size, 1.0f / scalar); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return Vector_CreatePyObject_alloc(vec, vec1->size, Py_TYPE(v1)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | /* divide in-place: obj /= obj */ | 
					
						
							| 
									
										
										
										
											2011-06-02 08:29:16 +00:00
										 |  |  | static PyObject *Vector_idiv(PyObject *v1, PyObject *v2) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   float scalar; | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   VectorObject *vec1 = (VectorObject *)v1; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(vec1) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-06-18 23:12:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-10 14:41:19 +10:00
										 |  |  |   if ((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) { | 
					
						
							|  |  |  |     /* parsed item not a number */ | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                     "Vector division: " | 
					
						
							|  |  |  |                     "Vector must be divided by a float"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   if (scalar == 0.0f) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_ZeroDivisionError, | 
					
						
							|  |  |  |                     "Vector division: " | 
					
						
							|  |  |  |                     "divide by zero error"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   mul_vn_fl(vec1->vec, vec1->size, 1.0f / scalar); | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(vec1); | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   Py_INCREF(v1); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   return v1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  | /* -obj
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |  * Returns the negative of this object. */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | static PyObject *Vector_neg(VectorObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   float *tvec; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   tvec = PyMem_Malloc(self->size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |   negate_vn_vn(tvec, self->vec, self->size); | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   return Vector_CreatePyObject_alloc(tvec, self->size, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*------------------------tp_richcmpr
 | 
					
						
							| 
									
										
										
										
											2012-07-16 23:23:33 +00:00
										 |  |  |  * returns -1 exception, 0 false, 1 true */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   VectorObject *vecA = NULL, *vecB = NULL; | 
					
						
							|  |  |  |   int result = 0; | 
					
						
							| 
									
										
										
										
											2020-08-20 16:10:13 +10:00
										 |  |  |   const double epsilon = 0.000001f; | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   double lenA, lenB; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (!VectorObject_Check(objectA) || !VectorObject_Check(objectB)) { | 
					
						
							|  |  |  |     if (comparison_type == Py_NE) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |       Py_RETURN_TRUE; | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Py_RETURN_FALSE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   vecA = (VectorObject *)objectA; | 
					
						
							|  |  |  |   vecB = (VectorObject *)objectB; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(vecA) == -1 || BaseMath_ReadCallback(vecB) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (vecA->size != vecB->size) { | 
					
						
							|  |  |  |     if (comparison_type == Py_NE) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |       Py_RETURN_TRUE; | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Py_RETURN_FALSE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   switch (comparison_type) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     case Py_LT: | 
					
						
							| 
									
										
										
										
											2014-03-31 11:17:46 +11:00
										 |  |  |       lenA = len_squared_vn(vecA->vec, vecA->size); | 
					
						
							|  |  |  |       lenB = len_squared_vn(vecB->vec, vecB->size); | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |       if (lenA < lenB) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |         result = 1; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case Py_LE: | 
					
						
							| 
									
										
										
										
											2014-03-31 11:17:46 +11:00
										 |  |  |       lenA = len_squared_vn(vecA->vec, vecA->size); | 
					
						
							|  |  |  |       lenB = len_squared_vn(vecB->vec, vecB->size); | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |       if (lenA < lenB) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |         result = 1; | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |         result = (((lenA + epsilon) > lenB) && ((lenA - epsilon) < lenB)); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case Py_EQ: | 
					
						
							|  |  |  |       result = EXPP_VectorsAreEqual(vecA->vec, vecB->vec, vecA->size, 1); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case Py_NE: | 
					
						
							| 
									
										
										
										
											2010-02-28 19:27:06 +00:00
										 |  |  |       result = !EXPP_VectorsAreEqual(vecA->vec, vecB->vec, vecA->size, 1); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |       break; | 
					
						
							|  |  |  |     case Py_GT: | 
					
						
							| 
									
										
										
										
											2014-03-31 11:17:46 +11:00
										 |  |  |       lenA = len_squared_vn(vecA->vec, vecA->size); | 
					
						
							|  |  |  |       lenB = len_squared_vn(vecB->vec, vecB->size); | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |       if (lenA > lenB) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |         result = 1; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case Py_GE: | 
					
						
							| 
									
										
										
										
											2014-03-31 11:17:46 +11:00
										 |  |  |       lenA = len_squared_vn(vecA->vec, vecA->size); | 
					
						
							|  |  |  |       lenB = len_squared_vn(vecB->vec, vecB->size); | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |       if (lenA > lenB) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |         result = 1; | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |         result = (((lenA + epsilon) > lenB) && ((lenA - epsilon) < lenB)); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       printf("The result of the comparison could not be evaluated"); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (result == 1) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     Py_RETURN_TRUE; | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_RETURN_FALSE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | static Py_hash_t Vector_hash(VectorObject *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMathObject_Prepare_ForHash(self) == -1) { | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return mathutils_array_hash(self->vec, self->size); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*-----------------PROTCOL DECLARATIONS--------------------------*/ | 
					
						
							|  |  |  | static PySequenceMethods Vector_SeqMethods = { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     (lenfunc)Vector_len,              /* sq_length */ | 
					
						
							|  |  |  |     (binaryfunc)NULL,                 /* sq_concat */ | 
					
						
							|  |  |  |     (ssizeargfunc)NULL,               /* sq_repeat */ | 
					
						
							|  |  |  |     (ssizeargfunc)Vector_item,        /* sq_item */ | 
					
						
							|  |  |  |     NULL,                             /* py3 deprecated slice func */ | 
					
						
							|  |  |  |     (ssizeobjargproc)Vector_ass_item, /* sq_ass_item */ | 
					
						
							|  |  |  |     NULL,                             /* py3 deprecated slice assign func */ | 
					
						
							|  |  |  |     (objobjproc)NULL,                 /* sq_contains */ | 
					
						
							|  |  |  |     (binaryfunc)NULL,                 /* sq_inplace_concat */ | 
					
						
							|  |  |  |     (ssizeargfunc)NULL,               /* sq_inplace_repeat */ | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *Vector_subscript(VectorObject *self, PyObject *item) | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   if (PyIndex_Check(item)) { | 
					
						
							|  |  |  |     Py_ssize_t i; | 
					
						
							|  |  |  |     i = PyNumber_AsSsize_t(item, PyExc_IndexError); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (i == -1 && PyErr_Occurred()) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (i < 0) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       i += self->size; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     return Vector_item(self, i); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (PySlice_Check(item)) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     Py_ssize_t start, stop, step, slicelength; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (PySlice_GetIndicesEx(item, self->size, &start, &stop, &step, &slicelength) < 0) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     if (slicelength <= 0) { | 
					
						
							| 
									
										
										
										
											2011-02-04 03:39:06 +00:00
										 |  |  |       return PyTuple_New(0); | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |     if (step == 1) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       return Vector_slice(self, start, stop); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   PyErr_Format( | 
					
						
							|  |  |  |       PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name); | 
					
						
							|  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *value) | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   if (PyIndex_Check(item)) { | 
					
						
							|  |  |  |     Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (i == -1 && PyErr_Occurred()) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (i < 0) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       i += self->size; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     return Vector_ass_item(self, i, value); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (PySlice_Check(item)) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     Py_ssize_t start, stop, step, slicelength; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (PySlice_GetIndicesEx(item, self->size, &start, &stop, &step, &slicelength) < 0) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     if (step == 1) { | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |       return Vector_ass_slice(self, start, stop, value); | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   PyErr_Format( | 
					
						
							|  |  |  |       PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name); | 
					
						
							|  |  |  |   return -1; | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyMappingMethods Vector_AsMapping = { | 
					
						
							|  |  |  |     (lenfunc)Vector_len, | 
					
						
							|  |  |  |     (binaryfunc)Vector_subscript, | 
					
						
							| 
									
										
										
										
											2019-01-19 13:21:18 +11:00
										 |  |  |     (objobjargproc)Vector_ass_subscript, | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-08-10 00:07:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-28 13:27:06 +00:00
										 |  |  | static PyNumberMethods Vector_NumMethods = { | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     (binaryfunc)Vector_add,     /*nb_add*/ | 
					
						
							|  |  |  |     (binaryfunc)Vector_sub,     /*nb_subtract*/ | 
					
						
							|  |  |  |     (binaryfunc)Vector_mul,     /*nb_multiply*/ | 
					
						
							|  |  |  |     NULL,                       /*nb_remainder*/ | 
					
						
							|  |  |  |     NULL,                       /*nb_divmod*/ | 
					
						
							|  |  |  |     NULL,                       /*nb_power*/ | 
					
						
							|  |  |  |     (unaryfunc)Vector_neg,      /*nb_negative*/ | 
					
						
							| 
									
										
										
										
											2012-08-27 13:40:19 +00:00
										 |  |  |     (unaryfunc)Vector_copy,     /*tp_positive*/ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     (unaryfunc)NULL,            /*tp_absolute*/ | 
					
						
							|  |  |  |     (inquiry)NULL,              /*tp_bool*/ | 
					
						
							|  |  |  |     (unaryfunc)NULL,            /*nb_invert*/ | 
					
						
							|  |  |  |     NULL,                       /*nb_lshift*/ | 
					
						
							|  |  |  |     (binaryfunc)NULL,           /*nb_rshift*/ | 
					
						
							|  |  |  |     NULL,                       /*nb_and*/ | 
					
						
							|  |  |  |     NULL,                       /*nb_xor*/ | 
					
						
							|  |  |  |     NULL,                       /*nb_or*/ | 
					
						
							|  |  |  |     NULL,                       /*nb_int*/ | 
					
						
							|  |  |  |     NULL,                       /*nb_reserved*/ | 
					
						
							|  |  |  |     NULL,                       /*nb_float*/ | 
					
						
							|  |  |  |     Vector_iadd,                /* nb_inplace_add */ | 
					
						
							|  |  |  |     Vector_isub,                /* nb_inplace_subtract */ | 
					
						
							|  |  |  |     Vector_imul,                /* nb_inplace_multiply */ | 
					
						
							|  |  |  |     NULL,                       /* nb_inplace_remainder */ | 
					
						
							|  |  |  |     NULL,                       /* nb_inplace_power */ | 
					
						
							|  |  |  |     NULL,                       /* nb_inplace_lshift */ | 
					
						
							|  |  |  |     NULL,                       /* nb_inplace_rshift */ | 
					
						
							|  |  |  |     NULL,                       /* nb_inplace_and */ | 
					
						
							|  |  |  |     NULL,                       /* nb_inplace_xor */ | 
					
						
							|  |  |  |     NULL,                       /* nb_inplace_or */ | 
					
						
							|  |  |  |     NULL,                       /* nb_floor_divide */ | 
					
						
							|  |  |  |     Vector_div,                 /* nb_true_divide */ | 
					
						
							|  |  |  |     NULL,                       /* nb_inplace_floor_divide */ | 
					
						
							|  |  |  |     Vector_idiv,                /* nb_inplace_true_divide */ | 
					
						
							|  |  |  |     NULL,                       /* nb_index */ | 
					
						
							| 
									
										
										
										
											2018-08-10 14:53:38 +02:00
										 |  |  |     (binaryfunc)Vector_matmul,  /* nb_matrix_multiply */ | 
					
						
							|  |  |  |     (binaryfunc)Vector_imatmul, /* nb_inplace_matrix_multiply */ | 
					
						
							| 
									
										
										
										
											2009-06-28 13:27:06 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*------------------PY_OBECT DEFINITION--------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | /* vector axis, vector.x/y/z/w */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(Vector_axis_x_doc, "Vector X axis.\n\n:type: float"); | 
					
						
							|  |  |  | PyDoc_STRVAR(Vector_axis_y_doc, "Vector Y axis.\n\n:type: float"); | 
					
						
							|  |  |  | PyDoc_STRVAR(Vector_axis_z_doc, "Vector Z axis (3D Vectors only).\n\n:type: float"); | 
					
						
							|  |  |  | PyDoc_STRVAR(Vector_axis_w_doc, "Vector W axis (4D Vectors only).\n\n:type: float"); | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static PyObject *Vector_axis_get(VectorObject *self, void *type) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 12:05:58 +10:00
										 |  |  |   return vector_item_internal(self, POINTER_AS_INT(type), true); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static int Vector_axis_set(VectorObject *self, PyObject *value, void *type) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-19 12:05:58 +10:00
										 |  |  |   return vector_ass_item_internal(self, POINTER_AS_INT(type), value, true); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* vector.length */ | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(Vector_length_doc, "Vector Length.\n\n:type: float"); | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static PyObject *Vector_length_get(VectorObject *self, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   return PyFloat_FromDouble(sqrt(dot_vn_vn(self->vec, self->vec, self->size))); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static int Vector_length_set(VectorObject *self, PyObject *value) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   double dot = 0.0f, param; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   if ((param = PyFloat_AsDouble(value)) == -1.0 && PyErr_Occurred()) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, "length must be set to a number"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-28 17:08:33 +00:00
										 |  |  |   if (param < 0.0) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, "cannot set a vectors length to a negative value"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-03-28 17:08:33 +00:00
										 |  |  |   if (param == 0.0) { | 
					
						
							| 
									
										
										
										
											2015-05-05 17:08:29 +10:00
										 |  |  |     copy_vn_fl(self->vec, self->size, 0.0f); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return 0; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   dot = dot_vn_vn(self->vec, self->vec, self->size); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (!dot) { | 
					
						
							| 
									
										
										
										
											2021-06-22 10:42:32 -07:00
										 |  |  |     /* can't sqrt zero */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   dot = sqrt(dot); | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (dot == param) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   dot = dot / param; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   mul_vn_fl(self->vec, self->size, 1.0 / dot); | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 12:11:09 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(self); /* checked already */ | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-11 09:40:14 +00:00
										 |  |  | /* vector.length_squared */ | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  | PyDoc_STRVAR(Vector_length_squared_doc, "Vector length squared (v.dot(v)).\n\n:type: float"); | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static PyObject *Vector_length_squared_get(VectorObject *self, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2011-08-11 09:40:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2011-08-11 09:40:14 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-08-11 09:40:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-24 04:12:16 +00:00
										 |  |  |   return PyFloat_FromDouble(dot_vn_vn(self->vec, self->vec, self->size)); | 
					
						
							| 
									
										
										
										
											2011-08-11 09:40:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Python script used to make swizzle array: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \code{.py} | 
					
						
							|  |  |  |  * SWIZZLE_BITS_PER_AXIS = 3 | 
					
						
							|  |  |  |  * SWIZZLE_VALID_AXIS = 0x4 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * axis_dict = {} | 
					
						
							|  |  |  |  * axis_pos = {'x': 0, 'y': 1, 'z': 2, 'w': 3} | 
					
						
							| 
									
										
										
										
											2019-09-30 17:06:28 +10:00
										 |  |  |  * axis_chars = 'xyzw' | 
					
						
							|  |  |  |  * while len(axis_chars) >= 2: | 
					
						
							|  |  |  |  *     for axis_0 in axis_chars: | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  *         axis_0_pos = axis_pos[axis_0] | 
					
						
							| 
									
										
										
										
											2019-09-30 17:06:28 +10:00
										 |  |  |  *         for axis_1 in axis_chars: | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  *             axis_1_pos = axis_pos[axis_1] | 
					
						
							|  |  |  |  *             axis_dict[axis_0 + axis_1] = ( | 
					
						
							|  |  |  |  *                 '((%s | SWIZZLE_VALID_AXIS) | ' | 
					
						
							|  |  |  |  *                 '((%s | SWIZZLE_VALID_AXIS) << SWIZZLE_BITS_PER_AXIS))' % | 
					
						
							|  |  |  |  *                 (axis_0_pos, axis_1_pos)) | 
					
						
							| 
									
										
										
										
											2019-09-30 17:06:28 +10:00
										 |  |  |  *             if len(axis_chars) > 2: | 
					
						
							|  |  |  |  *                 for axis_2 in axis_chars: | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  *                     axis_2_pos = axis_pos[axis_2] | 
					
						
							|  |  |  |  *                     axis_dict[axis_0 + axis_1 + axis_2] = ( | 
					
						
							|  |  |  |  *                         '((%s | SWIZZLE_VALID_AXIS) | ' | 
					
						
							|  |  |  |  *                         '((%s | SWIZZLE_VALID_AXIS) << SWIZZLE_BITS_PER_AXIS) | ' | 
					
						
							|  |  |  |  *                         '((%s | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 2)))' % | 
					
						
							|  |  |  |  *                         (axis_0_pos, axis_1_pos, axis_2_pos)) | 
					
						
							| 
									
										
										
										
											2019-09-30 17:06:28 +10:00
										 |  |  |  *                     if len(axis_chars) > 3: | 
					
						
							|  |  |  |  *                         for axis_3 in axis_chars: | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  *                             axis_3_pos = axis_pos[axis_3] | 
					
						
							|  |  |  |  *                             axis_dict[axis_0 + axis_1 + axis_2 + axis_3] = ( | 
					
						
							|  |  |  |  *                                 '((%s | SWIZZLE_VALID_AXIS) | ' | 
					
						
							|  |  |  |  *                                 '((%s | SWIZZLE_VALID_AXIS) << SWIZZLE_BITS_PER_AXIS) | ' | 
					
						
							|  |  |  |  *                                 '((%s | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 2)) | ' | 
					
						
							| 
									
										
										
										
											2019-04-29 19:59:13 +10:00
										 |  |  |  *                                 '((%s | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 3)))  ' | 
					
						
							|  |  |  |  *                                 % | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  *                                 (axis_0_pos, axis_1_pos, axis_2_pos, axis_3_pos)) | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-09-30 17:06:28 +10:00
										 |  |  |  *     axis_chars = axis_chars[:-1] | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  * items = list(axis_dict.items()) | 
					
						
							| 
									
										
										
										
											2019-04-29 19:59:13 +10:00
										 |  |  |  * items.sort( | 
					
						
							|  |  |  |  *     key=lambda a: a[0].replace('x', '0').replace('y', '1').replace('z', '2').replace('w', '3') | 
					
						
							|  |  |  |  * ) | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  * | 
					
						
							|  |  |  |  * unique = set() | 
					
						
							|  |  |  |  * for key, val in items: | 
					
						
							|  |  |  |  *     num = eval(val) | 
					
						
							|  |  |  |  *     set_str = 'Vector_swizzle_set' if (len(set(key)) == len(key)) else 'NULL' | 
					
						
							|  |  |  |  *     key_args = ', '.join(["'%s'" % c for c in key.upper()]) | 
					
						
							| 
									
										
										
										
											2019-07-04 21:10:06 +10:00
										 |  |  |  *     print('\t{"%s", %s(getter)Vector_swizzle_get, (setter)%s, NULL, SWIZZLE%d(%s)},' % | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  *           (key, (' ' * (4 - len(key))), set_str, len(key), key_args)) | 
					
						
							|  |  |  |  *     unique.add(num) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * if len(unique) != len(items): | 
					
						
							|  |  |  |  *     print("ERROR, duplicate values found") | 
					
						
							|  |  |  |  * \endcode | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Get a new Vector according to the provided swizzle bits. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static PyObject *Vector_swizzle_get(VectorObject *self, void *closure) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |   size_t axis_to; | 
					
						
							|  |  |  |   size_t axis_from; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   float vec[MAX_DIMENSIONS]; | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  |   uint swizzleClosure; | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   /* Unpack the axes from the closure into an array. */ | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |   axis_to = 0; | 
					
						
							| 
									
										
										
										
											2018-09-19 12:05:58 +10:00
										 |  |  |   swizzleClosure = POINTER_AS_INT(closure); | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |   while (swizzleClosure & SWIZZLE_VALID_AXIS) { | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |     axis_from = swizzleClosure & SWIZZLE_AXIS; | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |     if (axis_from >= self->size) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |       PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                       "Vector swizzle: " | 
					
						
							|  |  |  |                       "specified axis not present"); | 
					
						
							| 
									
										
										
										
											2010-01-31 22:50:07 +00:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |     vec[axis_to] = self->vec[axis_from]; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     swizzleClosure = swizzleClosure >> SWIZZLE_BITS_PER_AXIS; | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |     axis_to++; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-02-09 09:20:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Vector_CreatePyObject(vec, axis_to, Py_TYPE(self)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2018-09-02 18:28:27 +10:00
										 |  |  |  * Set the items of this vector using a swizzle. | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |  * - If value is a vector or list this operates like an array copy, except that | 
					
						
							|  |  |  |  *   the destination is effectively re-ordered as defined by the swizzle. At | 
					
						
							|  |  |  |  *   most min(len(source), len(dest)) values will be copied. | 
					
						
							|  |  |  |  * - If the value is scalar, it is copied to all axes listed in the swizzle. | 
					
						
							|  |  |  |  * - If an axis appears more than once in the swizzle, the final occurrence is | 
					
						
							|  |  |  |  *   the one that determines its value. | 
					
						
							| 
									
										
										
										
											2012-03-03 20:36:09 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  * \return 0 on success and -1 on failure. On failure, the vector will be unchanged. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-12-24 04:58:01 +00:00
										 |  |  | static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |   size_t size_from; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   float scalarVal; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |   size_t axis_from; | 
					
						
							|  |  |  |   size_t axis_to; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  |   uint swizzleClosure; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |   float tvec[MAX_DIMENSIONS]; | 
					
						
							|  |  |  |   float vec_assign[MAX_DIMENSIONS]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback_ForWrite(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   /* Check that the closure can be used with this vector: even 2D vectors have
 | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |    * swizzles defined for axes z and w, but they would be invalid. */ | 
					
						
							| 
									
										
										
										
											2018-09-19 12:05:58 +10:00
										 |  |  |   swizzleClosure = POINTER_AS_INT(closure); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   axis_from = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |   while (swizzleClosure & SWIZZLE_VALID_AXIS) { | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |     axis_to = swizzleClosure & SWIZZLE_AXIS; | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |     if (axis_to >= self->size) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |       PyErr_SetString(PyExc_AttributeError, | 
					
						
							|  |  |  |                       "Vector swizzle: " | 
					
						
							|  |  |  |                       "specified axis not present"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |       return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     swizzleClosure = swizzleClosure >> SWIZZLE_BITS_PER_AXIS; | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |     axis_from++; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   if (((scalarVal = PyFloat_AsDouble(value)) == -1 && PyErr_Occurred()) == 0) { | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |     int i; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |     for (i = 0; i < MAX_DIMENSIONS; i++) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |       vec_assign[i] = scalarVal; | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     size_from = axis_from; | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-03-05 09:16:12 +11:00
										 |  |  |   else if (((void)PyErr_Clear()), /* run but ignore the result */ | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  |            (size_from = mathutils_array_parse( | 
					
						
							|  |  |  |                 vec_assign, 2, 4, value, "mathutils.Vector.**** = swizzle assignment")) == -1) { | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (axis_from != size_from) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_AttributeError, "Vector swizzle: size does not match swizzle"); | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |   /* Copy vector contents onto swizzled axes. */ | 
					
						
							|  |  |  |   axis_from = 0; | 
					
						
							| 
									
										
										
										
											2018-09-19 12:05:58 +10:00
										 |  |  |   swizzleClosure = POINTER_AS_INT(closure); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-11 18:58:34 +00:00
										 |  |  |   /* We must first copy current vec into tvec, else some org values may be lost.
 | 
					
						
							| 
									
										
										
										
											2020-09-30 20:09:02 +10:00
										 |  |  |    * See T31760. | 
					
						
							| 
									
										
										
										
											2012-06-11 18:58:34 +00:00
										 |  |  |    * Assuming self->size can't be higher than MAX_DIMENSIONS! */ | 
					
						
							|  |  |  |   memcpy(tvec, self->vec, self->size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |   while (swizzleClosure & SWIZZLE_VALID_AXIS) { | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |     axis_to = swizzleClosure & SWIZZLE_AXIS; | 
					
						
							|  |  |  |     tvec[axis_to] = vec_assign[axis_from]; | 
					
						
							|  |  |  |     swizzleClosure = swizzleClosure >> SWIZZLE_BITS_PER_AXIS; | 
					
						
							|  |  |  |     axis_from++; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-11 18:58:34 +00:00
										 |  |  |   /* We must copy back the whole tvec into vec, else some changes may be lost (e.g. xz...).
 | 
					
						
							| 
									
										
										
										
											2020-09-30 20:09:02 +10:00
										 |  |  |    * See T31760. */ | 
					
						
							| 
									
										
										
										
											2012-06-11 18:58:34 +00:00
										 |  |  |   memcpy(self->vec, tvec, self->size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2010-04-25 19:27:59 +00:00
										 |  |  |   /* continue with BaseMathObject_WriteCallback at the end */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_WriteCallback(self) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 09:58:19 +10:00
										 |  |  | #define _SWIZZLE1(a) ((a) | SWIZZLE_VALID_AXIS)
 | 
					
						
							|  |  |  | #define _SWIZZLE2(a, b) (_SWIZZLE1(a) | (((b) | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS)))
 | 
					
						
							|  |  |  | #define _SWIZZLE3(a, b, c) \
 | 
					
						
							|  |  |  |   (_SWIZZLE2(a, b) | (((c) | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 2))) | 
					
						
							|  |  |  | #define _SWIZZLE4(a, b, c, d) \
 | 
					
						
							|  |  |  |   (_SWIZZLE3(a, b, c) | (((d) | SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 3))) | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 12:05:58 +10:00
										 |  |  | #define SWIZZLE2(a, b) POINTER_FROM_INT(_SWIZZLE2(a, b))
 | 
					
						
							|  |  |  | #define SWIZZLE3(a, b, c) POINTER_FROM_INT(_SWIZZLE3(a, b, c))
 | 
					
						
							|  |  |  | #define SWIZZLE4(a, b, c, d) POINTER_FROM_INT(_SWIZZLE4(a, b, c, d))
 | 
					
						
							| 
									
										
										
										
											2016-07-31 20:41:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python attributes get/set structure:                                      */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyGetSetDef Vector_getseters[] = { | 
					
						
							| 
									
										
										
										
											2019-07-04 21:10:06 +10:00
										 |  |  |     {"x", (getter)Vector_axis_get, (setter)Vector_axis_set, Vector_axis_x_doc, (void *)0}, | 
					
						
							|  |  |  |     {"y", (getter)Vector_axis_get, (setter)Vector_axis_set, Vector_axis_y_doc, (void *)1}, | 
					
						
							|  |  |  |     {"z", (getter)Vector_axis_get, (setter)Vector_axis_set, Vector_axis_z_doc, (void *)2}, | 
					
						
							|  |  |  |     {"w", (getter)Vector_axis_get, (setter)Vector_axis_set, Vector_axis_w_doc, (void *)3}, | 
					
						
							|  |  |  |     {"length", (getter)Vector_length_get, (setter)Vector_length_set, Vector_length_doc, NULL}, | 
					
						
							|  |  |  |     {"length_squared", | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |      (getter)Vector_length_squared_get, | 
					
						
							|  |  |  |      (setter)NULL, | 
					
						
							|  |  |  |      Vector_length_squared_doc, | 
					
						
							|  |  |  |      NULL}, | 
					
						
							| 
									
										
										
										
											2019-07-04 21:10:06 +10:00
										 |  |  |     {"magnitude", (getter)Vector_length_get, (setter)Vector_length_set, Vector_length_doc, NULL}, | 
					
						
							|  |  |  |     {"is_wrapped", | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |      (getter)BaseMathObject_is_wrapped_get, | 
					
						
							|  |  |  |      (setter)NULL, | 
					
						
							|  |  |  |      BaseMathObject_is_wrapped_doc, | 
					
						
							| 
									
										
										
										
											2015-02-15 14:10:46 +11:00
										 |  |  |      NULL}, | 
					
						
							| 
									
										
										
										
											2019-07-04 21:10:06 +10:00
										 |  |  |     {"is_frozen", | 
					
						
							| 
									
										
										
										
											2015-02-15 14:10:46 +11:00
										 |  |  |      (getter)BaseMathObject_is_frozen_get, | 
					
						
							|  |  |  |      (setter)NULL, | 
					
						
							|  |  |  |      BaseMathObject_is_frozen_doc, | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |      NULL}, | 
					
						
							| 
									
										
										
										
											2019-07-04 21:10:06 +10:00
										 |  |  |     {"owner", (getter)BaseMathObject_owner_get, (setter)NULL, BaseMathObject_owner_doc, NULL}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 12:47:46 +10:00
										 |  |  |     /* Auto-generated swizzle attributes, see Python script above. */ | 
					
						
							| 
									
										
										
										
											2019-07-04 21:10:06 +10:00
										 |  |  |     {"xx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE2(0, 0)}, | 
					
						
							|  |  |  |     {"xxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(0, 0, 0)}, | 
					
						
							|  |  |  |     {"xxxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 0, 0)}, | 
					
						
							|  |  |  |     {"xxxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 0, 1)}, | 
					
						
							|  |  |  |     {"xxxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 0, 2)}, | 
					
						
							|  |  |  |     {"xxxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 0, 3)}, | 
					
						
							|  |  |  |     {"xxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(0, 0, 1)}, | 
					
						
							|  |  |  |     {"xxyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 1, 0)}, | 
					
						
							|  |  |  |     {"xxyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 1, 1)}, | 
					
						
							|  |  |  |     {"xxyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 1, 2)}, | 
					
						
							|  |  |  |     {"xxyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 1, 3)}, | 
					
						
							|  |  |  |     {"xxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(0, 0, 2)}, | 
					
						
							|  |  |  |     {"xxzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 2, 0)}, | 
					
						
							|  |  |  |     {"xxzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 2, 1)}, | 
					
						
							|  |  |  |     {"xxzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 2, 2)}, | 
					
						
							|  |  |  |     {"xxzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 2, 3)}, | 
					
						
							|  |  |  |     {"xxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(0, 0, 3)}, | 
					
						
							|  |  |  |     {"xxwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 3, 0)}, | 
					
						
							|  |  |  |     {"xxwy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 3, 1)}, | 
					
						
							|  |  |  |     {"xxwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 3, 2)}, | 
					
						
							|  |  |  |     {"xxww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 0, 3, 3)}, | 
					
						
							|  |  |  |     {"xy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE2(0, 1)}, | 
					
						
							|  |  |  |     {"xyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(0, 1, 0)}, | 
					
						
							|  |  |  |     {"xyxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 0, 0)}, | 
					
						
							|  |  |  |     {"xyxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 0, 1)}, | 
					
						
							|  |  |  |     {"xyxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 0, 2)}, | 
					
						
							|  |  |  |     {"xyxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 0, 3)}, | 
					
						
							|  |  |  |     {"xyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(0, 1, 1)}, | 
					
						
							|  |  |  |     {"xyyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 1, 0)}, | 
					
						
							|  |  |  |     {"xyyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 1, 1)}, | 
					
						
							|  |  |  |     {"xyyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 1, 2)}, | 
					
						
							|  |  |  |     {"xyyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 1, 3)}, | 
					
						
							|  |  |  |     {"xyz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(0, 1, 2)}, | 
					
						
							|  |  |  |     {"xyzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 2, 0)}, | 
					
						
							|  |  |  |     {"xyzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 2, 1)}, | 
					
						
							|  |  |  |     {"xyzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 2, 2)}, | 
					
						
							|  |  |  |     {"xyzw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(0, 1, 2, 3)}, | 
					
						
							|  |  |  |     {"xyw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(0, 1, 3)}, | 
					
						
							|  |  |  |     {"xywx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 3, 0)}, | 
					
						
							|  |  |  |     {"xywy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 3, 1)}, | 
					
						
							|  |  |  |     {"xywz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(0, 1, 3, 2)}, | 
					
						
							|  |  |  |     {"xyww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 1, 3, 3)}, | 
					
						
							|  |  |  |     {"xz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE2(0, 2)}, | 
					
						
							|  |  |  |     {"xzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(0, 2, 0)}, | 
					
						
							|  |  |  |     {"xzxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 0, 0)}, | 
					
						
							|  |  |  |     {"xzxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 0, 1)}, | 
					
						
							|  |  |  |     {"xzxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 0, 2)}, | 
					
						
							|  |  |  |     {"xzxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 0, 3)}, | 
					
						
							|  |  |  |     {"xzy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(0, 2, 1)}, | 
					
						
							|  |  |  |     {"xzyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 1, 0)}, | 
					
						
							|  |  |  |     {"xzyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 1, 1)}, | 
					
						
							|  |  |  |     {"xzyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 1, 2)}, | 
					
						
							|  |  |  |     {"xzyw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(0, 2, 1, 3)}, | 
					
						
							|  |  |  |     {"xzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(0, 2, 2)}, | 
					
						
							|  |  |  |     {"xzzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 2, 0)}, | 
					
						
							|  |  |  |     {"xzzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 2, 1)}, | 
					
						
							|  |  |  |     {"xzzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 2, 2)}, | 
					
						
							|  |  |  |     {"xzzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 2, 3)}, | 
					
						
							|  |  |  |     {"xzw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(0, 2, 3)}, | 
					
						
							|  |  |  |     {"xzwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 3, 0)}, | 
					
						
							|  |  |  |     {"xzwy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(0, 2, 3, 1)}, | 
					
						
							|  |  |  |     {"xzwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 3, 2)}, | 
					
						
							|  |  |  |     {"xzww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 2, 3, 3)}, | 
					
						
							|  |  |  |     {"xw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE2(0, 3)}, | 
					
						
							|  |  |  |     {"xwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(0, 3, 0)}, | 
					
						
							|  |  |  |     {"xwxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 0, 0)}, | 
					
						
							|  |  |  |     {"xwxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 0, 1)}, | 
					
						
							|  |  |  |     {"xwxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 0, 2)}, | 
					
						
							|  |  |  |     {"xwxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 0, 3)}, | 
					
						
							|  |  |  |     {"xwy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(0, 3, 1)}, | 
					
						
							|  |  |  |     {"xwyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 1, 0)}, | 
					
						
							|  |  |  |     {"xwyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 1, 1)}, | 
					
						
							|  |  |  |     {"xwyz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(0, 3, 1, 2)}, | 
					
						
							|  |  |  |     {"xwyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 1, 3)}, | 
					
						
							|  |  |  |     {"xwz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(0, 3, 2)}, | 
					
						
							|  |  |  |     {"xwzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 2, 0)}, | 
					
						
							|  |  |  |     {"xwzy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(0, 3, 2, 1)}, | 
					
						
							|  |  |  |     {"xwzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 2, 2)}, | 
					
						
							|  |  |  |     {"xwzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 2, 3)}, | 
					
						
							|  |  |  |     {"xww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(0, 3, 3)}, | 
					
						
							|  |  |  |     {"xwwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 3, 0)}, | 
					
						
							|  |  |  |     {"xwwy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 3, 1)}, | 
					
						
							|  |  |  |     {"xwwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 3, 2)}, | 
					
						
							|  |  |  |     {"xwww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(0, 3, 3, 3)}, | 
					
						
							|  |  |  |     {"yx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE2(1, 0)}, | 
					
						
							|  |  |  |     {"yxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(1, 0, 0)}, | 
					
						
							|  |  |  |     {"yxxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 0, 0)}, | 
					
						
							|  |  |  |     {"yxxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 0, 1)}, | 
					
						
							|  |  |  |     {"yxxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 0, 2)}, | 
					
						
							|  |  |  |     {"yxxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 0, 3)}, | 
					
						
							|  |  |  |     {"yxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(1, 0, 1)}, | 
					
						
							|  |  |  |     {"yxyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 1, 0)}, | 
					
						
							|  |  |  |     {"yxyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 1, 1)}, | 
					
						
							|  |  |  |     {"yxyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 1, 2)}, | 
					
						
							|  |  |  |     {"yxyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 1, 3)}, | 
					
						
							|  |  |  |     {"yxz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(1, 0, 2)}, | 
					
						
							|  |  |  |     {"yxzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 2, 0)}, | 
					
						
							|  |  |  |     {"yxzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 2, 1)}, | 
					
						
							|  |  |  |     {"yxzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 2, 2)}, | 
					
						
							|  |  |  |     {"yxzw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(1, 0, 2, 3)}, | 
					
						
							|  |  |  |     {"yxw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(1, 0, 3)}, | 
					
						
							|  |  |  |     {"yxwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 3, 0)}, | 
					
						
							|  |  |  |     {"yxwy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 3, 1)}, | 
					
						
							|  |  |  |     {"yxwz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(1, 0, 3, 2)}, | 
					
						
							|  |  |  |     {"yxww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 0, 3, 3)}, | 
					
						
							|  |  |  |     {"yy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE2(1, 1)}, | 
					
						
							|  |  |  |     {"yyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(1, 1, 0)}, | 
					
						
							|  |  |  |     {"yyxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 0, 0)}, | 
					
						
							|  |  |  |     {"yyxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 0, 1)}, | 
					
						
							|  |  |  |     {"yyxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 0, 2)}, | 
					
						
							|  |  |  |     {"yyxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 0, 3)}, | 
					
						
							|  |  |  |     {"yyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(1, 1, 1)}, | 
					
						
							|  |  |  |     {"yyyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 1, 0)}, | 
					
						
							|  |  |  |     {"yyyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 1, 1)}, | 
					
						
							|  |  |  |     {"yyyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 1, 2)}, | 
					
						
							|  |  |  |     {"yyyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 1, 3)}, | 
					
						
							|  |  |  |     {"yyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(1, 1, 2)}, | 
					
						
							|  |  |  |     {"yyzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 2, 0)}, | 
					
						
							|  |  |  |     {"yyzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 2, 1)}, | 
					
						
							|  |  |  |     {"yyzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 2, 2)}, | 
					
						
							|  |  |  |     {"yyzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 2, 3)}, | 
					
						
							|  |  |  |     {"yyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(1, 1, 3)}, | 
					
						
							|  |  |  |     {"yywx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 3, 0)}, | 
					
						
							|  |  |  |     {"yywy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 3, 1)}, | 
					
						
							|  |  |  |     {"yywz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 3, 2)}, | 
					
						
							|  |  |  |     {"yyww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 1, 3, 3)}, | 
					
						
							|  |  |  |     {"yz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE2(1, 2)}, | 
					
						
							|  |  |  |     {"yzx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(1, 2, 0)}, | 
					
						
							|  |  |  |     {"yzxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 0, 0)}, | 
					
						
							|  |  |  |     {"yzxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 0, 1)}, | 
					
						
							|  |  |  |     {"yzxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 0, 2)}, | 
					
						
							|  |  |  |     {"yzxw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(1, 2, 0, 3)}, | 
					
						
							|  |  |  |     {"yzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(1, 2, 1)}, | 
					
						
							|  |  |  |     {"yzyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 1, 0)}, | 
					
						
							|  |  |  |     {"yzyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 1, 1)}, | 
					
						
							|  |  |  |     {"yzyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 1, 2)}, | 
					
						
							|  |  |  |     {"yzyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 1, 3)}, | 
					
						
							|  |  |  |     {"yzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(1, 2, 2)}, | 
					
						
							|  |  |  |     {"yzzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 2, 0)}, | 
					
						
							|  |  |  |     {"yzzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 2, 1)}, | 
					
						
							|  |  |  |     {"yzzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 2, 2)}, | 
					
						
							|  |  |  |     {"yzzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 2, 3)}, | 
					
						
							|  |  |  |     {"yzw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(1, 2, 3)}, | 
					
						
							|  |  |  |     {"yzwx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(1, 2, 3, 0)}, | 
					
						
							|  |  |  |     {"yzwy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 3, 1)}, | 
					
						
							|  |  |  |     {"yzwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 3, 2)}, | 
					
						
							|  |  |  |     {"yzww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 2, 3, 3)}, | 
					
						
							|  |  |  |     {"yw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE2(1, 3)}, | 
					
						
							|  |  |  |     {"ywx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(1, 3, 0)}, | 
					
						
							|  |  |  |     {"ywxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 0, 0)}, | 
					
						
							|  |  |  |     {"ywxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 0, 1)}, | 
					
						
							|  |  |  |     {"ywxz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(1, 3, 0, 2)}, | 
					
						
							|  |  |  |     {"ywxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 0, 3)}, | 
					
						
							|  |  |  |     {"ywy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(1, 3, 1)}, | 
					
						
							|  |  |  |     {"ywyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 1, 0)}, | 
					
						
							|  |  |  |     {"ywyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 1, 1)}, | 
					
						
							|  |  |  |     {"ywyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 1, 2)}, | 
					
						
							|  |  |  |     {"ywyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 1, 3)}, | 
					
						
							|  |  |  |     {"ywz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(1, 3, 2)}, | 
					
						
							|  |  |  |     {"ywzx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(1, 3, 2, 0)}, | 
					
						
							|  |  |  |     {"ywzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 2, 1)}, | 
					
						
							|  |  |  |     {"ywzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 2, 2)}, | 
					
						
							|  |  |  |     {"ywzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 2, 3)}, | 
					
						
							|  |  |  |     {"yww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(1, 3, 3)}, | 
					
						
							|  |  |  |     {"ywwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 3, 0)}, | 
					
						
							|  |  |  |     {"ywwy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 3, 1)}, | 
					
						
							|  |  |  |     {"ywwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 3, 2)}, | 
					
						
							|  |  |  |     {"ywww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(1, 3, 3, 3)}, | 
					
						
							|  |  |  |     {"zx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE2(2, 0)}, | 
					
						
							|  |  |  |     {"zxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(2, 0, 0)}, | 
					
						
							|  |  |  |     {"zxxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 0, 0)}, | 
					
						
							|  |  |  |     {"zxxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 0, 1)}, | 
					
						
							|  |  |  |     {"zxxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 0, 2)}, | 
					
						
							|  |  |  |     {"zxxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 0, 3)}, | 
					
						
							|  |  |  |     {"zxy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(2, 0, 1)}, | 
					
						
							|  |  |  |     {"zxyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 1, 0)}, | 
					
						
							|  |  |  |     {"zxyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 1, 1)}, | 
					
						
							|  |  |  |     {"zxyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 1, 2)}, | 
					
						
							|  |  |  |     {"zxyw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(2, 0, 1, 3)}, | 
					
						
							|  |  |  |     {"zxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(2, 0, 2)}, | 
					
						
							|  |  |  |     {"zxzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 2, 0)}, | 
					
						
							|  |  |  |     {"zxzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 2, 1)}, | 
					
						
							|  |  |  |     {"zxzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 2, 2)}, | 
					
						
							|  |  |  |     {"zxzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 2, 3)}, | 
					
						
							|  |  |  |     {"zxw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(2, 0, 3)}, | 
					
						
							|  |  |  |     {"zxwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 3, 0)}, | 
					
						
							|  |  |  |     {"zxwy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(2, 0, 3, 1)}, | 
					
						
							|  |  |  |     {"zxwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 3, 2)}, | 
					
						
							|  |  |  |     {"zxww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 0, 3, 3)}, | 
					
						
							|  |  |  |     {"zy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE2(2, 1)}, | 
					
						
							|  |  |  |     {"zyx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(2, 1, 0)}, | 
					
						
							|  |  |  |     {"zyxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 0, 0)}, | 
					
						
							|  |  |  |     {"zyxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 0, 1)}, | 
					
						
							|  |  |  |     {"zyxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 0, 2)}, | 
					
						
							|  |  |  |     {"zyxw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(2, 1, 0, 3)}, | 
					
						
							|  |  |  |     {"zyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(2, 1, 1)}, | 
					
						
							|  |  |  |     {"zyyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 1, 0)}, | 
					
						
							|  |  |  |     {"zyyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 1, 1)}, | 
					
						
							|  |  |  |     {"zyyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 1, 2)}, | 
					
						
							|  |  |  |     {"zyyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 1, 3)}, | 
					
						
							|  |  |  |     {"zyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(2, 1, 2)}, | 
					
						
							|  |  |  |     {"zyzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 2, 0)}, | 
					
						
							|  |  |  |     {"zyzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 2, 1)}, | 
					
						
							|  |  |  |     {"zyzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 2, 2)}, | 
					
						
							|  |  |  |     {"zyzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 2, 3)}, | 
					
						
							|  |  |  |     {"zyw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(2, 1, 3)}, | 
					
						
							|  |  |  |     {"zywx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(2, 1, 3, 0)}, | 
					
						
							|  |  |  |     {"zywy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 3, 1)}, | 
					
						
							|  |  |  |     {"zywz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 3, 2)}, | 
					
						
							|  |  |  |     {"zyww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 1, 3, 3)}, | 
					
						
							|  |  |  |     {"zz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE2(2, 2)}, | 
					
						
							|  |  |  |     {"zzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(2, 2, 0)}, | 
					
						
							|  |  |  |     {"zzxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 0, 0)}, | 
					
						
							|  |  |  |     {"zzxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 0, 1)}, | 
					
						
							|  |  |  |     {"zzxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 0, 2)}, | 
					
						
							|  |  |  |     {"zzxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 0, 3)}, | 
					
						
							|  |  |  |     {"zzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(2, 2, 1)}, | 
					
						
							|  |  |  |     {"zzyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 1, 0)}, | 
					
						
							|  |  |  |     {"zzyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 1, 1)}, | 
					
						
							|  |  |  |     {"zzyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 1, 2)}, | 
					
						
							|  |  |  |     {"zzyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 1, 3)}, | 
					
						
							|  |  |  |     {"zzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(2, 2, 2)}, | 
					
						
							|  |  |  |     {"zzzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 2, 0)}, | 
					
						
							|  |  |  |     {"zzzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 2, 1)}, | 
					
						
							|  |  |  |     {"zzzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 2, 2)}, | 
					
						
							|  |  |  |     {"zzzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 2, 3)}, | 
					
						
							|  |  |  |     {"zzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(2, 2, 3)}, | 
					
						
							|  |  |  |     {"zzwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 3, 0)}, | 
					
						
							|  |  |  |     {"zzwy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 3, 1)}, | 
					
						
							|  |  |  |     {"zzwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 3, 2)}, | 
					
						
							|  |  |  |     {"zzww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 2, 3, 3)}, | 
					
						
							|  |  |  |     {"zw", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE2(2, 3)}, | 
					
						
							|  |  |  |     {"zwx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(2, 3, 0)}, | 
					
						
							|  |  |  |     {"zwxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 0, 0)}, | 
					
						
							|  |  |  |     {"zwxy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(2, 3, 0, 1)}, | 
					
						
							|  |  |  |     {"zwxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 0, 2)}, | 
					
						
							|  |  |  |     {"zwxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 0, 3)}, | 
					
						
							|  |  |  |     {"zwy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(2, 3, 1)}, | 
					
						
							|  |  |  |     {"zwyx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(2, 3, 1, 0)}, | 
					
						
							|  |  |  |     {"zwyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 1, 1)}, | 
					
						
							|  |  |  |     {"zwyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 1, 2)}, | 
					
						
							|  |  |  |     {"zwyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 1, 3)}, | 
					
						
							|  |  |  |     {"zwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(2, 3, 2)}, | 
					
						
							|  |  |  |     {"zwzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 2, 0)}, | 
					
						
							|  |  |  |     {"zwzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 2, 1)}, | 
					
						
							|  |  |  |     {"zwzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 2, 2)}, | 
					
						
							|  |  |  |     {"zwzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 2, 3)}, | 
					
						
							|  |  |  |     {"zww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(2, 3, 3)}, | 
					
						
							|  |  |  |     {"zwwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 3, 0)}, | 
					
						
							|  |  |  |     {"zwwy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 3, 1)}, | 
					
						
							|  |  |  |     {"zwwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 3, 2)}, | 
					
						
							|  |  |  |     {"zwww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(2, 3, 3, 3)}, | 
					
						
							|  |  |  |     {"wx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE2(3, 0)}, | 
					
						
							|  |  |  |     {"wxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(3, 0, 0)}, | 
					
						
							|  |  |  |     {"wxxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 0, 0)}, | 
					
						
							|  |  |  |     {"wxxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 0, 1)}, | 
					
						
							|  |  |  |     {"wxxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 0, 2)}, | 
					
						
							|  |  |  |     {"wxxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 0, 3)}, | 
					
						
							|  |  |  |     {"wxy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(3, 0, 1)}, | 
					
						
							|  |  |  |     {"wxyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 1, 0)}, | 
					
						
							|  |  |  |     {"wxyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 1, 1)}, | 
					
						
							|  |  |  |     {"wxyz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(3, 0, 1, 2)}, | 
					
						
							|  |  |  |     {"wxyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 1, 3)}, | 
					
						
							|  |  |  |     {"wxz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(3, 0, 2)}, | 
					
						
							|  |  |  |     {"wxzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 2, 0)}, | 
					
						
							|  |  |  |     {"wxzy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(3, 0, 2, 1)}, | 
					
						
							|  |  |  |     {"wxzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 2, 2)}, | 
					
						
							|  |  |  |     {"wxzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 2, 3)}, | 
					
						
							|  |  |  |     {"wxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(3, 0, 3)}, | 
					
						
							|  |  |  |     {"wxwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 3, 0)}, | 
					
						
							|  |  |  |     {"wxwy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 3, 1)}, | 
					
						
							|  |  |  |     {"wxwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 3, 2)}, | 
					
						
							|  |  |  |     {"wxww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 0, 3, 3)}, | 
					
						
							|  |  |  |     {"wy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE2(3, 1)}, | 
					
						
							|  |  |  |     {"wyx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(3, 1, 0)}, | 
					
						
							|  |  |  |     {"wyxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 0, 0)}, | 
					
						
							|  |  |  |     {"wyxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 0, 1)}, | 
					
						
							|  |  |  |     {"wyxz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(3, 1, 0, 2)}, | 
					
						
							|  |  |  |     {"wyxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 0, 3)}, | 
					
						
							|  |  |  |     {"wyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(3, 1, 1)}, | 
					
						
							|  |  |  |     {"wyyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 1, 0)}, | 
					
						
							|  |  |  |     {"wyyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 1, 1)}, | 
					
						
							|  |  |  |     {"wyyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 1, 2)}, | 
					
						
							|  |  |  |     {"wyyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 1, 3)}, | 
					
						
							|  |  |  |     {"wyz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(3, 1, 2)}, | 
					
						
							|  |  |  |     {"wyzx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(3, 1, 2, 0)}, | 
					
						
							|  |  |  |     {"wyzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 2, 1)}, | 
					
						
							|  |  |  |     {"wyzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 2, 2)}, | 
					
						
							|  |  |  |     {"wyzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 2, 3)}, | 
					
						
							|  |  |  |     {"wyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(3, 1, 3)}, | 
					
						
							|  |  |  |     {"wywx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 3, 0)}, | 
					
						
							|  |  |  |     {"wywy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 3, 1)}, | 
					
						
							|  |  |  |     {"wywz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 3, 2)}, | 
					
						
							|  |  |  |     {"wyww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 1, 3, 3)}, | 
					
						
							|  |  |  |     {"wz", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE2(3, 2)}, | 
					
						
							|  |  |  |     {"wzx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(3, 2, 0)}, | 
					
						
							|  |  |  |     {"wzxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 0, 0)}, | 
					
						
							|  |  |  |     {"wzxy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(3, 2, 0, 1)}, | 
					
						
							|  |  |  |     {"wzxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 0, 2)}, | 
					
						
							|  |  |  |     {"wzxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 0, 3)}, | 
					
						
							|  |  |  |     {"wzy", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE3(3, 2, 1)}, | 
					
						
							|  |  |  |     {"wzyx", (getter)Vector_swizzle_get, (setter)Vector_swizzle_set, NULL, SWIZZLE4(3, 2, 1, 0)}, | 
					
						
							|  |  |  |     {"wzyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 1, 1)}, | 
					
						
							|  |  |  |     {"wzyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 1, 2)}, | 
					
						
							|  |  |  |     {"wzyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 1, 3)}, | 
					
						
							|  |  |  |     {"wzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(3, 2, 2)}, | 
					
						
							|  |  |  |     {"wzzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 2, 0)}, | 
					
						
							|  |  |  |     {"wzzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 2, 1)}, | 
					
						
							|  |  |  |     {"wzzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 2, 2)}, | 
					
						
							|  |  |  |     {"wzzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 2, 3)}, | 
					
						
							|  |  |  |     {"wzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(3, 2, 3)}, | 
					
						
							|  |  |  |     {"wzwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 3, 0)}, | 
					
						
							|  |  |  |     {"wzwy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 3, 1)}, | 
					
						
							|  |  |  |     {"wzwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 3, 2)}, | 
					
						
							|  |  |  |     {"wzww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 2, 3, 3)}, | 
					
						
							|  |  |  |     {"ww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE2(3, 3)}, | 
					
						
							|  |  |  |     {"wwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(3, 3, 0)}, | 
					
						
							|  |  |  |     {"wwxx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 0, 0)}, | 
					
						
							|  |  |  |     {"wwxy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 0, 1)}, | 
					
						
							|  |  |  |     {"wwxz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 0, 2)}, | 
					
						
							|  |  |  |     {"wwxw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 0, 3)}, | 
					
						
							|  |  |  |     {"wwy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(3, 3, 1)}, | 
					
						
							|  |  |  |     {"wwyx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 1, 0)}, | 
					
						
							|  |  |  |     {"wwyy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 1, 1)}, | 
					
						
							|  |  |  |     {"wwyz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 1, 2)}, | 
					
						
							|  |  |  |     {"wwyw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 1, 3)}, | 
					
						
							|  |  |  |     {"wwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(3, 3, 2)}, | 
					
						
							|  |  |  |     {"wwzx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 2, 0)}, | 
					
						
							|  |  |  |     {"wwzy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 2, 1)}, | 
					
						
							|  |  |  |     {"wwzz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 2, 2)}, | 
					
						
							|  |  |  |     {"wwzw", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 2, 3)}, | 
					
						
							|  |  |  |     {"www", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE3(3, 3, 3)}, | 
					
						
							|  |  |  |     {"wwwx", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 3, 0)}, | 
					
						
							|  |  |  |     {"wwwy", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 3, 1)}, | 
					
						
							|  |  |  |     {"wwwz", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 3, 2)}, | 
					
						
							|  |  |  |     {"wwww", (getter)Vector_swizzle_get, (setter)NULL, NULL, SWIZZLE4(3, 3, 3, 3)}, | 
					
						
							| 
									
										
										
										
											2016-07-31 20:41:24 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | #undef AXIS_FROM_CHAR
 | 
					
						
							| 
									
										
										
										
											2017-09-09 09:58:19 +10:00
										 |  |  | #undef SWIZZLE1
 | 
					
						
							|  |  |  | #undef SWIZZLE2
 | 
					
						
							|  |  |  | #undef SWIZZLE3
 | 
					
						
							|  |  |  | #undef SWIZZLE4
 | 
					
						
							|  |  |  | #undef _SWIZZLE1
 | 
					
						
							|  |  |  | #undef _SWIZZLE2
 | 
					
						
							|  |  |  | #undef _SWIZZLE3
 | 
					
						
							|  |  |  | #undef _SWIZZLE4
 | 
					
						
							| 
									
										
										
										
											2016-07-31 20:41:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |     {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-31 20:41:24 +10:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  * Row vector multiplication - (Vector * Matrix) | 
					
						
							|  |  |  |  * <pre> | 
					
						
							| 
									
										
										
										
											2011-12-21 11:36:28 +00:00
										 |  |  |  * [x][y][z] * [1][4][7] | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |  *             [2][5][8] | 
					
						
							|  |  |  |  *             [3][6][9] | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  * </pre> | 
					
						
							|  |  |  |  * \note vector/matrix multiplication is not commutative. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-12-26 00:42:35 +00:00
										 |  |  | static int row_vector_multiplication(float r_vec[MAX_DIMENSIONS], | 
					
						
							|  |  |  |                                      VectorObject *vec, | 
					
						
							|  |  |  |                                      MatrixObject *mat) | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-19 14:29:21 +00:00
										 |  |  |   float vec_cpy[MAX_DIMENSIONS]; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   int row, col, z = 0, vec_size = vec->size; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-20 04:11:23 +00:00
										 |  |  |   if (mat->num_row != vec_size) { | 
					
						
							| 
									
										
										
										
											2011-12-21 21:21:27 +00:00
										 |  |  |     if (mat->num_row == 4 && vec_size == 3) { | 
					
						
							|  |  |  |       vec_cpy[3] = 1.0f; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2011-07-14 09:54:03 +00:00
										 |  |  |       PyErr_SetString(PyExc_ValueError, | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |                       "vector * matrix: matrix column size " | 
					
						
							|  |  |  |                       "and the vector size must be the same"); | 
					
						
							| 
									
										
										
										
											2010-08-23 22:10:13 +00:00
										 |  |  |       return -1; | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(vec) == -1 || BaseMath_ReadCallback(mat) == -1) { | 
					
						
							| 
									
										
										
										
											2010-08-23 22:10:13 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-23 08:37:34 +00:00
										 |  |  |   memcpy(vec_cpy, vec->vec, vec_size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-26 00:42:35 +00:00
										 |  |  |   r_vec[3] = 1.0f; | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |   /* muliplication */ | 
					
						
							| 
									
										
										
										
											2011-12-21 11:36:28 +00:00
										 |  |  |   for (col = 0; col < mat->num_col; col++) { | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |     double dot = 0.0; | 
					
						
							| 
									
										
										
										
											2011-12-21 11:36:28 +00:00
										 |  |  |     for (row = 0; row < mat->num_row; row++) { | 
					
						
							| 
									
										
										
										
											2012-11-04 07:18:29 +00:00
										 |  |  |       dot += (double)(MATRIX_ITEM(mat, row, col) * vec_cpy[row]); | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-12-26 00:42:35 +00:00
										 |  |  |     r_vec[z++] = (float)dot; | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-08-23 22:10:13 +00:00
										 |  |  |   return 0; | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*----------------------------Vector.negate() -------------------- */ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(Vector_negate_doc, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |              ".. method:: negate()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Set all values to their negative.\n"); | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  | static PyObject *Vector_negate(VectorObject *self) | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   if (BaseMath_ReadCallback(self) == -1) { | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-03-30 06:12:48 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-03-03 06:01:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |   negate_vn(self->vec, self->size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |   (void)BaseMath_WriteCallback(self); /* already checked for error */ | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct PyMethodDef Vector_methods[] = { | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     /* Class Methods */ | 
					
						
							|  |  |  |     {"Fill", (PyCFunction)C_Vector_Fill, METH_VARARGS | METH_CLASS, C_Vector_Fill_doc}, | 
					
						
							|  |  |  |     {"Range", (PyCFunction)C_Vector_Range, METH_VARARGS | METH_CLASS, C_Vector_Range_doc}, | 
					
						
							|  |  |  |     {"Linspace", (PyCFunction)C_Vector_Linspace, METH_VARARGS | METH_CLASS, C_Vector_Linspace_doc}, | 
					
						
							|  |  |  |     {"Repeat", (PyCFunction)C_Vector_Repeat, METH_VARARGS | METH_CLASS, C_Vector_Repeat_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     /* In place only. */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |     {"zero", (PyCFunction)Vector_zero, METH_NOARGS, Vector_zero_doc}, | 
					
						
							|  |  |  |     {"negate", (PyCFunction)Vector_negate, METH_NOARGS, Vector_negate_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     /* Operate on original or copy. */ | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |     {"normalize", (PyCFunction)Vector_normalize, METH_NOARGS, Vector_normalize_doc}, | 
					
						
							|  |  |  |     {"normalized", (PyCFunction)Vector_normalized, METH_NOARGS, Vector_normalized_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |     {"resize", (PyCFunction)Vector_resize, METH_O, Vector_resize_doc}, | 
					
						
							|  |  |  |     {"resized", (PyCFunction)Vector_resized, METH_O, Vector_resized_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 06:14:50 +00:00
										 |  |  |     {"to_2d", (PyCFunction)Vector_to_2d, METH_NOARGS, Vector_to_2d_doc}, | 
					
						
							|  |  |  |     {"resize_2d", (PyCFunction)Vector_resize_2d, METH_NOARGS, Vector_resize_2d_doc}, | 
					
						
							|  |  |  |     {"to_3d", (PyCFunction)Vector_to_3d, METH_NOARGS, Vector_to_3d_doc}, | 
					
						
							|  |  |  |     {"resize_3d", (PyCFunction)Vector_resize_3d, METH_NOARGS, Vector_resize_3d_doc}, | 
					
						
							|  |  |  |     {"to_4d", (PyCFunction)Vector_to_4d, METH_NOARGS, Vector_to_4d_doc}, | 
					
						
							|  |  |  |     {"resize_4d", (PyCFunction)Vector_resize_4d, METH_NOARGS, Vector_resize_4d_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |     {"to_tuple", (PyCFunction)Vector_to_tuple, METH_VARARGS, Vector_to_tuple_doc}, | 
					
						
							|  |  |  |     {"to_track_quat", (PyCFunction)Vector_to_track_quat, METH_VARARGS, Vector_to_track_quat_doc}, | 
					
						
							| 
									
										
										
										
											2014-03-18 00:37:43 +11:00
										 |  |  |     {"orthogonal", (PyCFunction)Vector_orthogonal, METH_NOARGS, Vector_orthogonal_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     /* Operation between 2 or more types. */ | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |     {"reflect", (PyCFunction)Vector_reflect, METH_O, Vector_reflect_doc}, | 
					
						
							|  |  |  |     {"cross", (PyCFunction)Vector_cross, METH_O, Vector_cross_doc}, | 
					
						
							|  |  |  |     {"dot", (PyCFunction)Vector_dot, METH_O, Vector_dot_doc}, | 
					
						
							|  |  |  |     {"angle", (PyCFunction)Vector_angle, METH_VARARGS, Vector_angle_doc}, | 
					
						
							| 
									
										
										
										
											2012-03-14 06:14:15 +00:00
										 |  |  |     {"angle_signed", (PyCFunction)Vector_angle_signed, METH_VARARGS, Vector_angle_signed_doc}, | 
					
						
							| 
									
										
										
										
											2011-04-04 05:17:23 +00:00
										 |  |  |     {"rotation_difference", | 
					
						
							|  |  |  |      (PyCFunction)Vector_rotation_difference, | 
					
						
							|  |  |  |      METH_O, | 
					
						
							|  |  |  |      Vector_rotation_difference_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-04 03:06:23 +00:00
										 |  |  |     {"project", (PyCFunction)Vector_project, METH_O, Vector_project_doc}, | 
					
						
							|  |  |  |     {"lerp", (PyCFunction)Vector_lerp, METH_VARARGS, Vector_lerp_doc}, | 
					
						
							| 
									
										
										
										
											2014-03-31 13:18:23 +11:00
										 |  |  |     {"slerp", (PyCFunction)Vector_slerp, METH_VARARGS, Vector_slerp_doc}, | 
					
						
							| 
									
										
										
										
											2011-02-05 09:57:02 +00:00
										 |  |  |     {"rotate", (PyCFunction)Vector_rotate, METH_O, Vector_rotate_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     /* Base-math methods. */ | 
					
						
							| 
									
										
										
										
											2015-02-15 11:26:31 +11:00
										 |  |  |     {"freeze", (PyCFunction)BaseMathObject_freeze, METH_NOARGS, BaseMathObject_freeze_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     {"copy", (PyCFunction)Vector_copy, METH_NOARGS, Vector_copy_doc}, | 
					
						
							|  |  |  |     {"__copy__", (PyCFunction)Vector_copy, METH_NOARGS, NULL}, | 
					
						
							| 
									
										
										
										
											2012-03-30 11:35:58 +00:00
										 |  |  |     {"__deepcopy__", (PyCFunction)Vector_deepcopy, METH_VARARGS, NULL}, | 
					
						
							| 
									
										
										
										
											2019-02-03 14:01:45 +11:00
										 |  |  |     {NULL, NULL, 0, NULL}, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2021-07-03 23:08:40 +10:00
										 |  |  |  * NOTE: #Py_TPFLAGS_CHECKTYPES allows us to avoid casting all types to Vector when coercing | 
					
						
							| 
									
										
										
										
											2017-09-09 10:47:57 +10:00
										 |  |  |  * but this means for eg that (vec * mat) and (mat * vec) | 
					
						
							|  |  |  |  * both get sent to Vector_mul and it needs to sort out the order | 
					
						
							| 
									
										
										
										
											2012-03-09 18:28:30 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(vector_doc, | 
					
						
							| 
									
										
										
										
											2015-02-01 16:06:32 +01:00
										 |  |  |              ".. class:: Vector(seq)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   This object gives access to Vectors in Blender.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :param seq: Components of the vector, must be a sequence of at least two\n" | 
					
						
							|  |  |  |              "   :type seq: sequence of numbers\n"); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | PyTypeObject vector_Type = { | 
					
						
							|  |  |  |     PyVarObject_HEAD_INIT(NULL, 0) | 
					
						
							|  |  |  |     /*  For printing, in format "<module>.<name>" */ | 
					
						
							| 
									
										
										
										
											2012-04-15 14:54:15 +00:00
										 |  |  |     "Vector",             /* char *tp_name; */ | 
					
						
							| 
									
										
										
										
											2010-04-25 03:34:16 +00:00
										 |  |  |     sizeof(VectorObject), /* int tp_basicsize; */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     0,                    /* tp_itemsize;  For allocation */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Methods to implement standard operations */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     (destructor)BaseMathObject_dealloc, /* destructor tp_dealloc; */ | 
					
						
							| 
									
										
										
										
											2021-02-12 08:08:15 +11:00
										 |  |  |     0,                                  /* tp_vectorcall_offset */ | 
					
						
							|  |  |  |     NULL,                               /* getattrfunc tp_getattr; */ | 
					
						
							|  |  |  |     NULL,                               /* setattrfunc tp_setattr; */ | 
					
						
							|  |  |  |     NULL,                               /* cmpfunc tp_compare; */ | 
					
						
							|  |  |  |     (reprfunc)Vector_repr,              /* reprfunc tp_repr; */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Method suites for standard classes */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     &Vector_NumMethods, /* PyNumberMethods *tp_as_number; */ | 
					
						
							|  |  |  |     &Vector_SeqMethods, /* PySequenceMethods *tp_as_sequence; */ | 
					
						
							| 
									
										
										
										
											2009-07-01 13:31:36 +00:00
										 |  |  |     &Vector_AsMapping,  /* PyMappingMethods *tp_as_mapping; */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* More standard operations (here for binary compatibility) */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 10:46:14 +11:00
										 |  |  |     (hashfunc)Vector_hash, /* hashfunc tp_hash; */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     NULL,                  /* ternaryfunc tp_call; */ | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #ifndef MATH_STANDALONE
 | 
					
						
							| 
									
										
										
										
											2011-12-20 03:37:55 +00:00
										 |  |  |     (reprfunc)Vector_str, /* reprfunc tp_str; */ | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2021-02-12 08:08:15 +11:00
										 |  |  |     NULL, /* reprfunc tp_str; */ | 
					
						
							| 
									
										
										
										
											2012-12-08 01:16:59 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     NULL, /* getattrofunc tp_getattro; */ | 
					
						
							|  |  |  |     NULL, /* setattrofunc tp_setattro; */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     /* Functions to access object as input/output buffer */ | 
					
						
							|  |  |  |     NULL, /* PyBufferProcs *tp_as_buffer; */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     /*** Flags to define presence of optional/expanded features ***/ | 
					
						
							| 
									
										
										
										
											2011-03-03 06:01:31 +00:00
										 |  |  |     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, | 
					
						
							| 
									
										
										
											
												Mathutils refactor & include in sphinx generated docs, (TODO, include getset'ers in docs)
 - Mathutils.MidpointVecs --> vector.lerp(other, fac)
 - Mathutils.AngleBetweenVecs --> vector.angle(other)
 - Mathutils.ProjectVecs --> vector.project(other)
 - Mathutils.DifferenceQuats --> quat.difference(other)
 - Mathutils.Slerp --> quat.slerp(other, fac)
 - Mathutils.Rand: removed, use pythons random module
 - Mathutils.RotationMatrix(angle, size, axis_flag, axis) --> Mathutils.RotationMatrix(angle, size, axis); merge axis & axis_flag args
 - Matrix.scalePart --> Matrix.scale_part
 - Matrix.translationPart --> Matrix.translation_part
 - Matrix.rotationPart --> Matrix.rotation_part
 - toMatrix --> to_matrix
 - toEuler --> to_euler
 - toQuat --> to_quat
 - Vector.toTrackQuat --> Vector.to_track_quat
											
										 
											2010-01-25 09:44:04 +00:00
										 |  |  |     vector_doc, /*  char *tp_doc;  Documentation string */ | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     /*** Assigned meaning in release 2.0 ***/ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     /* call function for all accessible objects */ | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |     (traverseproc)BaseMathObject_traverse, /* tp_traverse */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     /* delete references to contained objects */ | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  |     (inquiry)BaseMathObject_clear, /* tp_clear */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     /***  Assigned meaning in release 2.1 ***/ | 
					
						
							|  |  |  |     /*** rich comparisons ***/ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     (richcmpfunc)Vector_richcmpr, /* richcmpfunc tp_richcompare; */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     /***  weak reference enabler ***/ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     0, /* long tp_weaklistoffset; */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     /*** Added in release 2.2 ***/ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     /*   Iterators */ | 
					
						
							|  |  |  |     NULL, /* getiterfunc tp_iter; */ | 
					
						
							|  |  |  |     NULL, /* iternextfunc tp_iternext; */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:55:09 +00:00
										 |  |  |     /*** Attribute descriptor and subclassing stuff ***/ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     Vector_methods,   /* struct PyMethodDef *tp_methods; */ | 
					
						
							|  |  |  |     NULL,             /* struct PyMemberDef *tp_members; */ | 
					
						
							|  |  |  |     Vector_getseters, /* struct PyGetSetDef *tp_getset; */ | 
					
						
							|  |  |  |     NULL,             /* struct _typeobject *tp_base; */ | 
					
						
							|  |  |  |     NULL,             /* PyObject *tp_dict; */ | 
					
						
							|  |  |  |     NULL,             /* descrgetfunc tp_descr_get; */ | 
					
						
							|  |  |  |     NULL,             /* descrsetfunc tp_descr_set; */ | 
					
						
							|  |  |  |     0,                /* long tp_dictoffset; */ | 
					
						
							|  |  |  |     NULL,             /* initproc tp_init; */ | 
					
						
							|  |  |  |     NULL,             /* allocfunc tp_alloc; */ | 
					
						
							| 
									
										
										
										
											2009-06-20 02:44:57 +00:00
										 |  |  |     Vector_new,       /* newfunc tp_new; */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     /*  Low-level free-memory routine */ | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     NULL, /* freefunc tp_free; */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     /* For PyObject_IS_GC */ | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     NULL, /* inquiry tp_is_gc; */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     NULL, /* PyObject *tp_bases; */ | 
					
						
							|  |  |  |     /* method resolution order */ | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |     NULL, /* PyObject *tp_mro; */ | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     NULL, /* PyObject *tp_cache; */ | 
					
						
							|  |  |  |     NULL, /* PyObject *tp_subclasses; */ | 
					
						
							|  |  |  |     NULL, /* PyObject *tp_weaklist; */ | 
					
						
							| 
									
										
										
										
											2019-01-19 13:21:18 +11:00
										 |  |  |     NULL, | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | PyObject *Vector_CreatePyObject(const float *vec, const int size, PyTypeObject *base_type) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |   VectorObject *self; | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   float *vec_alloc; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  |   if (size < 2) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_RuntimeError, "Vector(): invalid size"); | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2011-02-24 04:58:51 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   vec_alloc = PyMem_Malloc(size * sizeof(float)); | 
					
						
							|  |  |  |   if (UNLIKELY(vec_alloc == NULL)) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_MemoryError, | 
					
						
							|  |  |  |                     "Vector(): " | 
					
						
							|  |  |  |                     "problem allocating data"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   self = BASE_MATH_NEW(VectorObject, vector_Type, base_type); | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (self) { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     self->vec = vec_alloc; | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |     self->size = size; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |     /* init callbacks as NULL */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     self->cb_user = NULL; | 
					
						
							|  |  |  |     self->cb_type = self->cb_subtype = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     if (vec) { | 
					
						
							|  |  |  |       memcpy(self->vec, vec, size * sizeof(float)); | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     else { /* new empty */ | 
					
						
							| 
									
										
										
										
											2015-05-05 17:08:29 +10:00
										 |  |  |       copy_vn_fl(self->vec, size, 0.0f); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |       if (size == 4) { /* do the homogeneous thing */ | 
					
						
							|  |  |  |         self->vec[3] = 1.0f; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     self->flag = BASE_MATH_FLAG_DEFAULT; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     PyMem_Free(vec_alloc); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return (PyObject *)self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 11:02:26 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Create a vector that wraps existing memory. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param vec: Use this vector in-place. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | PyObject *Vector_CreatePyObject_wrap(float *vec, const int size, PyTypeObject *base_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   VectorObject *self; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (size < 2) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_RuntimeError, "Vector(): invalid size"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   self = BASE_MATH_NEW(VectorObject, vector_Type, base_type); | 
					
						
							|  |  |  |   if (self) { | 
					
						
							|  |  |  |     self->size = size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* init callbacks as NULL */ | 
					
						
							|  |  |  |     self->cb_user = NULL; | 
					
						
							|  |  |  |     self->cb_type = self->cb_subtype = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     self->vec = vec; | 
					
						
							|  |  |  |     self->flag = BASE_MATH_FLAG_DEFAULT | BASE_MATH_FLAG_IS_WRAP; | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   return (PyObject *)self; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 11:02:26 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Create a vector where the value is defined by registered callbacks, | 
					
						
							|  |  |  |  * see: #Mathutils_RegisterCallback | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  | PyObject *Vector_CreatePyObject_cb(PyObject *cb_user, int size, uchar cb_type, uchar cb_subtype) | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   VectorObject *self = (VectorObject *)Vector_CreatePyObject(NULL, size, NULL); | 
					
						
							| 
									
										
										
										
											2011-11-16 03:56:34 +00:00
										 |  |  |   if (self) { | 
					
						
							| 
									
										
										
										
											2011-02-24 05:46:57 +00:00
										 |  |  |     Py_INCREF(cb_user); | 
					
						
							| 
									
										
										
										
											2012-03-17 10:46:02 +00:00
										 |  |  |     self->cb_user = cb_user; | 
					
						
							|  |  |  |     self->cb_type = cb_type; | 
					
						
							|  |  |  |     self->cb_subtype = cb_subtype; | 
					
						
							| 
									
										
										
										
											2011-03-03 06:01:31 +00:00
										 |  |  |     PyObject_GC_Track(self); | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-11-28 06:03:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-25 10:11:37 +00:00
										 |  |  |   return (PyObject *)self; | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 11:02:26 +10:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  |  * \param vec: Initialized vector value to use in-place, allocated with #PyMem_Malloc | 
					
						
							| 
									
										
										
										
											2017-09-09 11:02:26 +10:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  | PyObject *Vector_CreatePyObject_alloc(float *vec, const int size, PyTypeObject *base_type) | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   VectorObject *self; | 
					
						
							|  |  |  |   self = (VectorObject *)Vector_CreatePyObject_wrap(vec, size, base_type); | 
					
						
							|  |  |  |   if (self) { | 
					
						
							| 
									
										
										
										
											2020-02-20 15:09:44 +11:00
										 |  |  |     self->flag &= ~BASE_MATH_FLAG_IS_WRAP; | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return (PyObject *)self; | 
					
						
							| 
									
										
										
										
											2011-12-18 07:27:11 +00:00
										 |  |  | } |