| 
									
										
										
										
											2011-06-26 17:16:06 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											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>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-07 00:53:52 +11:00
										 |  |  | #include "mathutils.h"
 | 
					
						
							| 
									
										
										
										
											2010-10-25 22:44:01 +00:00
										 |  |  | #include "mathutils_geometry.h"
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Used for PolyFill */ | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | #ifndef MATH_STANDALONE /* define when building outside blender */
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #  include "BKE_curve.h"
 | 
					
						
							|  |  |  | #  include "BKE_displist.h"
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | #  include "BLI_blenlib.h"
 | 
					
						
							| 
									
										
										
										
											2018-02-18 21:27:33 +11:00
										 |  |  | #  include "BLI_boxpack_2d.h"
 | 
					
						
							|  |  |  | #  include "BLI_convexhull_2d.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  | #  include "BLI_delaunay_2d.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #  include "MEM_guardedalloc.h"
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_math.h"
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-04 18:34:20 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "../generic/py_capi_utils.h"
 | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  | #include "../generic/python_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------DOC STRINGS ---------------------------*/ | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(M_Geometry_doc, "The Blender geometry module"); | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 20:20:02 +00:00
										 |  |  | /* ---------------------------------INTERSECTION FUNCTIONS-------------------- */ | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(M_Geometry_intersect_ray_tri_doc, | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              ".. function:: intersect_ray_tri(v1, v2, v3, ray, orig, clip=True)\n" | 
					
						
							| 
									
										
										
										
											2010-12-10 00:20:32 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Returns the intersection between a ray and a triangle, if possible, returns None " | 
					
						
							|  |  |  |              "otherwise.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg v1: Point1\n" | 
					
						
							|  |  |  |              "   :type v1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg v2: Point2\n" | 
					
						
							|  |  |  |              "   :type v2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg v3: Point3\n" | 
					
						
							|  |  |  |              "   :type v3: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg ray: Direction of the projection\n" | 
					
						
							|  |  |  |              "   :type ray: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg orig: Origin\n" | 
					
						
							|  |  |  |              "   :type orig: :class:`mathutils.Vector`\n" | 
					
						
							| 
									
										
										
										
											2011-04-14 12:19:31 +00:00
										 |  |  |              "   :arg clip: When False, don't restrict the intersection to the area of the " | 
					
						
							|  |  |  |              "triangle, use the infinite plane defined by the triangle.\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              "   :type clip: boolean\n" | 
					
						
							|  |  |  |              "   :return: The point of intersection or None if no intersection is found\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`mathutils.Vector` or None\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_intersect_ray_tri(PyObject *UNUSED(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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "intersect_ray_tri"; | 
					
						
							|  |  |  |   PyObject *py_ray, *py_ray_off, *py_tri[3]; | 
					
						
							|  |  |  |   float dir[3], orig[3], tri[3][3], e1[3], e2[3], pvec[3], tvec[3], qvec[3]; | 
					
						
							| 
									
										
										
											
												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
										 |  |  |   float det, inv_det, u, v, t; | 
					
						
							| 
									
										
										
										
											2015-08-04 18:34:20 +10:00
										 |  |  |   bool clip = true; | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, | 
					
						
							| 
									
										
										
										
											2015-08-04 18:34:20 +10:00
										 |  |  |                         "OOOOO|O&:intersect_ray_tri", | 
					
						
							|  |  |  |                         UNPACK3_EX(&, py_tri, ), | 
					
						
							|  |  |  |                         &py_ray, | 
					
						
							|  |  |  |                         &py_ray_off, | 
					
						
							|  |  |  |                         PyC_ParseBool, | 
					
						
							|  |  |  |                         &clip)) { | 
					
						
							| 
									
										
										
											
												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-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 18:09:55 +01:00
										 |  |  |   if (((mathutils_array_parse(dir, 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_ray, error_prefix) != | 
					
						
							|  |  |  |         -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse( | 
					
						
							|  |  |  |             orig, 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_ray_off, error_prefix) != -1)) == 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-11-13 09:38:53 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   for (i = 0; i < ARRAY_SIZE(tri); i++) { | 
					
						
							| 
									
										
										
										
											2015-01-29 18:09:55 +01:00
										 |  |  |     if (mathutils_array_parse( | 
					
						
							|  |  |  |             tri[i], 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_tri[i], error_prefix) == -1) { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   normalize_v3(dir); | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   /* find vectors for two edges sharing v1 */ | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   sub_v3_v3v3(e1, tri[1], tri[0]); | 
					
						
							|  |  |  |   sub_v3_v3v3(e2, tri[2], tri[0]); | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   /* begin calculating determinant - also used to calculated U parameter */ | 
					
						
							|  |  |  |   cross_v3_v3v3(pvec, dir, e2); | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   /* if determinant is near zero, ray lies in plane of triangle */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   det = dot_v3v3(e1, pvec); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-27 17:12:59 +00:00
										 |  |  |   if (det > -0.000001f && det < 0.000001f) { | 
					
						
							| 
									
										
										
											
												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
										 |  |  |     Py_RETURN_NONE; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   inv_det = 1.0f / det; | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   /* calculate distance from v1 to ray origin */ | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   sub_v3_v3v3(tvec, orig, tri[0]); | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   /* calculate U parameter and test bounds */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   u = dot_v3v3(tvec, pvec) * inv_det; | 
					
						
							| 
									
										
										
											
												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
										 |  |  |   if (clip && (u < 0.0f || u > 1.0f)) { | 
					
						
							|  |  |  |     Py_RETURN_NONE; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   /* prepare to test the V parameter */ | 
					
						
							|  |  |  |   cross_v3_v3v3(qvec, tvec, e1); | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   /* calculate V parameter and test bounds */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   v = dot_v3v3(dir, qvec) * inv_det; | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   if (clip && (v < 0.0f || u + v > 1.0f)) { | 
					
						
							|  |  |  |     Py_RETURN_NONE; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   /* calculate t, ray intersects triangle */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   t = dot_v3v3(e2, qvec) * inv_det; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-08 09:42:34 +02:00
										 |  |  |   /* ray hit behind */ | 
					
						
							|  |  |  |   if (t < 0.0f) { | 
					
						
							|  |  |  |     Py_RETURN_NONE; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   mul_v3_fl(dir, t); | 
					
						
							|  |  |  |   add_v3_v3v3(pvec, orig, dir); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Vector_CreatePyObject(pvec, 3, 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
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +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
										 |  |  | /* Line-Line intersection using algorithm from mathworld.wolfram.com */ | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(M_Geometry_intersect_line_line_doc, | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              ".. function:: intersect_line_line(v1, v2, v3, v4)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Returns a tuple with the points on each line respectively closest to the other.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg v1: First point of the first line\n" | 
					
						
							|  |  |  |              "   :type v1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg v2: Second point of the first line\n" | 
					
						
							|  |  |  |              "   :type v2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg v3: First point of the second line\n" | 
					
						
							|  |  |  |              "   :type v3: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg v4: Second point of the second line\n" | 
					
						
							|  |  |  |              "   :type v4: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :rtype: tuple of :class:`mathutils.Vector`'s\n"); | 
					
						
							|  |  |  | static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "intersect_line_line"; | 
					
						
							| 
									
										
										
										
											2011-06-02 08:29:16 +00:00
										 |  |  |   PyObject *tuple; | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   PyObject *py_lines[4]; | 
					
						
							|  |  |  |   float lines[4][3], i1[3], i2[3]; | 
					
						
							|  |  |  |   int len; | 
					
						
							|  |  |  |   int result; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "OOOO:intersect_line_line", UNPACK4_EX(&, py_lines, ))) { | 
					
						
							| 
									
										
										
											
												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-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 18:09:55 +01:00
										 |  |  |   if ((((len = mathutils_array_parse( | 
					
						
							|  |  |  |              lines[0], 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_lines[0], error_prefix)) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse( | 
					
						
							|  |  |  |             lines[1], len, len | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_lines[1], error_prefix) != | 
					
						
							|  |  |  |         -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse( | 
					
						
							|  |  |  |             lines[2], len, len | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_lines[2], error_prefix) != | 
					
						
							|  |  |  |         -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse( | 
					
						
							|  |  |  |             lines[3], len, len | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_lines[3], error_prefix) != | 
					
						
							|  |  |  |         -1)) == 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-11-13 09:38:53 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   result = isect_line_line_v3(UNPACK4(lines), i1, i2); | 
					
						
							| 
									
										
										
										
											2019-06-12 09:04:10 +10:00
										 |  |  |   /* The return-code isn't exposed,
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |    * this way we can check know how close the lines are. */ | 
					
						
							|  |  |  |   if (result == 1) { | 
					
						
							|  |  |  |     closest_to_line_v3(i2, i1, lines[2], lines[3]); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (result == 0) { | 
					
						
							| 
									
										
										
										
											2021-08-12 14:34:43 +10:00
										 |  |  |     /* Collinear. */ | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11: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
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   tuple = PyTuple_New(2); | 
					
						
							|  |  |  |   PyTuple_SET_ITEMS( | 
					
						
							|  |  |  |       tuple, Vector_CreatePyObject(i1, len, NULL), Vector_CreatePyObject(i2, len, NULL)); | 
					
						
							|  |  |  |   return tuple; | 
					
						
							| 
									
										
										
											
												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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  | /* Line-Line intersection using algorithm from mathworld.wolfram.com */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     M_Geometry_intersect_sphere_sphere_2d_doc, | 
					
						
							|  |  |  |     ".. function:: intersect_sphere_sphere_2d(p_a, radius_a, p_b, radius_b)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Returns 2 points on between intersecting circles.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg p_a: Center of the first circle\n" | 
					
						
							|  |  |  |     "   :type p_a: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg radius_a: Radius of the first circle\n" | 
					
						
							|  |  |  |     "   :type radius_a: float\n" | 
					
						
							|  |  |  |     "   :arg p_b: Center of the second circle\n" | 
					
						
							|  |  |  |     "   :type p_b: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg radius_b: Radius of the second circle\n" | 
					
						
							|  |  |  |     "   :type radius_b: float\n" | 
					
						
							|  |  |  |     "   :rtype: tuple of :class:`mathutils.Vector`'s or None when there is no intersection\n"); | 
					
						
							|  |  |  | static PyObject *M_Geometry_intersect_sphere_sphere_2d(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "intersect_sphere_sphere_2d"; | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |   PyObject *ret; | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   PyObject *py_v_a, *py_v_b; | 
					
						
							|  |  |  |   float v_a[2], v_b[2]; | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |   float rad_a, rad_b; | 
					
						
							|  |  |  |   float v_ab[2]; | 
					
						
							|  |  |  |   float dist; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple( | 
					
						
							|  |  |  |           args, "OfOf:intersect_sphere_sphere_2d", &py_v_a, &rad_a, &py_v_b, &rad_b)) { | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (((mathutils_array_parse(v_a, 2, 2, py_v_a, error_prefix) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(v_b, 2, 2, py_v_b, error_prefix) != -1)) == 0) { | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |   ret = PyTuple_New(2); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |   sub_v2_v2v2(v_ab, v_b, v_a); | 
					
						
							|  |  |  |   dist = len_v2(v_ab); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |   if (/* out of range */ | 
					
						
							|  |  |  |       (dist > rad_a + rad_b) || | 
					
						
							|  |  |  |       /* fully-contained in the other */ | 
					
						
							| 
									
										
										
										
											2014-01-09 03:07:17 +11:00
										 |  |  |       (dist < fabsf(rad_a - rad_b)) || | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |       /* co-incident */ | 
					
						
							|  |  |  |       (dist < FLT_EPSILON)) { | 
					
						
							|  |  |  |     /* out of range */ | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  |     PyTuple_SET_ITEMS(ret, Py_INCREF_RET(Py_None), Py_INCREF_RET(Py_None)); | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     const float dist_delta = ((rad_a * rad_a) - (rad_b * rad_b) + (dist * dist)) / (2.0f * dist); | 
					
						
							|  |  |  |     const float h = powf(fabsf((rad_a * rad_a) - (dist_delta * dist_delta)), 0.5f); | 
					
						
							|  |  |  |     float i_cent[2]; | 
					
						
							|  |  |  |     float i1[2], i2[2]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |     i_cent[0] = v_a[0] + ((v_ab[0] * dist_delta) / dist); | 
					
						
							|  |  |  |     i_cent[1] = v_a[1] + ((v_ab[1] * dist_delta) / dist); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |     i1[0] = i_cent[0] + h * v_ab[1] / dist; | 
					
						
							|  |  |  |     i1[1] = i_cent[1] - h * v_ab[0] / dist; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |     i2[0] = i_cent[0] - h * v_ab[1] / dist; | 
					
						
							|  |  |  |     i2[1] = i_cent[1] + h * v_ab[0] / dist; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  |     PyTuple_SET_ITEMS(ret, Vector_CreatePyObject(i1, 2, NULL), Vector_CreatePyObject(i2, 2, NULL)); | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-10 05:34:30 +10:00
										 |  |  | PyDoc_STRVAR(M_Geometry_intersect_tri_tri_2d_doc, | 
					
						
							|  |  |  |              ".. function:: intersect_tri_tri_2d(tri_a1, tri_a2, tri_a3, tri_b1, tri_b2, tri_b3)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Check if two 2D triangles intersect.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :rtype: bool\n"); | 
					
						
							|  |  |  | static PyObject *M_Geometry_intersect_tri_tri_2d(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const char *error_prefix = "intersect_tri_tri_2d"; | 
					
						
							|  |  |  |   PyObject *tri_pair_py[2][3]; | 
					
						
							|  |  |  |   float tri_pair[2][3][2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, | 
					
						
							|  |  |  |                         "OOOOOO:intersect_tri_tri_2d", | 
					
						
							|  |  |  |                         &tri_pair_py[0][0], | 
					
						
							|  |  |  |                         &tri_pair_py[0][1], | 
					
						
							|  |  |  |                         &tri_pair_py[0][2], | 
					
						
							|  |  |  |                         &tri_pair_py[1][0], | 
					
						
							|  |  |  |                         &tri_pair_py[1][1], | 
					
						
							|  |  |  |                         &tri_pair_py[1][2])) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (int i = 0; i < 2; i++) { | 
					
						
							|  |  |  |     for (int j = 0; j < 3; j++) { | 
					
						
							|  |  |  |       if (mathutils_array_parse( | 
					
						
							|  |  |  |               tri_pair[i][j], 2, 2 | MU_ARRAY_SPILL, tri_pair_py[i][j], error_prefix) == -1) { | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-20 16:10:13 +10:00
										 |  |  |   const bool ret = isect_tri_tri_v2(UNPACK3(tri_pair[0]), UNPACK3(tri_pair[1])); | 
					
						
							| 
									
										
										
										
											2019-08-10 05:34:30 +10:00
										 |  |  |   return PyBool_FromLong(ret); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(M_Geometry_normal_doc, | 
					
						
							| 
									
										
										
										
											2014-12-30 22:47:56 +11:00
										 |  |  |              ".. function:: normal(vectors)\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2014-12-30 22:47:56 +11:00
										 |  |  |              "   Returns the normal of a 3D polygon.\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2014-12-30 22:47:56 +11:00
										 |  |  |              "   :arg vectors: Vectors to calculate normals with\n" | 
					
						
							|  |  |  |              "   :type vectors: sequence of 3 or more 3d vector\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              "   :rtype: :class:`mathutils.Vector`\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_normal(PyObject *UNUSED(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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 22:47:56 +11:00
										 |  |  |   float(*coords)[3]; | 
					
						
							|  |  |  |   int coords_len; | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |   float n[3]; | 
					
						
							| 
									
										
										
										
											2014-12-30 22:47:56 +11:00
										 |  |  |   PyObject *ret = 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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 22:47:56 +11:00
										 |  |  |   /* use */ | 
					
						
							|  |  |  |   if (PyTuple_GET_SIZE(args) == 1) { | 
					
						
							|  |  |  |     args = PyTuple_GET_ITEM(args, 0); | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 22:47:56 +11:00
										 |  |  |   if ((coords_len = mathutils_array_parse_alloc_v( | 
					
						
							|  |  |  |            (float **)&coords, 3 | MU_ARRAY_SPILL, args, "normal")) == -1) { | 
					
						
							|  |  |  |     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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 22:47:56 +11:00
										 |  |  |   if (coords_len < 3) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_ValueError, "Expected 3 or more vectors"); | 
					
						
							|  |  |  |     goto finally; | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-08 00:11:05 +10:00
										 |  |  |   normal_poly_v3(n, coords, coords_len); | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   ret = Vector_CreatePyObject(n, 3, NULL); | 
					
						
							| 
									
										
										
										
											2014-12-30 22:47:56 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | finally: | 
					
						
							|  |  |  |   PyMem_Free(coords); | 
					
						
							|  |  |  |   return ret; | 
					
						
							| 
									
										
										
											
												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
										 |  |  | /* --------------------------------- AREA FUNCTIONS-------------------- */ | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(M_Geometry_area_tri_doc, | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              ".. function:: area_tri(v1, v2, v3)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Returns the area size of the 2D or 3D triangle defined.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg v1: Point1\n" | 
					
						
							|  |  |  |              "   :type v1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg v2: Point2\n" | 
					
						
							|  |  |  |              "   :type v2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg v3: Point3\n" | 
					
						
							|  |  |  |              "   :type v3: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :rtype: float\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_area_tri(PyObject *UNUSED(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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "area_tri"; | 
					
						
							|  |  |  |   PyObject *py_tri[3]; | 
					
						
							|  |  |  |   float tri[3][3]; | 
					
						
							|  |  |  |   int len; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "OOO:area_tri", UNPACK3_EX(&, py_tri, ))) { | 
					
						
							| 
									
										
										
											
												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-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if ((((len = mathutils_array_parse(tri[0], 2, 3, py_tri[0], error_prefix)) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(tri[1], len, len, py_tri[1], error_prefix) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(tri[2], len, len, py_tri[2], error_prefix) != -1)) == 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-11-13 09:38:53 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   return PyFloat_FromDouble((len == 3 ? area_tri_v3 : area_tri_v2)(UNPACK3(tri))); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-21 13:24:45 +00:00
										 |  |  | PyDoc_STRVAR(M_Geometry_volume_tetrahedron_doc, | 
					
						
							|  |  |  |              ".. function:: volume_tetrahedron(v1, v2, v3, v4)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return the volume formed by a tetrahedron (points can be in any order).\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg v1: Point1\n" | 
					
						
							|  |  |  |              "   :type v1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg v2: Point2\n" | 
					
						
							|  |  |  |              "   :type v2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg v3: Point3\n" | 
					
						
							|  |  |  |              "   :type v3: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg v4: Point4\n" | 
					
						
							|  |  |  |              "   :type v4: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :rtype: float\n"); | 
					
						
							|  |  |  | static PyObject *M_Geometry_volume_tetrahedron(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "volume_tetrahedron"; | 
					
						
							|  |  |  |   PyObject *py_tet[4]; | 
					
						
							|  |  |  |   float tet[4][3]; | 
					
						
							|  |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "OOOO:volume_tetrahedron", UNPACK4_EX(&, py_tet, ))) { | 
					
						
							| 
									
										
										
										
											2013-04-21 13:24:45 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   for (i = 0; i < ARRAY_SIZE(tet); i++) { | 
					
						
							|  |  |  |     if (mathutils_array_parse(tet[i], 3, 3 | MU_ARRAY_SPILL, py_tet[i], error_prefix) == -1) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-04-21 13:24:45 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   return PyFloat_FromDouble(volume_tetrahedron_v3(UNPACK4(tet))); | 
					
						
							| 
									
										
										
										
											2013-04-21 13:24:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     M_Geometry_intersect_line_line_2d_doc, | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |     ".. function:: intersect_line_line_2d(lineA_p1, lineA_p2, lineB_p1, lineB_p2)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2015-10-13 09:59:42 +02:00
										 |  |  |     "   Takes 2 segments (defined by 4 vectors) and returns a vector for their point of " | 
					
						
							|  |  |  |     "intersection or None.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2016-01-25 20:25:56 +11:00
										 |  |  |     "   .. warning:: Despite its name, this function works on segments, and not on lines.\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg lineA_p1: First point of the first line\n" | 
					
						
							|  |  |  |     "   :type lineA_p1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg lineA_p2: Second point of the first line\n" | 
					
						
							|  |  |  |     "   :type lineA_p2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg lineB_p1: First point of the second line\n" | 
					
						
							|  |  |  |     "   :type lineB_p1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg lineB_p2: Second point of the second line\n" | 
					
						
							|  |  |  |     "   :type lineB_p2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :return: The point of intersection or None when not found\n" | 
					
						
							|  |  |  |     "   :rtype: :class:`mathutils.Vector` or None\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_intersect_line_line_2d(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "intersect_line_line_2d"; | 
					
						
							|  |  |  |   PyObject *py_lines[4]; | 
					
						
							|  |  |  |   float lines[4][2]; | 
					
						
							| 
									
										
										
										
											2010-12-11 21:27:39 +00:00
										 |  |  |   float vi[2]; | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "OOOO:intersect_line_line_2d", UNPACK4_EX(&, py_lines, ))) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   for (i = 0; i < ARRAY_SIZE(lines); i++) { | 
					
						
							|  |  |  |     if (mathutils_array_parse(lines[i], 2, 2 | MU_ARRAY_SPILL, py_lines[i], error_prefix) == -1) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (isect_seg_seg_v2_point(UNPACK4(lines), vi) == 1) { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     return Vector_CreatePyObject(vi, 2, NULL); | 
					
						
							| 
									
										
										
										
											2011-03-19 11:12:48 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     M_Geometry_intersect_line_plane_doc, | 
					
						
							| 
									
										
										
										
											2011-05-19 04:28:09 +00:00
										 |  |  |     ".. function:: intersect_line_plane(line_a, line_b, plane_co, plane_no, no_flip=False)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2012-04-22 08:36:39 +00:00
										 |  |  |     "   Calculate the intersection between a line (as 2 vectors) and a plane.\n" | 
					
						
							|  |  |  |     "   Returns a vector for the intersection or None.\n" | 
					
						
							| 
									
										
										
										
											2011-05-19 04:28:09 +00:00
										 |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg line_a: First point of the first line\n" | 
					
						
							|  |  |  |     "   :type line_a: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg line_b: Second point of the first line\n" | 
					
						
							|  |  |  |     "   :type line_b: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg plane_co: A point on the plane\n" | 
					
						
							|  |  |  |     "   :type plane_co: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg plane_no: The direction the plane is facing\n" | 
					
						
							|  |  |  |     "   :type plane_no: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :return: The point of intersection or None when not found\n" | 
					
						
							|  |  |  |     "   :rtype: :class:`mathutils.Vector` or None\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_intersect_line_plane(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2011-05-19 04:28:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "intersect_line_plane"; | 
					
						
							|  |  |  |   PyObject *py_line_a, *py_line_b, *py_plane_co, *py_plane_no; | 
					
						
							|  |  |  |   float line_a[3], line_b[3], plane_co[3], plane_no[3]; | 
					
						
							| 
									
										
										
										
											2011-05-19 04:28:09 +00:00
										 |  |  |   float isect[3]; | 
					
						
							| 
									
										
										
										
											2020-08-20 16:10:13 +10:00
										 |  |  |   const bool no_flip = false; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, | 
					
						
							| 
									
										
										
										
											2015-08-04 18:34:20 +10:00
										 |  |  |                         "OOOO|O&:intersect_line_plane", | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |                         &py_line_a, | 
					
						
							|  |  |  |                         &py_line_b, | 
					
						
							|  |  |  |                         &py_plane_co, | 
					
						
							|  |  |  |                         &py_plane_no, | 
					
						
							| 
									
										
										
										
											2015-08-04 18:34:20 +10:00
										 |  |  |                         PyC_ParseBool, | 
					
						
							|  |  |  |                         &no_flip)) { | 
					
						
							| 
									
										
										
										
											2011-05-19 04:28:09 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (((mathutils_array_parse(line_a, 3, 3 | MU_ARRAY_SPILL, py_line_a, error_prefix) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(line_b, 3, 3 | MU_ARRAY_SPILL, py_line_b, error_prefix) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(plane_co, 3, 3 | MU_ARRAY_SPILL, py_plane_co, error_prefix) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(plane_no, 3, 3 | MU_ARRAY_SPILL, py_plane_no, error_prefix) != | 
					
						
							|  |  |  |         -1)) == 0) { | 
					
						
							| 
									
										
										
										
											2011-05-19 04:28:09 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-11 10:31:58 +01:00
										 |  |  |   /* TODO: implements no_flip */ | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (isect_line_plane_v3(isect, line_a, line_b, plane_co, plane_no) == 1) { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     return Vector_CreatePyObject(isect, 3, NULL); | 
					
						
							| 
									
										
										
										
											2011-05-19 04:28:09 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2011-05-19 04:28:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-20 05:56:21 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     M_Geometry_intersect_plane_plane_doc, | 
					
						
							|  |  |  |     ".. function:: intersect_plane_plane(plane_a_co, plane_a_no, plane_b_co, plane_b_no)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Return the intersection between two planes\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg plane_a_co: Point on the first plane\n" | 
					
						
							|  |  |  |     "   :type plane_a_co: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg plane_a_no: Normal of the first plane\n" | 
					
						
							|  |  |  |     "   :type plane_a_no: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg plane_b_co: Point on the second plane\n" | 
					
						
							|  |  |  |     "   :type plane_b_co: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg plane_b_no: Normal of the second plane\n" | 
					
						
							|  |  |  |     "   :type plane_b_no: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :return: The line of the intersection represented as a point and a vector\n" | 
					
						
							| 
									
										
										
										
											2013-12-29 12:51:27 +11:00
										 |  |  |     "   :rtype: tuple pair of :class:`mathutils.Vector` or None if the intersection can't be " | 
					
						
							|  |  |  |     "calculated\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_intersect_plane_plane(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2011-11-20 05:56:21 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "intersect_plane_plane"; | 
					
						
							| 
									
										
										
										
											2013-12-29 12:51:27 +11:00
										 |  |  |   PyObject *ret, *ret_co, *ret_no; | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   PyObject *py_plane_a_co, *py_plane_a_no, *py_plane_b_co, *py_plane_b_no; | 
					
						
							|  |  |  |   float plane_a_co[3], plane_a_no[3], plane_b_co[3], plane_b_no[3]; | 
					
						
							| 
									
										
										
										
											2015-09-04 22:04:54 +10:00
										 |  |  |   float plane_a[4], plane_b[4]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-20 05:56:21 +00:00
										 |  |  |   float isect_co[3]; | 
					
						
							|  |  |  |   float isect_no[3]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, | 
					
						
							|  |  |  |                         "OOOO:intersect_plane_plane", | 
					
						
							| 
									
										
										
										
											2015-01-06 18:32:54 +11:00
										 |  |  |                         &py_plane_a_co, | 
					
						
							|  |  |  |                         &py_plane_a_no, | 
					
						
							|  |  |  |                         &py_plane_b_co, | 
					
						
							|  |  |  |                         &py_plane_b_no)) { | 
					
						
							| 
									
										
										
										
											2011-11-20 05:56:21 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (((mathutils_array_parse(plane_a_co, 3, 3 | MU_ARRAY_SPILL, py_plane_a_co, error_prefix) != | 
					
						
							|  |  |  |         -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(plane_a_no, 3, 3 | MU_ARRAY_SPILL, py_plane_a_no, error_prefix) != | 
					
						
							|  |  |  |         -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(plane_b_co, 3, 3 | MU_ARRAY_SPILL, py_plane_b_co, error_prefix) != | 
					
						
							|  |  |  |         -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(plane_b_no, 3, 3 | MU_ARRAY_SPILL, py_plane_b_no, error_prefix) != | 
					
						
							|  |  |  |         -1)) == 0) { | 
					
						
							| 
									
										
										
										
											2011-11-20 05:56:21 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 22:04:54 +10:00
										 |  |  |   plane_from_point_normal_v3(plane_a, plane_a_co, plane_a_no); | 
					
						
							|  |  |  |   plane_from_point_normal_v3(plane_b, plane_b_co, plane_b_no); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 22:04:54 +10:00
										 |  |  |   if (isect_plane_plane_v3(plane_a, plane_b, isect_co, isect_no)) { | 
					
						
							| 
									
										
										
										
											2013-12-29 12:51:27 +11:00
										 |  |  |     normalize_v3(isect_no); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     ret_co = Vector_CreatePyObject(isect_co, 3, NULL); | 
					
						
							|  |  |  |     ret_no = Vector_CreatePyObject(isect_no, 3, NULL); | 
					
						
							| 
									
										
										
										
											2013-12-29 12:51:27 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  |     ret_co = Py_INCREF_RET(Py_None); | 
					
						
							|  |  |  |     ret_no = Py_INCREF_RET(Py_None); | 
					
						
							| 
									
										
										
										
											2013-12-29 12:51:27 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   ret = PyTuple_New(2); | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  |   PyTuple_SET_ITEMS(ret, ret_co, ret_no); | 
					
						
							| 
									
										
										
										
											2011-11-20 05:56:21 +00:00
										 |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-06-26 07:21:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     M_Geometry_intersect_line_sphere_doc, | 
					
						
							| 
									
										
										
										
											2011-06-26 08:07:09 +00:00
										 |  |  |     ".. function:: intersect_line_sphere(line_a, line_b, sphere_co, sphere_radius, clip=True)\n" | 
					
						
							| 
									
										
										
										
											2011-06-26 07:21:19 +00:00
										 |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  |     "   Takes a line (as 2 points) and a sphere (as a point and a radius) and\n" | 
					
						
							| 
									
										
										
										
											2011-06-26 07:21:19 +00:00
										 |  |  |     "   returns the intersection\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  |     "   :arg line_a: First point of the line\n" | 
					
						
							| 
									
										
										
										
											2011-06-26 07:21:19 +00:00
										 |  |  |     "   :type line_a: :class:`mathutils.Vector`\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  |     "   :arg line_b: Second point of the line\n" | 
					
						
							| 
									
										
										
										
											2011-06-26 07:21:19 +00:00
										 |  |  |     "   :type line_b: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg sphere_co: The center of the sphere\n" | 
					
						
							|  |  |  |     "   :type sphere_co: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg sphere_radius: Radius of the sphere\n" | 
					
						
							|  |  |  |     "   :type sphere_radius: sphere_radius\n" | 
					
						
							|  |  |  |     "   :return: The intersection points as a pair of vectors or None when there is no " | 
					
						
							|  |  |  |     "intersection\n" | 
					
						
							|  |  |  |     "   :rtype: A tuple pair containing :class:`mathutils.Vector` or None\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2011-06-26 07:21:19 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "intersect_line_sphere"; | 
					
						
							|  |  |  |   PyObject *py_line_a, *py_line_b, *py_sphere_co; | 
					
						
							|  |  |  |   float line_a[3], line_b[3], sphere_co[3]; | 
					
						
							| 
									
										
										
										
											2011-06-26 07:21:19 +00:00
										 |  |  |   float sphere_radius; | 
					
						
							| 
									
										
										
										
											2015-08-04 18:34:20 +10:00
										 |  |  |   bool clip = true; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-26 07:21:19 +00:00
										 |  |  |   float isect_a[3]; | 
					
						
							|  |  |  |   float isect_b[3]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, | 
					
						
							| 
									
										
										
										
											2015-08-04 18:34:20 +10:00
										 |  |  |                         "OOOf|O&:intersect_line_sphere", | 
					
						
							|  |  |  |                         &py_line_a, | 
					
						
							|  |  |  |                         &py_line_b, | 
					
						
							|  |  |  |                         &py_sphere_co, | 
					
						
							|  |  |  |                         &sphere_radius, | 
					
						
							|  |  |  |                         PyC_ParseBool, | 
					
						
							|  |  |  |                         &clip)) { | 
					
						
							| 
									
										
										
										
											2011-06-26 07:21:19 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (((mathutils_array_parse(line_a, 3, 3 | MU_ARRAY_SPILL, py_line_a, error_prefix) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(line_b, 3, 3 | MU_ARRAY_SPILL, py_line_b, error_prefix) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(sphere_co, 3, 3 | MU_ARRAY_SPILL, py_sphere_co, error_prefix) != | 
					
						
							|  |  |  |         -1)) == 0) { | 
					
						
							| 
									
										
										
										
											2011-06-26 07:21:19 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   bool use_a = true; | 
					
						
							|  |  |  |   bool use_b = true; | 
					
						
							|  |  |  |   float lambda; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   PyObject *ret = PyTuple_New(2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   switch (isect_line_sphere_v3(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) { | 
					
						
							|  |  |  |     case 1: | 
					
						
							|  |  |  |       if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && | 
					
						
							|  |  |  |                       (lambda <= 1.0f)))) { | 
					
						
							| 
									
										
										
										
											2013-07-21 08:16:37 +00:00
										 |  |  |         use_a = false; | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |       use_b = false; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case 2: | 
					
						
							|  |  |  |       if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && | 
					
						
							|  |  |  |                       (lambda <= 1.0f)))) { | 
					
						
							|  |  |  |         use_a = false; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (!(!clip || (((lambda = line_point_factor_v3(isect_b, line_a, line_b)) >= 0.0f) && | 
					
						
							|  |  |  |                       (lambda <= 1.0f)))) { | 
					
						
							| 
									
										
										
										
											2013-07-21 08:16:37 +00:00
										 |  |  |         use_b = false; | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       use_a = false; | 
					
						
							|  |  |  |       use_b = false; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   PyTuple_SET_ITEMS(ret, | 
					
						
							|  |  |  |                     use_a ? Vector_CreatePyObject(isect_a, 3, NULL) : Py_INCREF_RET(Py_None), | 
					
						
							|  |  |  |                     use_b ? Vector_CreatePyObject(isect_b, 3, NULL) : Py_INCREF_RET(Py_None)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   return ret; | 
					
						
							| 
									
										
										
										
											2011-06-26 07:21:19 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-26 17:16:06 +00:00
										 |  |  | /* keep in sync with M_Geometry_intersect_line_sphere */ | 
					
						
							| 
									
										
										
										
											2011-06-26 11:08:12 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     M_Geometry_intersect_line_sphere_2d_doc, | 
					
						
							|  |  |  |     ".. function:: intersect_line_sphere_2d(line_a, line_b, sphere_co, sphere_radius, clip=True)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  |     "   Takes a line (as 2 points) and a sphere (as a point and a radius) and\n" | 
					
						
							| 
									
										
										
										
											2011-06-26 11:08:12 +00:00
										 |  |  |     "   returns the intersection\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  |     "   :arg line_a: First point of the line\n" | 
					
						
							| 
									
										
										
										
											2011-06-26 11:08:12 +00:00
										 |  |  |     "   :type line_a: :class:`mathutils.Vector`\n" | 
					
						
							| 
									
										
										
										
											2014-12-19 00:42:50 +09:00
										 |  |  |     "   :arg line_b: Second point of the line\n" | 
					
						
							| 
									
										
										
										
											2011-06-26 11:08:12 +00:00
										 |  |  |     "   :type line_b: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg sphere_co: The center of the sphere\n" | 
					
						
							|  |  |  |     "   :type sphere_co: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg sphere_radius: Radius of the sphere\n" | 
					
						
							|  |  |  |     "   :type sphere_radius: sphere_radius\n" | 
					
						
							|  |  |  |     "   :return: The intersection points as a pair of vectors or None when there is no " | 
					
						
							|  |  |  |     "intersection\n" | 
					
						
							|  |  |  |     "   :rtype: A tuple pair containing :class:`mathutils.Vector` or None\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2011-06-26 11:08:12 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "intersect_line_sphere_2d"; | 
					
						
							|  |  |  |   PyObject *py_line_a, *py_line_b, *py_sphere_co; | 
					
						
							|  |  |  |   float line_a[2], line_b[2], sphere_co[2]; | 
					
						
							| 
									
										
										
										
											2011-06-26 11:08:12 +00:00
										 |  |  |   float sphere_radius; | 
					
						
							| 
									
										
										
										
											2015-08-04 18:34:20 +10:00
										 |  |  |   bool clip = true; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-14 11:57:35 +00:00
										 |  |  |   float isect_a[2]; | 
					
						
							|  |  |  |   float isect_b[2]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, | 
					
						
							| 
									
										
										
										
											2015-08-04 18:34:20 +10:00
										 |  |  |                         "OOOf|O&:intersect_line_sphere_2d", | 
					
						
							|  |  |  |                         &py_line_a, | 
					
						
							|  |  |  |                         &py_line_b, | 
					
						
							|  |  |  |                         &py_sphere_co, | 
					
						
							|  |  |  |                         &sphere_radius, | 
					
						
							|  |  |  |                         PyC_ParseBool, | 
					
						
							|  |  |  |                         &clip)) { | 
					
						
							| 
									
										
										
										
											2011-06-26 11:08:12 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (((mathutils_array_parse(line_a, 2, 2 | MU_ARRAY_SPILL, py_line_a, error_prefix) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(line_b, 2, 2 | MU_ARRAY_SPILL, py_line_b, error_prefix) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(sphere_co, 2, 2 | MU_ARRAY_SPILL, py_sphere_co, error_prefix) != | 
					
						
							|  |  |  |         -1)) == 0) { | 
					
						
							| 
									
										
										
										
											2011-06-26 11:08:12 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   bool use_a = true; | 
					
						
							|  |  |  |   bool use_b = true; | 
					
						
							|  |  |  |   float lambda; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   PyObject *ret = PyTuple_New(2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   switch (isect_line_sphere_v2(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) { | 
					
						
							|  |  |  |     case 1: | 
					
						
							|  |  |  |       if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && | 
					
						
							|  |  |  |                       (lambda <= 1.0f)))) { | 
					
						
							|  |  |  |         use_a = false; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       use_b = false; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case 2: | 
					
						
							|  |  |  |       if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && | 
					
						
							|  |  |  |                       (lambda <= 1.0f)))) { | 
					
						
							| 
									
										
										
										
											2013-04-14 11:57:35 +00:00
										 |  |  |         use_a = false; | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |       if (!(!clip || (((lambda = line_point_factor_v2(isect_b, line_a, line_b)) >= 0.0f) && | 
					
						
							|  |  |  |                       (lambda <= 1.0f)))) { | 
					
						
							| 
									
										
										
										
											2013-04-14 11:57:35 +00:00
										 |  |  |         use_b = false; | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       use_a = false; | 
					
						
							|  |  |  |       use_b = false; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   PyTuple_SET_ITEMS(ret, | 
					
						
							|  |  |  |                     use_a ? Vector_CreatePyObject(isect_a, 2, NULL) : Py_INCREF_RET(Py_None), | 
					
						
							|  |  |  |                     use_b ? Vector_CreatePyObject(isect_b, 2, NULL) : Py_INCREF_RET(Py_None)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   return ret; | 
					
						
							| 
									
										
										
										
											2011-06-26 11:08:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     M_Geometry_intersect_point_line_doc, | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |     ".. function:: intersect_point_line(pt, line_p1, line_p2)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Takes a point and a line and returns a tuple with the closest point on the line and its " | 
					
						
							|  |  |  |     "distance from the first point of the line as a percentage of the length of the line.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg pt: Point\n" | 
					
						
							|  |  |  |     "   :type pt: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg line_p1: First point of the line\n" | 
					
						
							|  |  |  |     "   :type line_p1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg line_p1: Second point of the line\n" | 
					
						
							|  |  |  |     "   :type line_p1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :rtype: (:class:`mathutils.Vector`, float)\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "intersect_point_line"; | 
					
						
							|  |  |  |   PyObject *py_pt, *py_line_a, *py_line_b; | 
					
						
							|  |  |  |   float pt[3], pt_out[3], line_a[3], line_b[3]; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   float lambda; | 
					
						
							|  |  |  |   PyObject *ret; | 
					
						
							| 
									
										
										
										
											2012-08-28 11:27:46 +00:00
										 |  |  |   int size = 2; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "OOO:intersect_point_line", &py_pt, &py_line_a, &py_line_b)) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   /* accept 2d verts */ | 
					
						
							| 
									
										
										
										
											2015-01-04 10:11:21 +01:00
										 |  |  |   if ((((size = mathutils_array_parse( | 
					
						
							|  |  |  |              pt, 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_pt, error_prefix)) != -1) && | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |        (mathutils_array_parse( | 
					
						
							|  |  |  |             line_a, 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_line_a, error_prefix) != -1) && | 
					
						
							| 
									
										
										
										
											2015-01-29 18:09:55 +01:00
										 |  |  |        (mathutils_array_parse( | 
					
						
							|  |  |  |             line_b, 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_line_b, error_prefix) != -1)) == 0) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2011-11-13 09:38:53 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   /* do the calculation */ | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   lambda = closest_to_line_v3(pt_out, pt, line_a, line_b); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   ret = PyTuple_New(2); | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  |   PyTuple_SET_ITEMS(ret, Vector_CreatePyObject(pt_out, size, NULL), PyFloat_FromDouble(lambda)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-21 16:58:17 +10:00
										 |  |  | PyDoc_STRVAR(M_Geometry_intersect_point_tri_doc, | 
					
						
							|  |  |  |              ".. function:: intersect_point_tri(pt, tri_p1, tri_p2, tri_p3)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2019-11-06 11:13:41 +03:00
										 |  |  |              "   Takes 4 vectors: one is the point and the next 3 define the triangle. Projects " | 
					
						
							|  |  |  |              "the point onto the triangle plane and checks if it is within the triangle.\n" | 
					
						
							| 
									
										
										
										
											2014-07-21 16:58:17 +10:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg pt: Point\n" | 
					
						
							|  |  |  |              "   :type pt: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg tri_p1: First point of the triangle\n" | 
					
						
							|  |  |  |              "   :type tri_p1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg tri_p2: Second point of the triangle\n" | 
					
						
							|  |  |  |              "   :type tri_p2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg tri_p3: Third point of the triangle\n" | 
					
						
							|  |  |  |              "   :type tri_p3: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :return: Point on the triangles plane or None if its outside the triangle\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`mathutils.Vector` or None\n"); | 
					
						
							|  |  |  | static PyObject *M_Geometry_intersect_point_tri(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "intersect_point_tri"; | 
					
						
							|  |  |  |   PyObject *py_pt, *py_tri[3]; | 
					
						
							|  |  |  |   float pt[3], tri[3][3]; | 
					
						
							| 
									
										
										
										
											2014-07-21 16:58:17 +10:00
										 |  |  |   float vi[3]; | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 19:18:57 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "OOOO:intersect_point_tri", &py_pt, UNPACK3_EX(&, py_tri, ))) { | 
					
						
							| 
									
										
										
										
											2014-07-21 16:58:17 +10:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 18:09:55 +01:00
										 |  |  |   if (mathutils_array_parse(pt, 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_pt, error_prefix) == | 
					
						
							|  |  |  |       -1) { | 
					
						
							| 
									
										
										
										
											2014-07-21 16:58:17 +10:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   for (i = 0; i < ARRAY_SIZE(tri); i++) { | 
					
						
							| 
									
										
										
										
											2015-01-29 18:09:55 +01:00
										 |  |  |     if (mathutils_array_parse( | 
					
						
							|  |  |  |             tri[i], 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_tri[i], error_prefix) == -1) { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-07-21 16:58:17 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (isect_point_tri_v3(pt, UNPACK3(tri), vi)) { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     return Vector_CreatePyObject(vi, 3, NULL); | 
					
						
							| 
									
										
										
										
											2014-07-21 16:58:17 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2014-07-21 16:58:17 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 11:13:41 +03:00
										 |  |  | PyDoc_STRVAR(M_Geometry_closest_point_on_tri_doc, | 
					
						
							|  |  |  |              ".. function:: closest_point_on_tri(pt, tri_p1, tri_p2, tri_p3)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Takes 4 vectors: one is the point and the next 3 define the triangle.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg pt: Point\n" | 
					
						
							|  |  |  |              "   :type pt: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg tri_p1: First point of the triangle\n" | 
					
						
							|  |  |  |              "   :type tri_p1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg tri_p2: Second point of the triangle\n" | 
					
						
							|  |  |  |              "   :type tri_p2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg tri_p3: Third point of the triangle\n" | 
					
						
							|  |  |  |              "   :type tri_p3: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :return: The closest point of the triangle.\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`mathutils.Vector`\n"); | 
					
						
							|  |  |  | static PyObject *M_Geometry_closest_point_on_tri(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const char *error_prefix = "closest_point_on_tri"; | 
					
						
							|  |  |  |   PyObject *py_pt, *py_tri[3]; | 
					
						
							|  |  |  |   float pt[3], tri[3][3]; | 
					
						
							|  |  |  |   float vi[3]; | 
					
						
							|  |  |  |   int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "OOOO:closest_point_on_tri", &py_pt, UNPACK3_EX(&, py_tri, ))) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (mathutils_array_parse(pt, 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_pt, error_prefix) == | 
					
						
							|  |  |  |       -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   for (i = 0; i < ARRAY_SIZE(tri); i++) { | 
					
						
							|  |  |  |     if (mathutils_array_parse( | 
					
						
							|  |  |  |             tri[i], 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_tri[i], error_prefix) == -1) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   closest_on_tri_to_point_v3(vi, pt, UNPACK3(tri)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return Vector_CreatePyObject(vi, 3, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     M_Geometry_intersect_point_tri_2d_doc, | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |     ".. function:: intersect_point_tri_2d(pt, tri_p1, tri_p2, tri_p3)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Takes 4 vectors (using only the x and y coordinates): one is the point and the next 3 " | 
					
						
							|  |  |  |     "define the triangle. Returns 1 if the point is within the triangle, otherwise 0.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg pt: Point\n" | 
					
						
							| 
									
										
										
										
											2014-07-21 16:58:17 +10:00
										 |  |  |     "   :type pt: :class:`mathutils.Vector`\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |     "   :arg tri_p1: First point of the triangle\n" | 
					
						
							|  |  |  |     "   :type tri_p1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg tri_p2: Second point of the triangle\n" | 
					
						
							|  |  |  |     "   :type tri_p2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg tri_p3: Third point of the triangle\n" | 
					
						
							|  |  |  |     "   :type tri_p3: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :rtype: int\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_intersect_point_tri_2d(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "intersect_point_tri_2d"; | 
					
						
							|  |  |  |   PyObject *py_pt, *py_tri[3]; | 
					
						
							|  |  |  |   float pt[2], tri[3][2]; | 
					
						
							|  |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "OOOO:intersect_point_tri_2d", &py_pt, UNPACK3_EX(&, py_tri, ))) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (mathutils_array_parse(pt, 2, 2 | MU_ARRAY_SPILL, py_pt, error_prefix) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2011-11-13 09:38:53 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   for (i = 0; i < ARRAY_SIZE(tri); i++) { | 
					
						
							|  |  |  |     if (mathutils_array_parse(tri[i], 2, 2 | MU_ARRAY_SPILL, py_tri[i], error_prefix) == -1) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   return PyLong_FromLong(isect_point_tri_v2(pt, UNPACK3(tri))); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 16:05:51 +00:00
										 |  |  | PyDoc_STRVAR(M_Geometry_intersect_point_quad_2d_doc, | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              ".. function:: intersect_point_quad_2d(pt, quad_p1, quad_p2, quad_p3, quad_p4)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2018-11-14 09:04:24 +11:00
										 |  |  |              "   Takes 5 vectors (using only the x and y coordinates): one is the point and the " | 
					
						
							|  |  |  |              "next 4 define the quad,\n" | 
					
						
							| 
									
										
										
										
											2011-12-17 00:52:36 +00:00
										 |  |  |              "   only the x and y are used from the vectors. Returns 1 if the point is within the " | 
					
						
							|  |  |  |              "quad, otherwise 0.\n" | 
					
						
							| 
									
										
										
										
											2015-03-08 16:47:30 +09:00
										 |  |  |              "   Works only with convex quads without singular edges.\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg pt: Point\n" | 
					
						
							| 
									
										
										
										
											2011-11-12 10:06:56 +00:00
										 |  |  |              "   :type pt: :class:`mathutils.Vector`\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              "   :arg quad_p1: First point of the quad\n" | 
					
						
							|  |  |  |              "   :type quad_p1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg quad_p2: Second point of the quad\n" | 
					
						
							|  |  |  |              "   :type quad_p2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg quad_p3: Third point of the quad\n" | 
					
						
							|  |  |  |              "   :type quad_p3: :class:`mathutils.Vector`\n" | 
					
						
							| 
									
										
										
										
											2016-01-28 00:30:50 -05:00
										 |  |  |              "   :arg quad_p4: Fourth point of the quad\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              "   :type quad_p4: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :rtype: int\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_intersect_point_quad_2d(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "intersect_point_quad_2d"; | 
					
						
							|  |  |  |   PyObject *py_pt, *py_quad[4]; | 
					
						
							|  |  |  |   float pt[2], quad[4][2]; | 
					
						
							|  |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "OOOOO:intersect_point_quad_2d", &py_pt, UNPACK4_EX(&, py_quad, ))) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (mathutils_array_parse(pt, 2, 2 | MU_ARRAY_SPILL, py_pt, error_prefix) == -1) { | 
					
						
							| 
									
										
										
										
											2009-06-22 04:26:48 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2011-11-13 09:38:53 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   for (i = 0; i < ARRAY_SIZE(quad); i++) { | 
					
						
							|  |  |  |     if (mathutils_array_parse(quad[i], 2, 2 | MU_ARRAY_SPILL, py_quad[i], error_prefix) == -1) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   return PyLong_FromLong(isect_point_quad_v2(pt, UNPACK4(quad))); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-12 10:06:56 +00:00
										 |  |  | PyDoc_STRVAR(M_Geometry_distance_point_to_plane_doc, | 
					
						
							|  |  |  |              ".. function:: distance_point_to_plane(pt, plane_co, plane_no)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Returns the signed distance between a point and a plane " | 
					
						
							|  |  |  |              "   (negative when below the normal).\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg pt: Point\n" | 
					
						
							|  |  |  |              "   :type pt: :class:`mathutils.Vector`\n" | 
					
						
							| 
									
										
										
										
											2013-12-10 00:02:37 +11:00
										 |  |  |              "   :arg plane_co: A point on the plane\n" | 
					
						
							| 
									
										
										
										
											2011-11-12 10:06:56 +00:00
										 |  |  |              "   :type plane_co: :class:`mathutils.Vector`\n" | 
					
						
							| 
									
										
										
										
											2013-12-10 00:02:37 +11:00
										 |  |  |              "   :arg plane_no: The direction the plane is facing\n" | 
					
						
							| 
									
										
										
										
											2011-11-12 10:06:56 +00:00
										 |  |  |              "   :type plane_no: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :rtype: float\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_distance_point_to_plane(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2011-11-12 10:06:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "distance_point_to_plane"; | 
					
						
							|  |  |  |   PyObject *py_pt, *py_plane_co, *py_plane_no; | 
					
						
							|  |  |  |   float pt[3], plane_co[3], plane_no[3]; | 
					
						
							| 
									
										
										
										
											2013-08-23 14:37:22 +00:00
										 |  |  |   float plane[4]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "OOO:distance_point_to_plane", &py_pt, &py_plane_co, &py_plane_no)) { | 
					
						
							| 
									
										
										
										
											2013-08-23 14:37:22 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (((mathutils_array_parse(pt, 3, 3 | MU_ARRAY_SPILL, py_pt, error_prefix) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(plane_co, 3, 3 | MU_ARRAY_SPILL, py_plane_co, error_prefix) != -1) && | 
					
						
							|  |  |  |        (mathutils_array_parse(plane_no, 3, 3 | MU_ARRAY_SPILL, py_plane_no, error_prefix) != | 
					
						
							|  |  |  |         -1)) == 0) { | 
					
						
							| 
									
										
										
										
											2011-11-12 10:06:56 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   plane_from_point_normal_v3(plane, plane_co, plane_no); | 
					
						
							|  |  |  |   return PyFloat_FromDouble(dist_signed_to_plane_v3(pt, plane)); | 
					
						
							| 
									
										
										
										
											2011-11-12 10:06:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     M_Geometry_barycentric_transform_doc, | 
					
						
							|  |  |  |     ".. function:: barycentric_transform(point, tri_a1, tri_a2, tri_a3, tri_b1, tri_b2, tri_b3)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Return a transformed point, the transformation is defined by 2 triangles.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg point: The point to transform.\n" | 
					
						
							|  |  |  |     "   :type point: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg tri_a1: source triangle vertex.\n" | 
					
						
							|  |  |  |     "   :type tri_a1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg tri_a2: source triangle vertex.\n" | 
					
						
							|  |  |  |     "   :type tri_a2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg tri_a3: source triangle vertex.\n" | 
					
						
							|  |  |  |     "   :type tri_a3: :class:`mathutils.Vector`\n" | 
					
						
							| 
									
										
										
										
											2018-03-19 08:19:48 +01:00
										 |  |  |     "   :arg tri_b1: target triangle vertex.\n" | 
					
						
							|  |  |  |     "   :type tri_b1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg tri_b2: target triangle vertex.\n" | 
					
						
							|  |  |  |     "   :type tri_b2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg tri_b3: target triangle vertex.\n" | 
					
						
							|  |  |  |     "   :type tri_b3: :class:`mathutils.Vector`\n" | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     "   :return: The transformed point\n" | 
					
						
							|  |  |  |     "   :rtype: :class:`mathutils.Vector`'s\n"); | 
					
						
							|  |  |  | static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "barycentric_transform"; | 
					
						
							|  |  |  |   PyObject *py_pt_src, *py_tri_src[3], *py_tri_dst[3]; | 
					
						
							|  |  |  |   float pt_src[3], pt_dst[3], tri_src[3][3], tri_dst[3][3]; | 
					
						
							|  |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, | 
					
						
							|  |  |  |                         "OOOOOOO:barycentric_transform", | 
					
						
							|  |  |  |                         &py_pt_src, | 
					
						
							|  |  |  |                         UNPACK3_EX(&, py_tri_src, ), | 
					
						
							|  |  |  |                         UNPACK3_EX(&, py_tri_dst, ))) { | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-18 18:41:47 +01:00
										 |  |  |   if (mathutils_array_parse(pt_src, 3, 3 | MU_ARRAY_SPILL, py_pt_src, error_prefix) == -1) { | 
					
						
							| 
									
										
										
										
											2013-08-23 14:37:22 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   for (i = 0; i < ARRAY_SIZE(tri_src); i++) { | 
					
						
							|  |  |  |     if (((mathutils_array_parse(tri_src[i], 3, 3 | MU_ARRAY_SPILL, py_tri_src[i], error_prefix) != | 
					
						
							|  |  |  |           -1) && | 
					
						
							|  |  |  |          (mathutils_array_parse(tri_dst[i], 3, 3 | MU_ARRAY_SPILL, py_tri_dst[i], error_prefix) != | 
					
						
							|  |  |  |           -1)) == 0) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-13 14:55:45 +10:00
										 |  |  |   transform_point_by_tri_v3(pt_dst, pt_src, UNPACK3(tri_dst), UNPACK3(tri_src)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |   return Vector_CreatePyObject(pt_dst, 3, NULL); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-07 20:14:40 +11:00
										 |  |  | struct PointsInPlanes_UserData { | 
					
						
							|  |  |  |   PyObject *py_verts; | 
					
						
							|  |  |  |   char *planes_used; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void points_in_planes_fn(const float co[3], int i, int j, int k, void *user_data_p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   struct PointsInPlanes_UserData *user_data = user_data_p; | 
					
						
							|  |  |  |   PyList_APPEND(user_data->py_verts, Vector_CreatePyObject(co, 3, NULL)); | 
					
						
							|  |  |  |   user_data->planes_used[i] = true; | 
					
						
							|  |  |  |   user_data->planes_used[j] = true; | 
					
						
							|  |  |  |   user_data->planes_used[k] = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-27 09:51:22 +00:00
										 |  |  | PyDoc_STRVAR(M_Geometry_points_in_planes_doc, | 
					
						
							|  |  |  |              ".. function:: points_in_planes(planes)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Returns a list of points inside all planes given and a list of index values for " | 
					
						
							|  |  |  |              "the planes used.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg planes: List of planes (4D vectors).\n" | 
					
						
							|  |  |  |              "   :type planes: list of :class:`mathutils.Vector`\n" | 
					
						
							| 
									
										
										
										
											2014-01-13 14:53:41 +11:00
										 |  |  |              "   :return: two lists, once containing the vertices inside the planes, another " | 
					
						
							|  |  |  |              "containing the plane indices used\n" | 
					
						
							| 
									
										
										
										
											2012-06-27 09:51:22 +00:00
										 |  |  |              "   :rtype: pair of lists\n"); | 
					
						
							|  |  |  | static PyObject *M_Geometry_points_in_planes(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject *py_planes; | 
					
						
							|  |  |  |   float(*planes)[4]; | 
					
						
							| 
									
										
										
										
											2020-02-20 15:38:58 +11:00
										 |  |  |   uint planes_len; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "O:points_in_planes", &py_planes)) { | 
					
						
							| 
									
										
										
										
											2012-06-27 09:51:22 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-27 09:51:22 +00:00
										 |  |  |   if ((planes_len = mathutils_array_parse_alloc_v( | 
					
						
							|  |  |  |            (float **)&planes, 4, py_planes, "points_in_planes")) == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-03 23:08:40 +10:00
										 |  |  |   /* NOTE: this could be refactored into plain C easy - py bits are noted. */ | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-07 20:14:40 +11:00
										 |  |  |   struct PointsInPlanes_UserData user_data = { | 
					
						
							|  |  |  |       .py_verts = PyList_New(0), | 
					
						
							|  |  |  |       .planes_used = PyMem_Malloc(sizeof(char) * planes_len), | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* python */ | 
					
						
							|  |  |  |   PyObject *py_plane_index = PyList_New(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-07 20:14:40 +11:00
										 |  |  |   memset(user_data.planes_used, 0, sizeof(char) * planes_len); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-07 20:14:40 +11:00
										 |  |  |   const float eps_coplanar = 1e-4f; | 
					
						
							|  |  |  |   const float eps_isect = 1e-6f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const bool has_isect = isect_planes_v3_fn( | 
					
						
							|  |  |  |       planes, planes_len, eps_coplanar, eps_isect, points_in_planes_fn, &user_data); | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   PyMem_Free(planes); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-07 20:14:40 +11:00
										 |  |  |   /* Now make user_data list of used planes. */ | 
					
						
							|  |  |  |   if (has_isect) { | 
					
						
							|  |  |  |     for (int i = 0; i < planes_len; i++) { | 
					
						
							|  |  |  |       if (user_data.planes_used[i]) { | 
					
						
							|  |  |  |         PyList_APPEND(py_plane_index, PyLong_FromLong(i)); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-11-07 20:14:40 +11:00
										 |  |  |   PyMem_Free(user_data.planes_used); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     PyObject *ret = PyTuple_New(2); | 
					
						
							| 
									
										
										
										
											2020-11-07 20:14:40 +11:00
										 |  |  |     PyTuple_SET_ITEMS(ret, user_data.py_verts, py_plane_index); | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |     return ret; | 
					
						
							| 
									
										
										
										
											2012-06-27 09:51:22 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | #ifndef MATH_STANDALONE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(M_Geometry_interpolate_bezier_doc, | 
					
						
							|  |  |  |              ".. function:: interpolate_bezier(knot1, handle1, handle2, knot2, resolution)\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |              "   Interpolate a bezier spline segment.\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |              "   :arg knot1: First bezier spline point.\n" | 
					
						
							|  |  |  |              "   :type knot1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg handle1: First bezier spline handle.\n" | 
					
						
							|  |  |  |              "   :type handle1: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg handle2: Second bezier spline handle.\n" | 
					
						
							|  |  |  |              "   :type handle2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg knot2: Second bezier spline point.\n" | 
					
						
							|  |  |  |              "   :type knot2: :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |              "   :arg resolution: Number of points to return.\n" | 
					
						
							|  |  |  |              "   :type resolution: int\n" | 
					
						
							|  |  |  |              "   :return: The interpolated points\n" | 
					
						
							|  |  |  |              "   :rtype: list of :class:`mathutils.Vector`'s\n"); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   const char *error_prefix = "interpolate_bezier"; | 
					
						
							|  |  |  |   PyObject *py_data[4]; | 
					
						
							|  |  |  |   float data[4][4] = {{0.0f}}; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   int resolu; | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   int dims = 0; | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   int i; | 
					
						
							|  |  |  |   float *coord_array, *fp; | 
					
						
							|  |  |  |   PyObject *list; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   if (!PyArg_ParseTuple(args, "OOOOi:interpolate_bezier", UNPACK4_EX(&, py_data, ), &resolu)) { | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   for (i = 0; i < 4; i++) { | 
					
						
							|  |  |  |     int dims_tmp; | 
					
						
							| 
									
										
										
										
											2015-01-29 18:09:55 +01:00
										 |  |  |     if ((dims_tmp = mathutils_array_parse( | 
					
						
							|  |  |  |              data[i], 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_data[i], error_prefix)) == -1) { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     dims = max_ii(dims, dims_tmp); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (resolu <= 1) { | 
					
						
							| 
									
										
										
										
											2011-07-14 01:25:05 +00:00
										 |  |  |     PyErr_SetString(PyExc_ValueError, "resolution must be 2 or over"); | 
					
						
							| 
									
										
										
										
											2011-01-03 12:11:05 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |   coord_array = MEM_callocN(dims * (resolu) * sizeof(float), error_prefix); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   for (i = 0; i < dims; i++) { | 
					
						
							| 
									
										
										
										
											2014-12-30 21:50:47 +11:00
										 |  |  |     BKE_curve_forward_diff_bezier( | 
					
						
							|  |  |  |         UNPACK4_EX(, data, [i]), coord_array + i, resolu - 1, sizeof(float) * dims); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   list = PyList_New(resolu); | 
					
						
							|  |  |  |   fp = coord_array; | 
					
						
							|  |  |  |   for (i = 0; i < resolu; i++, fp = fp + dims) { | 
					
						
							| 
									
										
										
										
											2015-01-04 17:03:54 +11:00
										 |  |  |     PyList_SET_ITEM(list, i, Vector_CreatePyObject(fp, dims, NULL)); | 
					
						
							| 
									
										
										
										
											2009-06-17 20:33:34 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   MEM_freeN(coord_array); | 
					
						
							|  |  |  |   return list; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-12-27 01:32:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-20 22:56:26 +00:00
										 |  |  | PyDoc_STRVAR(M_Geometry_tessellate_polygon_doc, | 
					
						
							|  |  |  |              ".. function:: tessellate_polygon(veclist_list)\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2019-10-09 17:26:39 +11:00
										 |  |  |              "   Takes a list of polylines (each point a pair or triplet of numbers) and returns " | 
					
						
							| 
									
										
										
										
											2020-01-27 16:42:25 +01:00
										 |  |  |              "the point indices for a polyline filled with triangles. Does not handle degenerate " | 
					
						
							|  |  |  |              "geometry (such as zero-length lines due to consecutive identical points).\n" | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |              "   :arg veclist_list: list of polylines\n" | 
					
						
							|  |  |  |              "   :rtype: list\n"); | 
					
						
							|  |  |  | /* PolyFill function, uses Blenders scanfill to fill multiple poly lines */ | 
					
						
							| 
									
										
										
										
											2012-03-20 22:56:26 +00:00
										 |  |  | static PyObject *M_Geometry_tessellate_polygon(PyObject *UNUSED(self), PyObject *polyLineSeq) | 
					
						
							| 
									
										
										
										
											2009-12-27 01:32:58 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   PyObject *tri_list; /* Return this list of tri's */ | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   PyObject *polyLine, *polyVec; | 
					
						
							| 
									
										
										
										
											2019-10-09 17:26:39 +11:00
										 |  |  |   int i, len_polylines, len_polypoints; | 
					
						
							|  |  |  |   bool list_parse_error = false; | 
					
						
							| 
									
										
										
										
											2019-10-09 17:08:51 +11:00
										 |  |  |   bool is_2d = true; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-17 00:54:22 +10:00
										 |  |  |   /* Display #ListBase. */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   ListBase dispbase = {NULL, NULL}; | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   DispList *dl; | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   float *fp; /* Pointer to the array of malloced dl->verts to set the points from the vectors. */ | 
					
						
							| 
									
										
										
										
											2019-10-09 17:26:39 +11:00
										 |  |  |   int totpoints = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (!PySequence_Check(polyLineSeq)) { | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, "expected a sequence of poly lines"); | 
					
						
							| 
									
										
										
										
											2009-12-27 01:32:58 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   len_polylines = PySequence_Size(polyLineSeq); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-25 11:36:26 +00:00
										 |  |  |   for (i = 0; i < len_polylines; i++) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     polyLine = PySequence_GetItem(polyLineSeq, i); | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     if (!PySequence_Check(polyLine)) { | 
					
						
							| 
									
										
										
										
											2012-05-07 06:58:03 +00:00
										 |  |  |       BKE_displist_free(&dispbase); | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |       Py_XDECREF(polyLine); /* may be null so use Py_XDECREF*/ | 
					
						
							|  |  |  |       PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                       "One or more of the polylines is not a sequence of mathutils.Vector's"); | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     len_polypoints = PySequence_Size(polyLine); | 
					
						
							| 
									
										
										
										
											2012-03-18 07:38:51 +00:00
										 |  |  |     if (len_polypoints > 0) { /* don't bother adding edges as polylines */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |       dl = MEM_callocN(sizeof(DispList), "poly disp"); | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |       BLI_addtail(&dispbase, dl); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |       dl->type = DL_INDEX3; | 
					
						
							|  |  |  |       dl->nr = len_polypoints; | 
					
						
							|  |  |  |       dl->type = DL_POLY; | 
					
						
							|  |  |  |       dl->parts = 1; /* no faces, 1 edge loop */ | 
					
						
							|  |  |  |       dl->col = 0;   /* no material */ | 
					
						
							| 
									
										
										
										
											2019-10-09 17:26:39 +11:00
										 |  |  |       dl->verts = fp = MEM_mallocN(sizeof(float[3]) * len_polypoints, "dl verts"); | 
					
						
							|  |  |  |       dl->index = MEM_callocN(sizeof(int[3]) * len_polypoints, "dl index"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-09 17:26:39 +11:00
										 |  |  |       for (int index = 0; index < len_polypoints; index++, fp += 3) { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |         polyVec = PySequence_GetItem(polyLine, index); | 
					
						
							| 
									
										
										
										
											2019-10-09 17:26:39 +11:00
										 |  |  |         const int polyVec_len = mathutils_array_parse( | 
					
						
							|  |  |  |             fp, 2, 3 | MU_ARRAY_SPILL, polyVec, "tessellate_polygon: parse coord"); | 
					
						
							|  |  |  |         Py_DECREF(polyVec); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-09 17:26:39 +11:00
										 |  |  |         if (UNLIKELY(polyVec_len == -1)) { | 
					
						
							|  |  |  |           list_parse_error = true; | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-10-09 17:26:39 +11:00
										 |  |  |         else if (polyVec_len == 2) { | 
					
						
							|  |  |  |           fp[2] = 0.0f; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (polyVec_len == 3) { | 
					
						
							|  |  |  |           is_2d = false; | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |         totpoints++; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Py_DECREF(polyLine); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-09 17:26:39 +11:00
										 |  |  |   if (list_parse_error) { | 
					
						
							| 
									
										
										
										
											2012-05-07 06:58:03 +00:00
										 |  |  |     BKE_displist_free(&dispbase); /* possible some dl was allocated */ | 
					
						
							| 
									
										
										
										
											2011-04-21 15:53:30 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:41:06 +02:00
										 |  |  |   if (totpoints) { | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     /* now make the list to return */ | 
					
						
							| 
									
										
										
										
											2019-10-09 17:08:51 +11:00
										 |  |  |     BKE_displist_fill(&dispbase, &dispbase, is_2d ? ((const float[3]){0, 0, -1}) : NULL, false); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     /* The faces are stored in a new DisplayList
 | 
					
						
							| 
									
										
										
										
											2019-08-17 00:54:22 +10:00
										 |  |  |      * that's added to the head of the #ListBase. */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     dl = dispbase.first; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     tri_list = PyList_New(dl->parts); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     if (!tri_list) { | 
					
						
							| 
									
										
										
										
											2012-05-07 06:58:03 +00:00
										 |  |  |       BKE_displist_free(&dispbase); | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |       PyErr_SetString(PyExc_RuntimeError, "failed to make a new list"); | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-09 17:26:39 +11:00
										 |  |  |     int *dl_face = dl->index; | 
					
						
							|  |  |  |     for (int index = 0; index < dl->parts; index++) { | 
					
						
							| 
									
										
										
										
											2017-08-22 18:02:58 +10:00
										 |  |  |       PyList_SET_ITEM(tri_list, index, PyC_Tuple_Pack_I32(dl_face[0], dl_face[1], dl_face[2])); | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |       dl_face += 3; | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-05-07 06:58:03 +00:00
										 |  |  |     BKE_displist_free(&dispbase); | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2012-03-18 07:38:51 +00:00
										 |  |  |     /* no points, do this so scripts don't barf */ | 
					
						
							| 
									
										
										
										
											2012-05-07 06:58:03 +00:00
										 |  |  |     BKE_displist_free(&dispbase); /* possible some dl was allocated */ | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     tri_list = PyList_New(0); | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   return tri_list; | 
					
						
							| 
									
										
										
										
											2009-12-27 01:32:58 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-18 12:50:44 +11:00
										 |  |  | static int boxPack_FromPyObject(PyObject *value, BoxPack **r_boxarray) | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-06 23:46:20 +00:00
										 |  |  |   Py_ssize_t len, i; | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   PyObject *list_item, *item_1, *item_2; | 
					
						
							| 
									
										
										
										
											2020-11-18 12:50:44 +11:00
										 |  |  |   BoxPack *boxarray; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   /* Error checking must already be done */ | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (!PyList_Check(value)) { | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, "can only back a list of [x, y, w, h]"); | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   len = PyList_GET_SIZE(value); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-18 12:50:44 +11:00
										 |  |  |   boxarray = MEM_mallocN(sizeof(BoxPack) * len, __func__); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   for (i = 0; i < len; i++) { | 
					
						
							|  |  |  |     list_item = PyList_GET_ITEM(value, i); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     if (!PyList_Check(list_item) || PyList_GET_SIZE(list_item) < 4) { | 
					
						
							| 
									
										
										
										
											2020-11-18 12:50:44 +11:00
										 |  |  |       MEM_freeN(boxarray); | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |       PyErr_SetString(PyExc_TypeError, "can only pack a list of [x, y, w, h]"); | 
					
						
							|  |  |  |       return -1; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-18 12:50:44 +11:00
										 |  |  |     BoxPack *box = &boxarray[i]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     item_1 = PyList_GET_ITEM(list_item, 2); | 
					
						
							|  |  |  |     item_2 = PyList_GET_ITEM(list_item, 3); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     box->w = (float)PyFloat_AsDouble(item_1); | 
					
						
							|  |  |  |     box->h = (float)PyFloat_AsDouble(item_2); | 
					
						
							|  |  |  |     box->index = i; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     /* accounts for error case too and overwrites with own error */ | 
					
						
							|  |  |  |     if (box->w < 0.0f || box->h < 0.0f) { | 
					
						
							| 
									
										
										
										
											2020-11-18 12:50:44 +11:00
										 |  |  |       MEM_freeN(boxarray); | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |       PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                       "error parsing width and height values from list: " | 
					
						
							|  |  |  |                       "[x, y, w, h], not numbers or below zero"); | 
					
						
							|  |  |  |       return -1; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     /* verts will be added later */ | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-11-18 12:50:44 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |   *r_boxarray = boxarray; | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-18 12:50:44 +11:00
										 |  |  | static void boxPack_ToPyObject(PyObject *value, const BoxPack *boxarray) | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-06 23:46:20 +00:00
										 |  |  |   Py_ssize_t len, i; | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   PyObject *list_item; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   len = PyList_GET_SIZE(value); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   for (i = 0; i < len; i++) { | 
					
						
							| 
									
										
										
										
											2020-11-18 12:50:44 +11:00
										 |  |  |     const BoxPack *box = &boxarray[i]; | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |     list_item = PyList_GET_ITEM(value, box->index); | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     PyList_SET_ITEM(list_item, 0, PyFloat_FromDouble(box->x)); | 
					
						
							|  |  |  |     PyList_SET_ITEM(list_item, 1, PyFloat_FromDouble(box->y)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(M_Geometry_box_pack_2d_doc, | 
					
						
							|  |  |  |              ".. function:: box_pack_2d(boxes)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2020-05-08 14:09:55 +02:00
										 |  |  |              "   Returns a tuple with the width and height of the packed bounding box.\n" | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg boxes: list of boxes, each box is a list where the first 4 items are [x, y, " | 
					
						
							|  |  |  |              "width, height, ...] other items are ignored.\n" | 
					
						
							|  |  |  |              "   :type boxes: list\n" | 
					
						
							|  |  |  |              "   :return: the width and height of the packed bounding box\n" | 
					
						
							|  |  |  |              "   :rtype: tuple, pair of floats\n"); | 
					
						
							|  |  |  | static PyObject *M_Geometry_box_pack_2d(PyObject *UNUSED(self), PyObject *boxlist) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   float tot_width = 0.0f, tot_height = 0.0f; | 
					
						
							| 
									
										
										
										
											2011-09-06 23:46:20 +00:00
										 |  |  |   Py_ssize_t len; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   PyObject *ret; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |   if (!PyList_Check(boxlist)) { | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     PyErr_SetString(PyExc_TypeError, "expected a list of boxes [[x, y, w, h], ... ]"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   len = PyList_GET_SIZE(boxlist); | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   if (len) { | 
					
						
							| 
									
										
										
										
											2012-05-05 00:23:55 +00:00
										 |  |  |     BoxPack *boxarray = NULL; | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  |     if (boxPack_FromPyObject(boxlist, &boxarray) == -1) { | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |       return NULL; /* exception set */ | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     /* Non Python function */ | 
					
						
							| 
									
										
										
										
											2013-09-10 19:23:39 +00:00
										 |  |  |     BLI_box_pack_2d(boxarray, len, &tot_width, &tot_height); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-18 12:50:44 +11:00
										 |  |  |     boxPack_ToPyObject(boxlist, boxarray); | 
					
						
							|  |  |  |     MEM_freeN(boxarray); | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   ret = PyTuple_New(2); | 
					
						
							| 
									
										
										
										
											2015-01-06 16:42:22 +11:00
										 |  |  |   PyTuple_SET_ITEMS(ret, PyFloat_FromDouble(tot_width), PyFloat_FromDouble(tot_height)); | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-11 06:56:51 +00:00
										 |  |  | PyDoc_STRVAR(M_Geometry_box_fit_2d_doc, | 
					
						
							|  |  |  |              ".. function:: box_fit_2d(points)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2013-09-11 07:10:15 +00:00
										 |  |  |              "   Returns an angle that best fits the points to an axis aligned rectangle\n" | 
					
						
							| 
									
										
										
										
											2013-09-11 06:56:51 +00:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg points: list of 2d points.\n" | 
					
						
							|  |  |  |              "   :type points: list\n" | 
					
						
							| 
									
										
										
										
											2013-09-11 07:10:15 +00:00
										 |  |  |              "   :return: angle\n" | 
					
						
							|  |  |  |              "   :rtype: float\n"); | 
					
						
							| 
									
										
										
										
											2013-09-11 06:56:51 +00:00
										 |  |  | static PyObject *M_Geometry_box_fit_2d(PyObject *UNUSED(self), PyObject *pointlist) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   float(*points)[2]; | 
					
						
							|  |  |  |   Py_ssize_t len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   float angle = 0.0f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   len = mathutils_array_parse_alloc_v(((float **)&points), 2, pointlist, "box_fit_2d"); | 
					
						
							|  |  |  |   if (len == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (len) { | 
					
						
							|  |  |  |     /* Non Python function */ | 
					
						
							| 
									
										
										
										
											2017-10-20 14:03:22 +11:00
										 |  |  |     angle = BLI_convexhull_aabb_fit_points_2d(points, len); | 
					
						
							| 
									
										
										
										
											2013-09-11 06:56:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     PyMem_Free(points); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return PyFloat_FromDouble(angle); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-09-10 07:52:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(M_Geometry_convex_hull_2d_doc, | 
					
						
							|  |  |  |              ".. function:: convex_hull_2d(points)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Returns a list of indices into the list given\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :arg points: list of 2d points.\n" | 
					
						
							|  |  |  |              "   :type points: list\n" | 
					
						
							|  |  |  |              "   :return: a list of indices\n" | 
					
						
							|  |  |  |              "   :rtype: list of ints\n"); | 
					
						
							|  |  |  | static PyObject *M_Geometry_convex_hull_2d(PyObject *UNUSED(self), PyObject *pointlist) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-11 06:56:51 +00:00
										 |  |  |   float(*points)[2]; | 
					
						
							| 
									
										
										
										
											2013-09-10 07:52:10 +00:00
										 |  |  |   Py_ssize_t len; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-11 06:56:51 +00:00
										 |  |  |   PyObject *ret; | 
					
						
							| 
									
										
										
										
											2013-09-10 07:52:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-11 06:56:51 +00:00
										 |  |  |   len = mathutils_array_parse_alloc_v(((float **)&points), 2, pointlist, "convex_hull_2d"); | 
					
						
							| 
									
										
										
										
											2013-09-10 07:52:10 +00:00
										 |  |  |   if (len == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-09-10 07:52:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-19 11:18:00 +11:00
										 |  |  |   if (len) { | 
					
						
							|  |  |  |     int *index_map; | 
					
						
							|  |  |  |     Py_ssize_t len_ret, i; | 
					
						
							| 
									
										
										
										
											2013-09-10 07:52:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 14:03:22 +11:00
										 |  |  |     index_map = MEM_mallocN(sizeof(*index_map) * len * 2, __func__); | 
					
						
							| 
									
										
										
										
											2013-09-10 07:52:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* Non Python function */ | 
					
						
							|  |  |  |     len_ret = BLI_convexhull_2d(points, len, index_map); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ret = PyList_New(len_ret); | 
					
						
							|  |  |  |     for (i = 0; i < len_ret; i++) { | 
					
						
							|  |  |  |       PyList_SET_ITEM(ret, i, PyLong_FromLong(index_map[i])); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-09-11 06:56:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     MEM_freeN(index_map); | 
					
						
							| 
									
										
										
										
											2013-09-10 07:52:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-27 09:51:22 +00:00
										 |  |  |     PyMem_Free(points); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2013-09-10 07:52:10 +00:00
										 |  |  |     ret = PyList_New(0); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-09-11 06:56:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-10 07:52:10 +00:00
										 |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  | /* Return a PyObject that is a list of lists, using the flattened list array
 | 
					
						
							|  |  |  |  * to fill values, with start_table and len_table giving the start index | 
					
						
							| 
									
										
										
										
											2019-08-18 04:11:50 +10:00
										 |  |  |  * and length of the toplevel_len sub-lists. | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-07-13 11:27:09 +02:00
										 |  |  | static PyObject *list_of_lists_from_arrays(const int *array, | 
					
						
							|  |  |  |                                            const int *start_table, | 
					
						
							|  |  |  |                                            const int *len_table, | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  |                                            int toplevel_len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject *ret, *sublist; | 
					
						
							|  |  |  |   int i, j, sublist_len, sublist_start, val; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-18 15:10:34 -04:00
										 |  |  |   if (array == NULL) { | 
					
						
							|  |  |  |     return PyList_New(0); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  |   ret = PyList_New(toplevel_len); | 
					
						
							|  |  |  |   for (i = 0; i < toplevel_len; i++) { | 
					
						
							|  |  |  |     sublist_len = len_table[i]; | 
					
						
							|  |  |  |     sublist = PyList_New(sublist_len); | 
					
						
							|  |  |  |     sublist_start = start_table[i]; | 
					
						
							|  |  |  |     for (j = 0; j < sublist_len; j++) { | 
					
						
							|  |  |  |       val = array[sublist_start + j]; | 
					
						
							|  |  |  |       PyList_SET_ITEM(sublist, j, PyLong_FromLong(val)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     PyList_SET_ITEM(ret, i, sublist); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     M_Geometry_delaunay_2d_cdt_doc, | 
					
						
							| 
									
										
										
										
											2021-07-19 11:57:28 +10:00
										 |  |  |     ".. function:: delaunay_2d_cdt(vert_coords, edges, faces, output_type, epsilon, " | 
					
						
							|  |  |  |     "need_ids=True)\n" | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2020-09-29 15:46:20 -04:00
										 |  |  |     "   Computes the Constrained Delaunay Triangulation of a set of vertices,\n" | 
					
						
							|  |  |  |     "   with edges and faces that must appear in the triangulation.\n" | 
					
						
							|  |  |  |     "   Some triangles may be eaten away, or combined with other triangles,\n" | 
					
						
							|  |  |  |     "   according to output type.\n" | 
					
						
							|  |  |  |     "   The returned verts may be in a different order from input verts, may be moved\n" | 
					
						
							|  |  |  |     "   slightly, and may be merged with other nearby verts.\n" | 
					
						
							|  |  |  |     "   The three returned orig lists give, for each of verts, edges, and faces, the list of\n" | 
					
						
							|  |  |  |     "   input element indices corresponding to the positionally same output element.\n" | 
					
						
							|  |  |  |     "   For edges, the orig indices start with the input edges and then continue\n" | 
					
						
							|  |  |  |     "   with the edges implied by each of the faces (n of them for an n-gon).\n" | 
					
						
							| 
									
										
										
										
											2021-07-18 15:24:12 -04:00
										 |  |  |     "   If the need_ids argument is supplied, and False, then the code skips the preparation\n" | 
					
						
							|  |  |  |     "   of the orig arrays, which may save some time." | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  |     "\n" | 
					
						
							|  |  |  |     "   :arg vert_coords: Vertex coordinates (2d)\n" | 
					
						
							|  |  |  |     "   :type vert_coords: list of :class:`mathutils.Vector`\n" | 
					
						
							|  |  |  |     "   :arg edges: Edges, as pairs of indices in `vert_coords`\n" | 
					
						
							|  |  |  |     "   :type edges: list of (int, int)\n" | 
					
						
							|  |  |  |     "   :arg faces: Faces, each sublist is a face, as indices in `vert_coords` (CCW oriented)\n" | 
					
						
							|  |  |  |     "   :type faces: list of list of int\n" | 
					
						
							|  |  |  |     "   :arg output_type: What output looks like. 0 => triangles with convex hull. " | 
					
						
							|  |  |  |     "1 => triangles inside constraints. " | 
					
						
							|  |  |  |     "2 => the input constraints, intersected. " | 
					
						
							| 
									
										
										
										
											2021-07-18 15:24:12 -04:00
										 |  |  |     "3 => like 2 but detect holes and omit them from output. " | 
					
						
							|  |  |  |     "4 => like 2 but with extra edges to make valid BMesh faces. " | 
					
						
							|  |  |  |     "5 => like 4 but detect holes and omit them from output.\n" | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  |     "   :type output_type: int\\n" | 
					
						
							|  |  |  |     "   :arg epsilon: For nearness tests; should not be zero\n" | 
					
						
							|  |  |  |     "   :type epsilon: float\n" | 
					
						
							| 
									
										
										
										
											2021-07-19 11:57:28 +10:00
										 |  |  |     "   :arg need_ids: are the orig output arrays needed?\n" | 
					
						
							| 
									
										
										
										
											2021-07-18 15:24:12 -04:00
										 |  |  |     "   :type need_args: bool\n" | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  |     "   :return: Output tuple, (vert_coords, edges, faces, orig_verts, orig_edges, orig_faces)\n" | 
					
						
							|  |  |  |     "   :rtype: (list of `mathutils.Vector`, " | 
					
						
							|  |  |  |     "list of (int, int), " | 
					
						
							|  |  |  |     "list of list of int, " | 
					
						
							|  |  |  |     "list of list of int, " | 
					
						
							|  |  |  |     "list of list of int, " | 
					
						
							|  |  |  |     "list of list of int)\n" | 
					
						
							|  |  |  |     "\n"); | 
					
						
							|  |  |  | static PyObject *M_Geometry_delaunay_2d_cdt(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const char *error_prefix = "delaunay_2d_cdt"; | 
					
						
							|  |  |  |   PyObject *vert_coords, *edges, *faces, *item; | 
					
						
							|  |  |  |   int output_type; | 
					
						
							|  |  |  |   float epsilon; | 
					
						
							| 
									
										
										
										
											2021-07-18 15:10:34 -04:00
										 |  |  |   bool need_ids = true; | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  |   float(*in_coords)[2] = NULL; | 
					
						
							|  |  |  |   int(*in_edges)[2] = NULL; | 
					
						
							|  |  |  |   int *in_faces = NULL; | 
					
						
							|  |  |  |   int *in_faces_start_table = NULL; | 
					
						
							|  |  |  |   int *in_faces_len_table = NULL; | 
					
						
							|  |  |  |   Py_ssize_t vert_coords_len, edges_len, faces_len; | 
					
						
							|  |  |  |   CDT_input in; | 
					
						
							|  |  |  |   CDT_result *res = NULL; | 
					
						
							|  |  |  |   PyObject *out_vert_coords = NULL; | 
					
						
							|  |  |  |   PyObject *out_edges = NULL; | 
					
						
							|  |  |  |   PyObject *out_faces = NULL; | 
					
						
							|  |  |  |   PyObject *out_orig_verts = NULL; | 
					
						
							|  |  |  |   PyObject *out_orig_edges = NULL; | 
					
						
							|  |  |  |   PyObject *out_orig_faces = NULL; | 
					
						
							|  |  |  |   PyObject *ret_value = NULL; | 
					
						
							|  |  |  |   int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-18 15:10:34 -04:00
										 |  |  |   if (!PyArg_ParseTuple(args, | 
					
						
							|  |  |  |                         "OOOif|p:delaunay_2d_cdt", | 
					
						
							|  |  |  |                         &vert_coords, | 
					
						
							|  |  |  |                         &edges, | 
					
						
							|  |  |  |                         &faces, | 
					
						
							|  |  |  |                         &output_type, | 
					
						
							|  |  |  |                         &epsilon, | 
					
						
							|  |  |  |                         &need_ids)) { | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   vert_coords_len = mathutils_array_parse_alloc_v( | 
					
						
							|  |  |  |       (float **)&in_coords, 2, vert_coords, error_prefix); | 
					
						
							|  |  |  |   if (vert_coords_len == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   edges_len = mathutils_array_parse_alloc_vi((int **)&in_edges, 2, edges, error_prefix); | 
					
						
							|  |  |  |   if (edges_len == -1) { | 
					
						
							|  |  |  |     goto exit_cdt; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   faces_len = mathutils_array_parse_alloc_viseq( | 
					
						
							|  |  |  |       &in_faces, &in_faces_start_table, &in_faces_len_table, faces, error_prefix); | 
					
						
							|  |  |  |   if (faces_len == -1) { | 
					
						
							|  |  |  |     goto exit_cdt; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   in.verts_len = (int)vert_coords_len; | 
					
						
							|  |  |  |   in.vert_coords = in_coords; | 
					
						
							|  |  |  |   in.edges_len = edges_len; | 
					
						
							|  |  |  |   in.faces_len = faces_len; | 
					
						
							|  |  |  |   in.edges = in_edges; | 
					
						
							|  |  |  |   in.faces = in_faces; | 
					
						
							|  |  |  |   in.faces_start_table = in_faces_start_table; | 
					
						
							|  |  |  |   in.faces_len_table = in_faces_len_table; | 
					
						
							|  |  |  |   in.epsilon = epsilon; | 
					
						
							| 
									
										
										
										
											2021-07-18 15:10:34 -04:00
										 |  |  |   in.need_ids = need_ids; | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   res = BLI_delaunay_2d_cdt_calc(&in, output_type); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ret_value = PyTuple_New(6); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   out_vert_coords = PyList_New(res->verts_len); | 
					
						
							|  |  |  |   for (i = 0; i < res->verts_len; i++) { | 
					
						
							|  |  |  |     item = Vector_CreatePyObject(res->vert_coords[i], 2, NULL); | 
					
						
							|  |  |  |     if (item == NULL) { | 
					
						
							|  |  |  |       Py_DECREF(ret_value); | 
					
						
							|  |  |  |       Py_DECREF(out_vert_coords); | 
					
						
							|  |  |  |       goto exit_cdt; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     PyList_SET_ITEM(out_vert_coords, i, item); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   PyTuple_SET_ITEM(ret_value, 0, out_vert_coords); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   out_edges = PyList_New(res->edges_len); | 
					
						
							|  |  |  |   for (i = 0; i < res->edges_len; i++) { | 
					
						
							|  |  |  |     item = PyTuple_New(2); | 
					
						
							|  |  |  |     PyTuple_SET_ITEM(item, 0, PyLong_FromLong((long)res->edges[i][0])); | 
					
						
							|  |  |  |     PyTuple_SET_ITEM(item, 1, PyLong_FromLong((long)res->edges[i][1])); | 
					
						
							|  |  |  |     PyList_SET_ITEM(out_edges, i, item); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   PyTuple_SET_ITEM(ret_value, 1, out_edges); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   out_faces = list_of_lists_from_arrays( | 
					
						
							|  |  |  |       res->faces, res->faces_start_table, res->faces_len_table, res->faces_len); | 
					
						
							|  |  |  |   PyTuple_SET_ITEM(ret_value, 2, out_faces); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   out_orig_verts = list_of_lists_from_arrays( | 
					
						
							|  |  |  |       res->verts_orig, res->verts_orig_start_table, res->verts_orig_len_table, res->verts_len); | 
					
						
							|  |  |  |   PyTuple_SET_ITEM(ret_value, 3, out_orig_verts); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   out_orig_edges = list_of_lists_from_arrays( | 
					
						
							|  |  |  |       res->edges_orig, res->edges_orig_start_table, res->edges_orig_len_table, res->edges_len); | 
					
						
							|  |  |  |   PyTuple_SET_ITEM(ret_value, 4, out_orig_edges); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   out_orig_faces = list_of_lists_from_arrays( | 
					
						
							|  |  |  |       res->faces_orig, res->faces_orig_start_table, res->faces_orig_len_table, res->faces_len); | 
					
						
							|  |  |  |   PyTuple_SET_ITEM(ret_value, 5, out_orig_faces); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit_cdt: | 
					
						
							|  |  |  |   if (in_coords != NULL) { | 
					
						
							|  |  |  |     PyMem_Free(in_coords); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (in_edges != NULL) { | 
					
						
							|  |  |  |     PyMem_Free(in_edges); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (in_faces != NULL) { | 
					
						
							|  |  |  |     PyMem_Free(in_faces); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (in_faces_start_table != NULL) { | 
					
						
							|  |  |  |     PyMem_Free(in_faces_start_table); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (in_faces_len_table != NULL) { | 
					
						
							|  |  |  |     PyMem_Free(in_faces_len_table); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (res) { | 
					
						
							|  |  |  |     BLI_delaunay_2d_cdt_free(res); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return ret_value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | #endif /* MATH_STANDALONE */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static PyMethodDef M_Geometry_methods[] = { | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |     {"intersect_ray_tri", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_ray_tri, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_intersect_ray_tri_doc}, | 
					
						
							|  |  |  |     {"intersect_point_line", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_point_line, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_intersect_point_line_doc}, | 
					
						
							| 
									
										
										
										
											2014-07-21 16:58:17 +10:00
										 |  |  |     {"intersect_point_tri", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_point_tri, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |      M_Geometry_intersect_point_tri_doc}, | 
					
						
							| 
									
										
										
										
											2019-11-06 11:13:41 +03:00
										 |  |  |     {"closest_point_on_tri", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_closest_point_on_tri, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_closest_point_on_tri_doc}, | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |     {"intersect_point_tri_2d", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_point_tri_2d, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_intersect_point_tri_2d_doc}, | 
					
						
							|  |  |  |     {"intersect_point_quad_2d", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_point_quad_2d, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_intersect_point_quad_2d_doc}, | 
					
						
							|  |  |  |     {"intersect_line_line", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_line_line, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_intersect_line_line_doc}, | 
					
						
							|  |  |  |     {"intersect_line_line_2d", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_line_line_2d, | 
					
						
							| 
									
										
										
										
											2011-05-19 04:28:09 +00:00
										 |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_intersect_line_line_2d_doc}, | 
					
						
							|  |  |  |     {"intersect_line_plane", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_line_plane, | 
					
						
							| 
									
										
										
										
											2011-11-20 05:56:21 +00:00
										 |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_intersect_line_plane_doc}, | 
					
						
							|  |  |  |     {"intersect_plane_plane", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_plane_plane, | 
					
						
							| 
									
										
										
										
											2011-06-26 07:21:19 +00:00
										 |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_intersect_plane_plane_doc}, | 
					
						
							|  |  |  |     {"intersect_line_sphere", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_line_sphere, | 
					
						
							| 
									
										
										
										
											2011-06-26 11:08:12 +00:00
										 |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_intersect_line_sphere_doc}, | 
					
						
							|  |  |  |     {"intersect_line_sphere_2d", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_line_sphere_2d, | 
					
						
							| 
									
										
										
										
											2011-11-12 10:06:56 +00:00
										 |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_intersect_line_sphere_2d_doc}, | 
					
						
							|  |  |  |     {"distance_point_to_plane", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_distance_point_to_plane, | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_distance_point_to_plane_doc}, | 
					
						
							|  |  |  |     {"intersect_sphere_sphere_2d", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_sphere_sphere_2d, | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |      METH_VARARGS, | 
					
						
							| 
									
										
										
										
											2013-01-28 11:52:17 +00:00
										 |  |  |      M_Geometry_intersect_sphere_sphere_2d_doc}, | 
					
						
							| 
									
										
										
										
											2019-08-10 05:34:30 +10:00
										 |  |  |     {"intersect_tri_tri_2d", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_intersect_tri_tri_2d, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_intersect_tri_tri_2d_doc}, | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |     {"area_tri", (PyCFunction)M_Geometry_area_tri, METH_VARARGS, M_Geometry_area_tri_doc}, | 
					
						
							| 
									
										
										
										
											2013-04-21 13:24:45 +00:00
										 |  |  |     {"volume_tetrahedron", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_volume_tetrahedron, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_volume_tetrahedron_doc}, | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |     {"normal", (PyCFunction)M_Geometry_normal, METH_VARARGS, M_Geometry_normal_doc}, | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  |     {"barycentric_transform", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_barycentric_transform, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_barycentric_transform_doc}, | 
					
						
							| 
									
										
										
										
											2012-06-27 09:51:22 +00:00
										 |  |  |     {"points_in_planes", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_points_in_planes, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_points_in_planes_doc}, | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | #ifndef MATH_STANDALONE
 | 
					
						
							|  |  |  |     {"interpolate_bezier", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_interpolate_bezier, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_interpolate_bezier_doc}, | 
					
						
							| 
									
										
										
										
											2012-03-20 22:56:26 +00:00
										 |  |  |     {"tessellate_polygon", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_tessellate_polygon, | 
					
						
							|  |  |  |      METH_O, | 
					
						
							|  |  |  |      M_Geometry_tessellate_polygon_doc}, | 
					
						
							| 
									
										
										
										
											2013-09-10 07:52:10 +00:00
										 |  |  |     {"convex_hull_2d", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_convex_hull_2d, | 
					
						
							|  |  |  |      METH_O, | 
					
						
							|  |  |  |      M_Geometry_convex_hull_2d_doc}, | 
					
						
							| 
									
										
										
										
											2019-08-13 07:31:14 -04:00
										 |  |  |     {"delaunay_2d_cdt", | 
					
						
							|  |  |  |      (PyCFunction)M_Geometry_delaunay_2d_cdt, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      M_Geometry_delaunay_2d_cdt_doc}, | 
					
						
							| 
									
										
										
										
											2013-09-11 06:56:51 +00:00
										 |  |  |     {"box_fit_2d", (PyCFunction)M_Geometry_box_fit_2d, METH_O, M_Geometry_box_fit_2d_doc}, | 
					
						
							| 
									
										
										
										
											2011-01-02 02:11:38 +00:00
										 |  |  |     {"box_pack_2d", (PyCFunction)M_Geometry_box_pack_2d, METH_O, M_Geometry_box_pack_2d_doc}, | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  | static struct PyModuleDef M_Geometry_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
										 |  |  |     PyModuleDef_HEAD_INIT, | 
					
						
							| 
									
										
										
										
											2010-10-25 22:44:01 +00:00
										 |  |  |     "mathutils.geometry", /* 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_Geometry_doc,       /* m_doc */ | 
					
						
							|  |  |  |     0,                    /* m_size */ | 
					
						
							|  |  |  |     M_Geometry_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
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*----------------------------MODULE INIT-------------------------*/ | 
					
						
							| 
									
										
										
										
											2011-07-15 04:01:47 +00:00
										 |  |  | PyMODINIT_FUNC PyInit_mathutils_geometry(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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-24 13:26:30 +00:00
										 |  |  |   PyObject *submodule = PyModule_Create(&M_Geometry_module_def); | 
					
						
							| 
									
										
										
										
											2010-10-29 22:59:39 +00:00
										 |  |  |   return submodule; | 
					
						
							| 
									
										
										
											
												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
										 |  |  | } |