diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-13 13:38:53 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-13 13:38:53 +0400 |
commit | 963e39e417c654602bde7c0e8e8ff522478a1ac3 (patch) | |
tree | bda66d770f83f13c668fa92627618ba2fa5039c4 | |
parent | 72a7101576dc54f6608fda8a0def19db20d10f44 (diff) |
formatting edits only - no functional changes
-rw-r--r-- | source/blender/python/mathutils/mathutils_geometry.c | 232 |
1 files changed, 154 insertions, 78 deletions
diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index a0a6ba277cf..c2487db707c 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -85,7 +85,14 @@ static PyObject *M_Geometry_intersect_ray_tri(PyObject *UNUSED(self), PyObject* float det, inv_det, u, v, t; int clip= 1; - if (!PyArg_ParseTuple(args, "O!O!O!O!O!|i:intersect_ray_tri", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &ray, &vector_Type, &ray_off , &clip)) { + if (!PyArg_ParseTuple(args, + "O!O!O!O!O!|i:intersect_ray_tri", + &vector_Type, &vec1, + &vector_Type, &vec2, + &vector_Type, &vec3, + &vector_Type, &ray, + &vector_Type, &ray_off, &clip)) + { return NULL; } if (vec1->size != 3 || vec2->size != 3 || vec3->size != 3 || ray->size != 3 || ray_off->size != 3) { @@ -94,8 +101,14 @@ static PyObject *M_Geometry_intersect_ray_tri(PyObject *UNUSED(self), PyObject* return NULL; } - if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(ray) == -1 || BaseMath_ReadCallback(ray_off) == -1) + if ( BaseMath_ReadCallback(vec1) == -1 || + BaseMath_ReadCallback(vec2) == -1 || + BaseMath_ReadCallback(vec3) == -1 || + BaseMath_ReadCallback(ray) == -1 || + BaseMath_ReadCallback(ray_off) == -1) + { return NULL; + } copy_v3_v3(v1, vec1->vec); copy_v3_v3(v2, vec2->vec); @@ -173,17 +186,28 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject VectorObject *vec1, *vec2, *vec3, *vec4; float v1[3], v2[3], v3[3], v4[3], i1[3], i2[3]; - if (!PyArg_ParseTuple(args, "O!O!O!O!:intersect_line_line", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &vec4)) { + if (!PyArg_ParseTuple(args, "O!O!O!O!:intersect_line_line", + &vector_Type, &vec1, + &vector_Type, &vec2, + &vector_Type, &vec3, + &vector_Type, &vec4)) + { return NULL; } + if (vec1->size != vec2->size || vec1->size != vec3->size || vec3->size != vec2->size) { PyErr_SetString(PyExc_ValueError, "vectors must be of the same size"); return NULL; } - if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(vec4) == -1) + if ( BaseMath_ReadCallback(vec1) == -1 || + BaseMath_ReadCallback(vec2) == -1 || + BaseMath_ReadCallback(vec3) == -1 || + BaseMath_ReadCallback(vec4) == -1) + { return NULL; + } if (vec1->size == 3 || vec1->size == 2) { int result; @@ -257,9 +281,14 @@ static PyObject *M_Geometry_normal(PyObject *UNUSED(self), PyObject* args) float n[3]; if (PyTuple_GET_SIZE(args) == 3) { - if (!PyArg_ParseTuple(args, "O!O!O!:normal", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3)) { + if (!PyArg_ParseTuple(args, "O!O!O!:normal", + &vector_Type, &vec1, + &vector_Type, &vec2, + &vector_Type, &vec3)) + { return NULL; } + if (vec1->size != vec2->size || vec1->size != vec3->size) { PyErr_SetString(PyExc_ValueError, "vectors must be of the same size"); @@ -271,13 +300,22 @@ static PyObject *M_Geometry_normal(PyObject *UNUSED(self), PyObject* args) return NULL; } - if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1) + if ( BaseMath_ReadCallback(vec1) == -1 || + BaseMath_ReadCallback(vec2) == -1 || + BaseMath_ReadCallback(vec3) == -1) + { return NULL; + } normal_tri_v3(n, vec1->vec, vec2->vec, vec3->vec); } else { - if (!PyArg_ParseTuple(args, "O!O!O!O!:normal", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &vec4)) { + if (!PyArg_ParseTuple(args, "O!O!O!O!:normal", + &vector_Type, &vec1, + &vector_Type, &vec2, + &vector_Type, &vec3, + &vector_Type, &vec4)) + { return NULL; } if (vec1->size != vec2->size || vec1->size != vec3->size || vec1->size != vec4->size) { @@ -291,8 +329,13 @@ static PyObject *M_Geometry_normal(PyObject *UNUSED(self), PyObject* args) return NULL; } - if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(vec4) == -1) + if ( BaseMath_ReadCallback(vec1) == -1 || + BaseMath_ReadCallback(vec2) == -1 || + BaseMath_ReadCallback(vec3) == -1 || + BaseMath_ReadCallback(vec4) == -1) + { return NULL; + } normal_quad_v3(n, vec1->vec, vec2->vec, vec3->vec, vec4->vec); } @@ -319,7 +362,11 @@ static PyObject *M_Geometry_area_tri(PyObject *UNUSED(self), PyObject* args) { VectorObject *vec1, *vec2, *vec3; - if (!PyArg_ParseTuple(args, "O!O!O!:area_tri", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3)) { + if (!PyArg_ParseTuple(args, "O!O!O!:area_tri", + &vector_Type, &vec1, + &vector_Type, &vec2, + &vector_Type, &vec3)) + { return NULL; } @@ -329,8 +376,12 @@ static PyObject *M_Geometry_area_tri(PyObject *UNUSED(self), PyObject* args) return NULL; } - if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1) + if ( BaseMath_ReadCallback(vec1) == -1 || + BaseMath_ReadCallback(vec2) == -1 || + BaseMath_ReadCallback(vec3) == -1) + { return NULL; + } if (vec1->size == 3) { return PyFloat_FromDouble(area_tri_v3(vec1->vec, vec2->vec, vec3->vec)); @@ -367,16 +418,21 @@ static PyObject *M_Geometry_intersect_line_line_2d(PyObject *UNUSED(self), PyObj VectorObject *line_a1, *line_a2, *line_b1, *line_b2; float vi[2]; if (!PyArg_ParseTuple(args, "O!O!O!O!:intersect_line_line_2d", - &vector_Type, &line_a1, - &vector_Type, &line_a2, - &vector_Type, &line_b1, - &vector_Type, &line_b2) - ) { + &vector_Type, &line_a1, + &vector_Type, &line_a2, + &vector_Type, &line_b1, + &vector_Type, &line_b2)) + { return NULL; } - if (BaseMath_ReadCallback(line_a1) == -1 || BaseMath_ReadCallback(line_a2) == -1 || BaseMath_ReadCallback(line_b1) == -1 || BaseMath_ReadCallback(line_b2) == -1) + if ( BaseMath_ReadCallback(line_a1) == -1 || + BaseMath_ReadCallback(line_a2) == -1 || + BaseMath_ReadCallback(line_b1) == -1 || + BaseMath_ReadCallback(line_b2) == -1) + { return NULL; + } if (isect_seg_seg_v2_point(line_a1->vec, line_a2->vec, line_b1->vec, line_b2->vec, vi) == 1) { return newVectorObject(vi, 2, Py_NEW, NULL); @@ -411,20 +467,20 @@ static PyObject *M_Geometry_intersect_line_plane(PyObject *UNUSED(self), PyObjec int no_flip= 0; float isect[3]; if (!PyArg_ParseTuple(args, "O!O!O!O!|i:intersect_line_plane", - &vector_Type, &line_a, - &vector_Type, &line_b, - &vector_Type, &plane_co, - &vector_Type, &plane_no, - &no_flip) - ) { + &vector_Type, &line_a, + &vector_Type, &line_b, + &vector_Type, &plane_co, + &vector_Type, &plane_no, + &no_flip)) + { return NULL; } if ( BaseMath_ReadCallback(line_a) == -1 || BaseMath_ReadCallback(line_b) == -1 || BaseMath_ReadCallback(plane_co) == -1 || - BaseMath_ReadCallback(plane_no) == -1 - ) { + BaseMath_ReadCallback(plane_no) == -1) + { return NULL; } @@ -471,18 +527,18 @@ static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObje float isect_b[3]; if (!PyArg_ParseTuple(args, "O!O!O!f|i:intersect_line_sphere", - &vector_Type, &line_a, - &vector_Type, &line_b, - &vector_Type, &sphere_co, - &sphere_radius, &clip) - ) { + &vector_Type, &line_a, + &vector_Type, &line_b, + &vector_Type, &sphere_co, + &sphere_radius, &clip)) + { return NULL; } - if ( BaseMath_ReadCallback(line_a) == -1 || + if ( BaseMath_ReadCallback(line_a) == -1 || BaseMath_ReadCallback(line_b) == -1 || - BaseMath_ReadCallback(sphere_co) == -1 - ) { + BaseMath_ReadCallback(sphere_co) == -1) + { return NULL; } @@ -551,18 +607,18 @@ static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyO float isect_b[3]; if (!PyArg_ParseTuple(args, "O!O!O!f|i:intersect_line_sphere_2d", - &vector_Type, &line_a, - &vector_Type, &line_b, - &vector_Type, &sphere_co, - &sphere_radius, &clip) - ) { + &vector_Type, &line_a, + &vector_Type, &line_b, + &vector_Type, &sphere_co, + &sphere_radius, &clip)) + { return NULL; } if ( BaseMath_ReadCallback(line_a) == -1 || BaseMath_ReadCallback(line_b) == -1 || - BaseMath_ReadCallback(sphere_co) == -1 - ) { + BaseMath_ReadCallback(sphere_co) == -1) + { return NULL; } else { @@ -617,16 +673,20 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec PyObject *ret; if (!PyArg_ParseTuple(args, "O!O!O!:intersect_point_line", - &vector_Type, &pt, - &vector_Type, &line_1, - &vector_Type, &line_2) - ) { + &vector_Type, &pt, + &vector_Type, &line_1, + &vector_Type, &line_2)) + { return NULL; } - - if (BaseMath_ReadCallback(pt) == -1 || BaseMath_ReadCallback(line_1) == -1 || BaseMath_ReadCallback(line_2) == -1) + + if ( BaseMath_ReadCallback(pt) == -1 || + BaseMath_ReadCallback(line_1) == -1 || + BaseMath_ReadCallback(line_2) == -1) + { return NULL; - + } + /* accept 2d verts */ if (pt->size==3) { copy_v3_v3(pt_in, pt->vec);} else { pt_in[2]=0.0; copy_v2_v2(pt_in, pt->vec); } @@ -666,17 +726,22 @@ static PyObject *M_Geometry_intersect_point_tri_2d(PyObject *UNUSED(self), PyObj VectorObject *pt_vec, *tri_p1, *tri_p2, *tri_p3; if (!PyArg_ParseTuple(args, "O!O!O!O!:intersect_point_tri_2d", - &vector_Type, &pt_vec, - &vector_Type, &tri_p1, - &vector_Type, &tri_p2, - &vector_Type, &tri_p3) - ) { + &vector_Type, &pt_vec, + &vector_Type, &tri_p1, + &vector_Type, &tri_p2, + &vector_Type, &tri_p3)) + { return NULL; } - if (BaseMath_ReadCallback(pt_vec) == -1 || BaseMath_ReadCallback(tri_p1) == -1 || BaseMath_ReadCallback(tri_p2) == -1 || BaseMath_ReadCallback(tri_p3) == -1) + if ( BaseMath_ReadCallback(pt_vec) == -1 || + BaseMath_ReadCallback(tri_p1) == -1 || + BaseMath_ReadCallback(tri_p2) == -1 || + BaseMath_ReadCallback(tri_p3) == -1) + { return NULL; - + } + return PyLong_FromLong(isect_point_tri_v2(pt_vec->vec, tri_p1->vec, tri_p2->vec, tri_p3->vec)); } @@ -702,18 +767,24 @@ static PyObject *M_Geometry_intersect_point_quad_2d(PyObject *UNUSED(self), PyOb VectorObject *pt_vec, *quad_p1, *quad_p2, *quad_p3, *quad_p4; if (!PyArg_ParseTuple(args, "O!O!O!O!O!:intersect_point_quad_2d", - &vector_Type, &pt_vec, - &vector_Type, &quad_p1, - &vector_Type, &quad_p2, - &vector_Type, &quad_p3, - &vector_Type, &quad_p4) - ) { + &vector_Type, &pt_vec, + &vector_Type, &quad_p1, + &vector_Type, &quad_p2, + &vector_Type, &quad_p3, + &vector_Type, &quad_p4)) + { return NULL; } - - if (BaseMath_ReadCallback(pt_vec) == -1 || BaseMath_ReadCallback(quad_p1) == -1 || BaseMath_ReadCallback(quad_p2) == -1 || BaseMath_ReadCallback(quad_p3) == -1 || BaseMath_ReadCallback(quad_p4) == -1) + + if ( BaseMath_ReadCallback(pt_vec) == -1 || + BaseMath_ReadCallback(quad_p1) == -1 || + BaseMath_ReadCallback(quad_p2) == -1 || + BaseMath_ReadCallback(quad_p3) == -1 || + BaseMath_ReadCallback(quad_p4) == -1) + { return NULL; - + } + return PyLong_FromLong(isect_point_quad_v2(pt_vec->vec, quad_p1->vec, quad_p2->vec, quad_p3->vec, quad_p4->vec)); } @@ -738,8 +809,8 @@ static PyObject *M_Geometry_distance_point_to_plane(PyObject *UNUSED(self), PyOb if (!PyArg_ParseTuple(args, "O!O!O!:distance_point_to_plane", &vector_Type, &pt, &vector_Type, &plene_co, - &vector_Type, &plane_no) - ) { + &vector_Type, &plane_no)) + { return NULL; } @@ -783,14 +854,14 @@ static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObje float vec[3]; if (!PyArg_ParseTuple(args, "O!O!O!O!O!O!O!:barycentric_transform", - &vector_Type, &vec_pt, - &vector_Type, &vec_t1_src, - &vector_Type, &vec_t2_src, - &vector_Type, &vec_t3_src, - &vector_Type, &vec_t1_tar, - &vector_Type, &vec_t2_tar, - &vector_Type, &vec_t3_tar) - ) { + &vector_Type, &vec_pt, + &vector_Type, &vec_t1_src, + &vector_Type, &vec_t2_src, + &vector_Type, &vec_t3_src, + &vector_Type, &vec_t1_tar, + &vector_Type, &vec_t2_tar, + &vector_Type, &vec_t3_tar)) + { return NULL; } @@ -850,11 +921,11 @@ static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject* if (!PyArg_ParseTuple(args, "O!O!O!O!i:interpolate_bezier", - &vector_Type, &vec_k1, - &vector_Type, &vec_h1, - &vector_Type, &vec_h2, - &vector_Type, &vec_k2, &resolu) - ) { + &vector_Type, &vec_k1, + &vector_Type, &vec_h1, + &vector_Type, &vec_h2, + &vector_Type, &vec_k2, &resolu)) + { return NULL; } @@ -864,8 +935,13 @@ static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject* return NULL; } - if (BaseMath_ReadCallback(vec_k1) == -1 || BaseMath_ReadCallback(vec_h1) == -1 || BaseMath_ReadCallback(vec_k2) == -1 || BaseMath_ReadCallback(vec_h2) == -1) + if ( BaseMath_ReadCallback(vec_k1) == -1 || + BaseMath_ReadCallback(vec_h1) == -1 || + BaseMath_ReadCallback(vec_k2) == -1 || + BaseMath_ReadCallback(vec_h2) == -1) + { return NULL; + } dims= MAX4(vec_k1->size, vec_h1->size, vec_h2->size, vec_k2->size); |