2009-06-17 20:33:34 +00:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
|
|
|
* Contributor(s): Joseph Gilbert, Campbell Barton
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-11-05 01:48:10 +00:00
|
|
|
/** \file blender/python/mathutils/mathutils.c
|
|
|
|
* \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
|
|
|
|
2015-01-06 16:42:22 +11:00
|
|
|
#include "../generic/python_utildefines.h"
|
|
|
|
|
2012-12-08 01:16:59 +00:00
|
|
|
#ifndef MATH_STANDALONE
|
|
|
|
# include "BLI_dynstr.h"
|
|
|
|
#endif
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2011-05-24 16:05:51 +00:00
|
|
|
PyDoc_STRVAR(M_Mathutils_doc,
|
2015-02-01 16:06:32 +01:00
|
|
|
"This module provides access to the math classes:\n"
|
|
|
|
"\n"
|
|
|
|
"- :class:`Color`,\n"
|
|
|
|
"- :class:`Euler`,\n"
|
|
|
|
"- :class:`Matrix`,\n"
|
|
|
|
"- :class:`Quaternion`,\n"
|
|
|
|
"- :class:`Vector`,\n"
|
|
|
|
"\n"
|
|
|
|
".. note::\n"
|
|
|
|
"\n"
|
|
|
|
" Classes, methods and attributes that accept vectors also accept other numeric sequences,\n"
|
|
|
|
" such as tuples, lists."
|
2011-05-24 16:05:51 +00:00
|
|
|
);
|
2011-11-29 20:22:35 +00:00
|
|
|
static int mathutils_array_parse_fast(float *array,
|
2011-12-18 07:27:11 +00:00
|
|
|
int size,
|
|
|
|
PyObject *value_fast,
|
2011-12-25 11:36:26 +00:00
|
|
|
const char *error_prefix)
|
2010-04-25 19:27:59 +00:00
|
|
|
{
|
2011-02-04 03:39:06 +00:00
|
|
|
PyObject *item;
|
2010-04-25 19:27:59 +00:00
|
|
|
|
2011-12-18 07:27:11 +00:00
|
|
|
int i;
|
2010-04-25 19:27:59 +00:00
|
|
|
|
2011-12-24 13:26:30 +00:00
|
|
|
i = size;
|
2010-04-25 19:27:59 +00:00
|
|
|
do {
|
|
|
|
i--;
|
2012-03-16 21:39:56 +00:00
|
|
|
if (((array[i] = PyFloat_AsDouble((item = PySequence_Fast_GET_ITEM(value_fast, i)))) == -1.0f) &&
|
|
|
|
PyErr_Occurred())
|
2011-11-29 20:22:35 +00:00
|
|
|
{
|
2011-07-14 09:54:03 +00:00
|
|
|
PyErr_Format(PyExc_TypeError,
|
2011-07-14 01:25:05 +00:00
|
|
|
"%.200s: sequence index %d expected a number, "
|
|
|
|
"found '%.200s' type, ",
|
|
|
|
error_prefix, i, Py_TYPE(item)->tp_name);
|
2010-04-25 19:27:59 +00:00
|
|
|
Py_DECREF(value_fast);
|
|
|
|
return -1;
|
|
|
|
}
|
2011-10-13 01:29:08 +00:00
|
|
|
} while (i);
|
2010-04-25 19:27:59 +00:00
|
|
|
|
|
|
|
Py_XDECREF(value_fast);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2015-02-15 10:46:14 +11:00
|
|
|
/**
|
|
|
|
* helper function that returns a Python ``__hash__``.
|
|
|
|
*
|
|
|
|
* \note consistent with the equivalent tuple of floats (CPython's 'tuplehash')
|
|
|
|
*/
|
|
|
|
Py_hash_t mathutils_array_hash(const float *array, size_t array_len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Py_uhash_t x; /* Unsigned for defined overflow behavior. */
|
|
|
|
Py_hash_t y;
|
|
|
|
Py_uhash_t mult;
|
|
|
|
Py_ssize_t len;
|
|
|
|
|
|
|
|
mult = _PyHASH_MULTIPLIER;
|
|
|
|
len = array_len;
|
|
|
|
x = 0x345678UL;
|
|
|
|
i = 0;
|
|
|
|
while (--len >= 0) {
|
|
|
|
y = _Py_HashDouble((double)(array[i++]));
|
|
|
|
if (y == -1)
|
|
|
|
return -1;
|
|
|
|
x = (x ^ y) * mult;
|
|
|
|
/* the cast might truncate len; that doesn't change hash stability */
|
|
|
|
mult += (Py_hash_t)(82520UL + len + len);
|
|
|
|
}
|
|
|
|
x += 97531UL;
|
|
|
|
if (x == (Py_uhash_t)-1)
|
|
|
|
x = -2;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2015-06-18 06:11:02 +10:00
|
|
|
/* helper function returns length of the 'value', -1 on error */
|
2011-01-16 11:26:01 +00:00
|
|
|
int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix)
|
|
|
|
{
|
2014-12-30 21:50:47 +11:00
|
|
|
const int flag = array_max;
|
2011-01-16 11:26:01 +00:00
|
|
|
int size;
|
|
|
|
|
2014-12-30 22:47:56 +11:00
|
|
|
array_max &= ~MU_ARRAY_FLAGS;
|
2014-12-30 21:50:47 +11:00
|
|
|
|
2011-12-18 07:27:11 +00:00
|
|
|
#if 1 /* approx 6x speedup for mathutils types */
|
|
|
|
|
2012-03-16 21:39:56 +00:00
|
|
|
if ((size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
|
|
|
|
(size = EulerObject_Check(value) ? 3 : 0) ||
|
|
|
|
(size = QuaternionObject_Check(value) ? 4 : 0) ||
|
|
|
|
(size = ColorObject_Check(value) ? 3 : 0))
|
2011-10-02 12:21:24 +00:00
|
|
|
{
|
2011-10-13 01:29:08 +00:00
|
|
|
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
2011-01-16 11:26:01 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-12-30 21:50:47 +11:00
|
|
|
if (flag & MU_ARRAY_SPILL) {
|
|
|
|
CLAMP_MAX(size, array_max);
|
|
|
|
}
|
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (size > array_max || size < array_min) {
|
2012-03-26 06:55:09 +00:00
|
|
|
if (array_max == array_min) {
|
2011-07-14 01:25:05 +00:00
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"%.200s: sequence size is %d, expected %d",
|
|
|
|
error_prefix, size, array_max);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"%.200s: sequence size is %d, expected [%d - %d]",
|
|
|
|
error_prefix, size, array_min, array_max);
|
|
|
|
}
|
2011-01-16 11:26:01 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(array, ((BaseMathObject *)value)->data, size * sizeof(float));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2011-12-24 13:26:30 +00:00
|
|
|
PyObject *value_fast = NULL;
|
2011-12-18 07:27:11 +00:00
|
|
|
|
|
|
|
/* non list/tuple cases */
|
2011-12-24 13:26:30 +00:00
|
|
|
if (!(value_fast = PySequence_Fast(value, error_prefix))) {
|
2011-12-18 07:27:11 +00:00
|
|
|
/* PySequence_Fast sets the error */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-12-24 13:26:30 +00:00
|
|
|
size = PySequence_Fast_GET_SIZE(value_fast);
|
2011-12-18 07:27:11 +00:00
|
|
|
|
2014-12-30 21:50:47 +11:00
|
|
|
if (flag & MU_ARRAY_SPILL) {
|
|
|
|
CLAMP_MAX(size, array_max);
|
|
|
|
}
|
|
|
|
|
2011-12-18 07:27:11 +00:00
|
|
|
if (size > array_max || size < array_min) {
|
2012-03-26 06:55:09 +00:00
|
|
|
if (array_max == array_min) {
|
2011-12-18 07:27:11 +00:00
|
|
|
PyErr_Format(PyExc_ValueError,
|
2012-03-26 06:55:09 +00:00
|
|
|
"%.200s: sequence size is %d, expected %d",
|
|
|
|
error_prefix, size, array_max);
|
2011-12-18 07:27:11 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
2012-03-26 06:55:09 +00:00
|
|
|
"%.200s: sequence size is %d, expected [%d - %d]",
|
|
|
|
error_prefix, size, array_min, array_max);
|
2011-12-18 07:27:11 +00:00
|
|
|
}
|
|
|
|
Py_DECREF(value_fast);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-12-30 21:50:47 +11:00
|
|
|
size = mathutils_array_parse_fast(array, size, value_fast, error_prefix);
|
2011-12-18 07:27:11 +00:00
|
|
|
}
|
2014-12-30 21:50:47 +11:00
|
|
|
|
|
|
|
if (size != -1) {
|
|
|
|
if (flag & MU_ARRAY_ZERO) {
|
|
|
|
int size_left = array_max - size;
|
|
|
|
if (size_left) {
|
|
|
|
memset(&array[size], 0, sizeof(float) * size_left);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
2011-12-18 07:27:11 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 16:58:58 +00:00
|
|
|
/* on error, -1 is returned and no allocation is made */
|
2011-12-18 07:27:11 +00:00
|
|
|
int mathutils_array_parse_alloc(float **array, int array_min, PyObject *value, const char *error_prefix)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
#if 1 /* approx 6x speedup for mathutils types */
|
|
|
|
|
2012-03-16 21:39:56 +00:00
|
|
|
if ((size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
|
|
|
|
(size = EulerObject_Check(value) ? 3 : 0) ||
|
|
|
|
(size = QuaternionObject_Check(value) ? 4 : 0) ||
|
|
|
|
(size = ColorObject_Check(value) ? 3 : 0))
|
2011-12-18 07:27:11 +00:00
|
|
|
{
|
|
|
|
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size < array_min) {
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"%.200s: sequence size is %d, expected > %d",
|
|
|
|
error_prefix, size, array_min);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-12-24 13:26:30 +00:00
|
|
|
*array = PyMem_Malloc(size * sizeof(float));
|
2011-12-18 07:27:11 +00:00
|
|
|
memcpy(*array, ((BaseMathObject *)value)->data, size * sizeof(float));
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2011-12-24 13:26:30 +00:00
|
|
|
PyObject *value_fast = NULL;
|
2012-03-09 18:28:30 +00:00
|
|
|
// *array = NULL;
|
2012-06-26 16:58:58 +00:00
|
|
|
int ret;
|
2011-12-18 07:27:11 +00:00
|
|
|
|
|
|
|
/* non list/tuple cases */
|
2011-12-24 13:26:30 +00:00
|
|
|
if (!(value_fast = PySequence_Fast(value, error_prefix))) {
|
2011-12-18 07:27:11 +00:00
|
|
|
/* PySequence_Fast sets the error */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-12-24 13:26:30 +00:00
|
|
|
size = PySequence_Fast_GET_SIZE(value_fast);
|
2011-12-18 07:27:11 +00:00
|
|
|
|
|
|
|
if (size < array_min) {
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"%.200s: sequence size is %d, expected > %d",
|
|
|
|
error_prefix, size, array_min);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-12-24 13:26:30 +00:00
|
|
|
*array = PyMem_Malloc(size * sizeof(float));
|
2011-12-18 07:27:11 +00:00
|
|
|
|
2012-06-26 16:58:58 +00:00
|
|
|
ret = mathutils_array_parse_fast(*array, size, value_fast, error_prefix);
|
|
|
|
|
|
|
|
if (ret == -1) {
|
|
|
|
PyMem_Free(*array);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2011-01-16 11:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-22 10:19:24 +00:00
|
|
|
/* parse an array of vectors */
|
|
|
|
int mathutils_array_parse_alloc_v(float **array, int array_dim, PyObject *value, const char *error_prefix)
|
|
|
|
{
|
|
|
|
PyObject *value_fast = NULL;
|
2014-12-30 22:47:56 +11:00
|
|
|
const int array_dim_flag = array_dim;
|
2012-04-22 10:19:24 +00:00
|
|
|
int i, size;
|
|
|
|
|
|
|
|
/* non list/tuple cases */
|
|
|
|
if (!(value_fast = PySequence_Fast(value, error_prefix))) {
|
|
|
|
/* PySequence_Fast sets the error */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = PySequence_Fast_GET_SIZE(value_fast);
|
|
|
|
|
|
|
|
if (size != 0) {
|
|
|
|
float *fp;
|
|
|
|
|
2014-12-30 22:47:56 +11:00
|
|
|
array_dim &= ~MU_ARRAY_FLAGS;
|
|
|
|
|
2012-04-22 10:19:24 +00:00
|
|
|
fp = *array = PyMem_Malloc(size * array_dim * sizeof(float));
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++, fp += array_dim) {
|
|
|
|
PyObject *item = PySequence_Fast_GET_ITEM(value, i);
|
|
|
|
|
2014-12-30 22:47:56 +11:00
|
|
|
if (mathutils_array_parse(fp, array_dim, array_dim_flag, item, error_prefix) == -1) {
|
2012-04-22 10:19:24 +00:00
|
|
|
PyMem_Free(*array);
|
|
|
|
*array = NULL;
|
|
|
|
size = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Py_DECREF(value_fast);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2011-02-05 09:57:02 +00:00
|
|
|
int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix)
|
|
|
|
{
|
2011-10-13 01:29:08 +00:00
|
|
|
if (EulerObject_Check(value)) {
|
|
|
|
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
2011-02-05 09:57:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
eulO_to_mat3(rmat, ((EulerObject *)value)->eul, ((EulerObject *)value)->order);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (QuaternionObject_Check(value)) {
|
2011-10-13 01:29:08 +00:00
|
|
|
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
2011-02-05 09:57:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float tquat[4];
|
|
|
|
normalize_qt_qt(tquat, ((QuaternionObject *)value)->quat);
|
|
|
|
quat_to_mat3(rmat, tquat);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (MatrixObject_Check(value)) {
|
2011-10-13 01:29:08 +00:00
|
|
|
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
2011-02-05 09:57:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2011-12-20 04:11:23 +00:00
|
|
|
else if (((MatrixObject *)value)->num_row < 3 || ((MatrixObject *)value)->num_col < 3) {
|
2011-07-14 01:25:05 +00:00
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"%.200s: matrix must have minimum 3x3 dimensions",
|
|
|
|
error_prefix);
|
2011-02-05 09:57:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
matrix_as_3x3(rmat, (MatrixObject *)value);
|
|
|
|
normalize_m3(rmat);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-07-14 01:25:05 +00:00
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
"%.200s: expected a Euler, Quaternion or Matrix type, "
|
|
|
|
"found %.200s", error_prefix, Py_TYPE(value)->tp_name);
|
2011-02-05 09:57:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-20 20:20:02 +00:00
|
|
|
/* ----------------------------------MATRIX FUNCTIONS-------------------- */
|
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
|
|
|
|
|
|
|
/* Utility functions */
|
|
|
|
|
2012-10-20 20:20:02 +00:00
|
|
|
/* LomontRRDCompare4, Ever Faster Float Comparisons by Randy Dillon */
|
2015-07-10 14:32:35 +02:00
|
|
|
/* XXX We may want to use 'safer' BLI's compare_ff_relative ultimately?
|
|
|
|
* LomontRRDCompare4() is an optimized version of Dawson's AlmostEqual2sComplement() (see [1] and [2]).
|
|
|
|
* Dawson himself now claims this is not a 'safe' thing to do (pushing ULP method beyond its limits),
|
|
|
|
* an recommands using work from [3] instead, which is done in BLI func...
|
|
|
|
*
|
|
|
|
* [1] http://www.randydillon.org/Papers/2007/everfast.htm
|
|
|
|
* [2] http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
|
|
|
|
* [3] https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ instead
|
|
|
|
*/
|
2012-03-26 06:55:09 +00:00
|
|
|
#define SIGNMASK(i) (-(int)(((unsigned int)(i)) >> 31))
|
2010-02-28 19:27:06 +00:00
|
|
|
|
|
|
|
int EXPP_FloatsAreEqual(float af, float bf, int maxDiff)
|
2012-03-26 06:55:09 +00:00
|
|
|
{
|
|
|
|
/* solid, fast routine across all platforms
|
|
|
|
* with constant time behavior */
|
2010-02-28 19:27:06 +00:00
|
|
|
int ai = *(int *)(&af);
|
|
|
|
int bi = *(int *)(&bf);
|
2012-03-26 06:55:09 +00:00
|
|
|
int test = SIGNMASK(ai ^ bi);
|
2010-02-28 19:27:06 +00:00
|
|
|
int diff, v1, v2;
|
|
|
|
|
|
|
|
assert((0 == test) || (0xFFFFFFFF == test));
|
|
|
|
diff = (ai ^ (test & 0x7fffffff)) - bi;
|
|
|
|
v1 = maxDiff + diff;
|
|
|
|
v2 = maxDiff - diff;
|
2012-03-26 06:55:09 +00:00
|
|
|
return (v1 | v2) >= 0;
|
2009-06-17 20:33:34 +00:00
|
|
|
}
|
2010-02-28 19:27:06 +00:00
|
|
|
|
2009-06-17 20:33:34 +00:00
|
|
|
/*---------------------- EXPP_VectorsAreEqual -------------------------
|
2012-03-03 20:36:09 +00:00
|
|
|
* Builds on EXPP_FloatsAreEqual to test vectors */
|
2012-12-02 04:51:15 +00:00
|
|
|
int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps)
|
2009-06-22 04:26:48 +00:00
|
|
|
{
|
2009-06-17 20:33:34 +00:00
|
|
|
int x;
|
2011-12-24 13:26:30 +00:00
|
|
|
for (x = 0; x < size; x++) {
|
2009-06-17 20:33:34 +00:00
|
|
|
if (EXPP_FloatsAreEqual(vecA[x], vecB[x], floatSteps) == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-12-08 01:16:59 +00:00
|
|
|
#ifndef MATH_STANDALONE
|
2011-12-20 03:37:55 +00:00
|
|
|
/* dynstr as python string utility funcions, frees 'ds'! */
|
|
|
|
PyObject *mathutils_dynstr_to_py(struct DynStr *ds)
|
|
|
|
{
|
|
|
|
const int ds_len = BLI_dynstr_get_len(ds); /* space for \0 */
|
|
|
|
char *ds_buf = PyMem_Malloc(ds_len + 1);
|
|
|
|
PyObject *ret;
|
|
|
|
BLI_dynstr_get_cstring_ex(ds, ds_buf);
|
|
|
|
BLI_dynstr_free(ds);
|
|
|
|
ret = PyUnicode_FromStringAndSize(ds_buf, ds_len);
|
|
|
|
PyMem_Free(ds_buf);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-12-08 01:16:59 +00:00
|
|
|
#endif
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2012-03-30 11:35:58 +00:00
|
|
|
/* silly function, we dont use arg. just check its compatible with __deepcopy__ */
|
|
|
|
int mathutils_deepcopy_args_check(PyObject *args)
|
|
|
|
{
|
|
|
|
PyObject *dummy_pydict;
|
|
|
|
return PyArg_ParseTuple(args, "|O!:__deepcopy__", &PyDict_Type, &dummy_pydict) != 0;
|
|
|
|
}
|
|
|
|
|
2009-06-22 04:26:48 +00:00
|
|
|
/* Mathutils Callbacks */
|
|
|
|
|
|
|
|
/* for mathutils internal use only, eventually should re-alloc but to start with we only have a few users */
|
2013-05-17 07:10:40 +00:00
|
|
|
#define MATHUTILS_TOT_CB 16
|
2012-03-17 10:46:02 +00:00
|
|
|
static Mathutils_Callback *mathutils_callbacks[MATHUTILS_TOT_CB] = {NULL};
|
2009-06-22 04:26:48 +00:00
|
|
|
|
2012-03-17 10:46:02 +00:00
|
|
|
unsigned char Mathutils_RegisterCallback(Mathutils_Callback *cb)
|
2009-06-22 04:26:48 +00:00
|
|
|
{
|
2012-03-17 10:46:02 +00:00
|
|
|
unsigned char i;
|
2009-06-22 04:26:48 +00:00
|
|
|
|
|
|
|
/* find the first free slot */
|
2011-12-24 13:26:30 +00:00
|
|
|
for (i = 0; mathutils_callbacks[i]; i++) {
|
|
|
|
if (mathutils_callbacks[i] == cb) /* already registered? */
|
2009-06-22 04:26:48 +00:00
|
|
|
return i;
|
|
|
|
}
|
2012-03-17 10:46:02 +00:00
|
|
|
|
2012-04-10 12:35:15 +00:00
|
|
|
BLI_assert(i + 1 < MATHUTILS_TOT_CB);
|
2012-03-17 10:46:02 +00:00
|
|
|
|
2009-06-22 04:26:48 +00:00
|
|
|
mathutils_callbacks[i] = cb;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2009-06-23 13:34:45 +00:00
|
|
|
/* use macros to check for NULL */
|
2009-06-25 10:11:37 +00:00
|
|
|
int _BaseMathObject_ReadCallback(BaseMathObject *self)
|
2009-06-23 13:34:45 +00:00
|
|
|
{
|
2011-12-24 13:26:30 +00:00
|
|
|
Mathutils_Callback *cb = mathutils_callbacks[self->cb_type];
|
2012-02-26 23:59:08 +00:00
|
|
|
if (LIKELY(cb->get(self, self->cb_subtype) != -1)) {
|
2011-02-28 18:42:41 +00:00
|
|
|
return 0;
|
2012-02-26 23:59:08 +00:00
|
|
|
}
|
2009-06-25 10:11:37 +00:00
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (!PyErr_Occurred()) {
|
2011-07-14 01:25:05 +00:00
|
|
|
PyErr_Format(PyExc_RuntimeError,
|
|
|
|
"%s read, user has become invalid",
|
|
|
|
Py_TYPE(self)->tp_name);
|
|
|
|
}
|
2011-02-28 18:42:41 +00:00
|
|
|
return -1;
|
2009-06-22 04:26:48 +00:00
|
|
|
}
|
|
|
|
|
2009-06-25 10:11:37 +00:00
|
|
|
int _BaseMathObject_WriteCallback(BaseMathObject *self)
|
2009-06-23 13:34:45 +00:00
|
|
|
{
|
2011-12-24 13:26:30 +00:00
|
|
|
Mathutils_Callback *cb = mathutils_callbacks[self->cb_type];
|
2012-02-26 23:59:08 +00:00
|
|
|
if (LIKELY(cb->set(self, self->cb_subtype) != -1)) {
|
2011-02-28 18:42:41 +00:00
|
|
|
return 0;
|
2012-02-26 23:59:08 +00:00
|
|
|
}
|
2009-06-25 10:11:37 +00:00
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (!PyErr_Occurred()) {
|
2011-07-14 01:25:05 +00:00
|
|
|
PyErr_Format(PyExc_RuntimeError,
|
|
|
|
"%s write, user has become invalid",
|
|
|
|
Py_TYPE(self)->tp_name);
|
|
|
|
}
|
2011-02-28 18:42:41 +00:00
|
|
|
return -1;
|
2009-06-22 04:26:48 +00:00
|
|
|
}
|
|
|
|
|
2009-06-25 10:11:37 +00:00
|
|
|
int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index)
|
2009-06-23 13:34:45 +00:00
|
|
|
{
|
2011-12-24 13:26:30 +00:00
|
|
|
Mathutils_Callback *cb = mathutils_callbacks[self->cb_type];
|
2012-02-26 23:59:08 +00:00
|
|
|
if (LIKELY(cb->get_index(self, self->cb_subtype, index) != -1)) {
|
2011-02-28 18:42:41 +00:00
|
|
|
return 0;
|
2012-02-26 23:59:08 +00:00
|
|
|
}
|
2009-06-25 10:11:37 +00:00
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (!PyErr_Occurred()) {
|
2011-07-14 01:25:05 +00:00
|
|
|
PyErr_Format(PyExc_RuntimeError,
|
|
|
|
"%s read index, user has become invalid",
|
|
|
|
Py_TYPE(self)->tp_name);
|
|
|
|
}
|
2011-02-28 18:42:41 +00:00
|
|
|
return -1;
|
2009-06-22 04:26:48 +00:00
|
|
|
}
|
2009-06-17 20:33:34 +00:00
|
|
|
|
2009-06-25 10:11:37 +00:00
|
|
|
int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index)
|
2009-06-23 13:34:45 +00:00
|
|
|
{
|
2011-12-24 13:26:30 +00:00
|
|
|
Mathutils_Callback *cb = mathutils_callbacks[self->cb_type];
|
2012-02-26 23:59:08 +00:00
|
|
|
if (LIKELY(cb->set_index(self, self->cb_subtype, index) != -1)) {
|
2011-02-28 18:42:41 +00:00
|
|
|
return 0;
|
2012-02-26 23:59:08 +00:00
|
|
|
}
|
2009-06-25 10:11:37 +00:00
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (!PyErr_Occurred()) {
|
2011-07-14 01:25:05 +00:00
|
|
|
PyErr_Format(PyExc_RuntimeError,
|
|
|
|
"%s write index, user has become invalid",
|
|
|
|
Py_TYPE(self)->tp_name);
|
|
|
|
}
|
2011-02-28 18:42:41 +00:00
|
|
|
return -1;
|
2009-06-23 13:34:45 +00:00
|
|
|
}
|
|
|
|
|
2015-02-15 11:26:31 +11:00
|
|
|
void _BaseMathObject_RaiseFrozenExc(const BaseMathObject *self)
|
|
|
|
{
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
"%s is frozen (immutable)",
|
|
|
|
Py_TYPE(self)->tp_name);
|
|
|
|
}
|
|
|
|
|
2015-02-15 10:46:14 +11:00
|
|
|
void _BaseMathObject_RaiseNotFrozenExc(const BaseMathObject *self)
|
|
|
|
{
|
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
"%s is not frozen (mutable), call freeze first",
|
|
|
|
Py_TYPE(self)->tp_name);
|
|
|
|
}
|
|
|
|
|
2009-06-25 10:11:37 +00:00
|
|
|
/* BaseMathObject generic functions for all mathutils types */
|
2012-02-24 06:44:04 +00:00
|
|
|
char BaseMathObject_owner_doc[] = "The item this is wrapping or None (read-only).";
|
2011-12-24 04:58:01 +00:00
|
|
|
PyObject *BaseMathObject_owner_get(BaseMathObject *self, void *UNUSED(closure))
|
2009-06-23 13:34:45 +00:00
|
|
|
{
|
2011-12-24 13:26:30 +00:00
|
|
|
PyObject *ret = self->cb_user ? self->cb_user : Py_None;
|
2015-01-06 16:42:22 +11:00
|
|
|
return Py_INCREF_RET(ret);
|
2009-06-23 13:34:45 +00:00
|
|
|
}
|
|
|
|
|
2012-02-24 06:44:04 +00:00
|
|
|
char BaseMathObject_is_wrapped_doc[] = "True when this object wraps external data (read-only).\n\n:type: boolean";
|
2011-12-24 04:58:01 +00:00
|
|
|
PyObject *BaseMathObject_is_wrapped_get(BaseMathObject *self, void *UNUSED(closure))
|
2009-06-23 13:34:45 +00:00
|
|
|
{
|
2015-01-04 17:03:54 +11:00
|
|
|
return PyBool_FromLong((self->flag & BASE_MATH_FLAG_IS_WRAP) != 0);
|
2009-06-22 04:26:48 +00:00
|
|
|
}
|
2009-06-25 10:11:37 +00:00
|
|
|
|
2015-02-15 11:26:31 +11:00
|
|
|
char BaseMathObject_is_frozen_doc[] = "True when this object has been frozen (read-only).\n\n:type: boolean";
|
|
|
|
PyObject *BaseMathObject_is_frozen_get(BaseMathObject *self, void *UNUSED(closure))
|
|
|
|
{
|
|
|
|
return PyBool_FromLong((self->flag & BASE_MATH_FLAG_IS_FROZEN) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
char BaseMathObject_freeze_doc[] =
|
|
|
|
".. function:: freeze()\n"
|
|
|
|
"\n"
|
|
|
|
" Make this object immutable.\n"
|
|
|
|
"\n"
|
|
|
|
" After this the object can be hashed, used in dictionaries & sets.\n"
|
|
|
|
"\n"
|
|
|
|
" :return: An instance of this object.\n"
|
|
|
|
;
|
|
|
|
PyObject *BaseMathObject_freeze(BaseMathObject *self)
|
|
|
|
{
|
|
|
|
if (self->flag & BASE_MATH_FLAG_IS_WRAP) {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "Cannot freeze wrapped data");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->flag |= BASE_MATH_FLAG_IS_FROZEN;
|
|
|
|
|
2015-06-16 10:18:45 +10:00
|
|
|
return Py_INCREF_RET((PyObject *)self);
|
2015-02-15 11:26:31 +11:00
|
|
|
}
|
|
|
|
|
2011-02-24 04:58:51 +00:00
|
|
|
int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg)
|
|
|
|
{
|
|
|
|
Py_VISIT(self->cb_user);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BaseMathObject_clear(BaseMathObject *self)
|
|
|
|
{
|
|
|
|
Py_CLEAR(self->cb_user);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseMathObject_dealloc(BaseMathObject *self)
|
2009-06-25 10:11:37 +00:00
|
|
|
{
|
|
|
|
/* only free non wrapped */
|
2015-01-04 17:03:54 +11:00
|
|
|
if ((self->flag & BASE_MATH_FLAG_IS_WRAP) == 0) {
|
2011-02-24 05:46:57 +00:00
|
|
|
PyMem_Free(self->data);
|
2011-02-24 04:58:51 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (self->cb_user) {
|
2011-03-03 06:14:55 +00:00
|
|
|
PyObject_GC_UnTrack(self);
|
|
|
|
BaseMathObject_clear(self);
|
|
|
|
}
|
2009-06-25 10:11:37 +00:00
|
|
|
|
2009-06-30 00:42:17 +00:00
|
|
|
Py_TYPE(self)->tp_free(self); // PyObject_DEL(self); // breaks subtypes
|
2009-06-25 10:11:37 +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
|
|
|
/*----------------------------MODULE INIT-------------------------*/
|
2011-02-13 10:52:18 +00:00
|
|
|
static struct PyMethodDef M_Mathutils_methods[] = {
|
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
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct PyModuleDef M_Mathutils_module_def = {
|
|
|
|
PyModuleDef_HEAD_INIT,
|
2010-04-11 14:22:27 +00:00
|
|
|
"mathutils", /* m_name */
|
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
|
|
|
M_Mathutils_doc, /* m_doc */
|
|
|
|
0, /* m_size */
|
|
|
|
M_Mathutils_methods, /* m_methods */
|
2011-02-13 10:52:18 +00:00
|
|
|
NULL, /* m_reload */
|
|
|
|
NULL, /* m_traverse */
|
|
|
|
NULL, /* m_clear */
|
|
|
|
NULL, /* m_free */
|
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-01-07 00:53:52 +11:00
|
|
|
|
|
|
|
/* submodules only */
|
|
|
|
#include "mathutils_geometry.h"
|
2014-12-15 19:45:01 +01:00
|
|
|
#include "mathutils_interpolate.h"
|
2014-05-17 12:05:16 +10:00
|
|
|
#ifndef MATH_STANDALONE
|
|
|
|
# include "mathutils_kdtree.h"
|
|
|
|
# include "mathutils_noise.h"
|
|
|
|
#endif
|
2014-01-07 00:53:52 +11:00
|
|
|
|
2011-07-15 04:01:47 +00:00
|
|
|
PyMODINIT_FUNC PyInit_mathutils(void)
|
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-04-15 14:54:15 +00:00
|
|
|
PyObject *mod;
|
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
|
|
|
PyObject *submodule;
|
2011-12-24 13:26:30 +00:00
|
|
|
PyObject *sys_modules = PyThreadState_GET()->interp->modules;
|
2010-10-29 22:59:39 +00:00
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (PyType_Ready(&vector_Type) < 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
|
|
|
return NULL;
|
2011-10-13 01:29:08 +00:00
|
|
|
if (PyType_Ready(&matrix_Type) < 0)
|
2011-12-24 07:03:19 +00:00
|
|
|
return NULL;
|
|
|
|
if (PyType_Ready(&matrix_access_Type) < 0)
|
|
|
|
return NULL;
|
2011-10-13 01:29:08 +00:00
|
|
|
if (PyType_Ready(&euler_Type) < 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
|
|
|
return NULL;
|
2011-10-13 01:29:08 +00:00
|
|
|
if (PyType_Ready(&quaternion_Type) < 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
|
|
|
return NULL;
|
2011-10-13 01:29:08 +00:00
|
|
|
if (PyType_Ready(&color_Type) < 0)
|
2010-04-11 14:22:27 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-04-15 14:54:15 +00:00
|
|
|
mod = PyModule_Create(&M_Mathutils_module_def);
|
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
|
|
|
|
|
|
|
/* each type has its own new() function */
|
2012-04-15 14:54:15 +00:00
|
|
|
PyModule_AddObject(mod, vector_Type.tp_name, (PyObject *)&vector_Type);
|
|
|
|
PyModule_AddObject(mod, matrix_Type.tp_name, (PyObject *)&matrix_Type);
|
|
|
|
PyModule_AddObject(mod, euler_Type.tp_name, (PyObject *)&euler_Type);
|
|
|
|
PyModule_AddObject(mod, quaternion_Type.tp_name, (PyObject *)&quaternion_Type);
|
|
|
|
PyModule_AddObject(mod, color_Type.tp_name, (PyObject *)&color_Type);
|
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-10-25 22:44:01 +00:00
|
|
|
/* submodule */
|
2012-04-15 14:54:15 +00:00
|
|
|
PyModule_AddObject(mod, "geometry", (submodule = PyInit_mathutils_geometry()));
|
2014-12-31 09:58:47 +01:00
|
|
|
/* XXX, python doesnt do imports with this usefully yet
|
|
|
|
* 'from mathutils.geometry import PolyFill'
|
|
|
|
* ...fails without this. */
|
|
|
|
PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
|
|
|
|
Py_INCREF(submodule);
|
|
|
|
|
2014-12-15 19:45:01 +01:00
|
|
|
PyModule_AddObject(mod, "interpolate", (submodule = PyInit_mathutils_interpolate()));
|
2010-10-31 13:17:39 +00:00
|
|
|
/* XXX, python doesnt do imports with this usefully yet
|
|
|
|
* 'from mathutils.geometry import PolyFill'
|
|
|
|
* ...fails without this. */
|
2012-04-15 14:54:15 +00:00
|
|
|
PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
|
|
|
|
Py_INCREF(submodule);
|
2011-11-29 10:28:52 +00:00
|
|
|
|
2013-09-14 00:30:56 +00:00
|
|
|
#ifndef MATH_STANDALONE
|
2011-11-29 10:28:52 +00:00
|
|
|
/* Noise submodule */
|
2012-04-15 14:54:15 +00:00
|
|
|
PyModule_AddObject(mod, "noise", (submodule = PyInit_mathutils_noise()));
|
|
|
|
PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
|
|
|
|
Py_INCREF(submodule);
|
2014-01-06 20:32:34 +11:00
|
|
|
|
|
|
|
/* KDTree submodule */
|
|
|
|
PyModule_AddObject(mod, "kdtree", (submodule = PyInit_mathutils_kdtree()));
|
|
|
|
PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
|
|
|
|
Py_INCREF(submodule);
|
2013-09-14 00:30:56 +00:00
|
|
|
#endif
|
2010-10-31 13:17:39 +00:00
|
|
|
|
2011-12-24 13:26:30 +00:00
|
|
|
mathutils_matrix_row_cb_index = Mathutils_RegisterCallback(&mathutils_matrix_row_cb);
|
|
|
|
mathutils_matrix_col_cb_index = Mathutils_RegisterCallback(&mathutils_matrix_col_cb);
|
2011-12-26 00:05:41 +00:00
|
|
|
mathutils_matrix_translation_cb_index = Mathutils_RegisterCallback(&mathutils_matrix_translation_cb);
|
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-04-15 14:54:15 +00:00
|
|
|
return mod;
|
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
|
|
|
}
|