Revision: 37821
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37821
Author:   campbellbarton
Date:     2011-06-26 08:07:09 +0000 (Sun, 26 Jun 2011)
Log Message:
-----------
renamed math functions and made public
 lambda_cp_line --> line_point_factor_v3
 lambda_cp_line2 --> line_point_factor_v2

correction to previous commit function name
 isect_seg_sphere_v3 --> isect_line_sphere_v3
 ... since its not clipped.

added a clip argument to the python version of the function.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_geom.h
    trunk/blender/source/blender/blenlib/intern/math_geom.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/python/generic/mathutils_geometry.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h        2011-06-26 
07:21:19 UTC (rev 37820)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h        2011-06-26 
08:07:09 UTC (rev 37821)
@@ -66,6 +66,9 @@
 float closest_to_line_v2(float r[2], const float p[2], const float l1[2], 
const float l2[2]);
 void closest_to_line_segment_v3(float r[3], const float p[3], const float 
l1[3], const float l2[3]);
 
+float line_point_factor_v3(const float p[3], const float l1[3], const float 
l2[3]);
+float line_point_factor_v2(const float p[2], const float l1[2], const float 
l2[2]);
+
 /******************************* Intersection ********************************/
 
 /* TODO int return value consistency */
@@ -78,8 +81,8 @@
 
 int isect_line_line_v2(const float a1[2], const float a2[2], const float 
b1[2], const float b2[2]);
 int isect_line_line_v2_int(const int a1[2], const int a2[2], const int b1[2], 
const int b2[2]);
+int isect_line_sphere_v3(const float l1[3], const float l2[3], const float 
sp[3], const float r, float r_p1[3], float r_p2[3]);
 int isect_seg_seg_v2_point(const float v1[2], const float v2[2], const float 
v3[2], const float v4[2], float vi[2]);
-int isect_seg_sphere_v3(const float l1[3], const float l2[3], const float 
sp[3], const float r, float r_p1[3], float r_p2[3]);
 
 /* Returns the number of point of interests
  * 0 - lines are colinear

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c     2011-06-26 
07:21:19 UTC (rev 37820)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c     2011-06-26 
08:07:09 UTC (rev 37821)
@@ -37,8 +37,6 @@
 #include "BLI_memarena.h"
 #include "BLI_utildefines.h"
 
-static float lambda_cp_line(const float p[3], const float l1[3], const float 
l2[3]);
-
 /********************************** Polygons *********************************/
 
 void cent_tri_v3(float cent[3], const float v1[3], const float v2[3], const 
float v3[3])
@@ -349,9 +347,9 @@
        return -1;
 }
 
-int isect_seg_sphere_v3(const float l1[3], const float l2[3],
-                        const float sp[3], const float r,
-                        float r_p1[3], float r_p2[3])
+int isect_line_sphere_v3(const float l1[3], const float l2[3],
+                         const float sp[3], const float r,
+                         float r_p1[3], float r_p2[3])
 {
        /* l1:         coordinates (point of line)
         * l2:         coordinates (point of line)
@@ -741,7 +739,7 @@
 
                add_v3_v3v3(l1_plane, l1, p_no);
 
-               dist = lambda_cp_line(plane_co, l1, l1_plane);
+               dist = line_point_factor_v3(plane_co, l1, l1_plane);
 
                /* treat line like a ray, when 'no_flip' is set */
                if(no_flip && dist < 0.0f) {
@@ -1191,7 +1189,7 @@
 }
 
 /* little sister we only need to know lambda */
-static float lambda_cp_line(const float p[3], const float l1[3], const float 
l2[3])
+float line_point_factor_v3(const float p[3], const float l1[3], const float 
l2[3])
 {
        float h[3],u[3];
        sub_v3_v3v3(u, l2, l1);
@@ -1199,6 +1197,14 @@
        return(dot_v3v3(u,h)/dot_v3v3(u,u));
 }
 
+float line_point_factor_v2(const float p[2], const float l1[2], const float 
l2[2])
+{
+       float h[2], u[2];
+       sub_v2_v2v2(u, l2, l1);
+       sub_v2_v2v2(h, p, l1);
+       return(dot_v2v2(u, h)/dot_v2v2(u, u));
+}
+
 /* Similar to LineIntersectsTriangleUV, except it operates on a quad and in 
2d, assumes point is in quad */
 void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float 
v2[2], const float v3[2], const float pt[2], float *uv)
 {

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c     
2011-06-26 07:21:19 UTC (rev 37820)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c     
2011-06-26 08:07:09 UTC (rev 37821)
@@ -1174,25 +1174,6 @@
 #endif // PROJ_DEBUG_NOSEAMBLEED
 
 
-/* TODO - move to math_geom.c */
-
-/* little sister we only need to know lambda */
-#ifndef PROJ_DEBUG_NOSEAMBLEED
-static float lambda_cp_line2(const float p[2], const float l1[2], const float 
l2[2])
-{
-       float h[2], u[2];
-       
-       u[0] = l2[0] - l1[0];
-       u[1] = l2[1] - l1[1];
-
-       h[0] = p[0] - l1[0];
-       h[1] = p[1] - l1[1];
-       
-       return(dot_v2v2(u, h)/dot_v2v2(u, u));
-}
-#endif // PROJ_DEBUG_NOSEAMBLEED
-
-
 /* Converts a UV location to a 3D screenspace location
  * Takes a 'uv' and 3 UV coords, and sets the values of pixelScreenCo
  * 
@@ -2518,9 +2499,9 @@
                                                                                
*/
                                                                                
                                                                                
/* Since this is a seam we need to work out where on the line this pixel is */
-                                                                               
//fac = lambda_cp_line2(uv, uv_seam_quad[0], uv_seam_quad[1]);
+                                                                               
//fac = line_point_factor_v2(uv, uv_seam_quad[0], uv_seam_quad[1]);
                                                                                
-                                                                               
fac = lambda_cp_line2(uv, seam_subsection[0], seam_subsection[1]);
+                                                                               
fac = line_point_factor_v2(uv, seam_subsection[0], seam_subsection[1]);
                                                                                
if (fac < 0.0f)         { VECCOPY(pixelScreenCo, edge_verts_inset_clip[0]); }
                                                                                
else if (fac > 1.0f)    { VECCOPY(pixelScreenCo, edge_verts_inset_clip[1]); }
                                                                                
else                            { interp_v3_v3v3(pixelScreenCo, 
edge_verts_inset_clip[0], edge_verts_inset_clip[1], fac); }

Modified: trunk/blender/source/blender/python/generic/mathutils_geometry.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_geometry.c    
2011-06-26 07:21:19 UTC (rev 37820)
+++ trunk/blender/source/blender/python/generic/mathutils_geometry.c    
2011-06-26 08:07:09 UTC (rev 37821)
@@ -522,7 +522,7 @@
        VectorObject *line_a, *line_b, *plane_co, *plane_no;
        int no_flip= 0;
        float isect[3];
-       if(!PyArg_ParseTuple(args, "O!O!O!O!|i:intersect_line_line_2d",
+       if(!PyArg_ParseTuple(args, "O!O!O!O!|i:intersect_line_plane",
          &vector_Type, &line_a,
          &vector_Type, &line_b,
          &vector_Type, &plane_co,
@@ -555,7 +555,7 @@
 
 
 PyDoc_STRVAR(M_Geometry_intersect_line_sphere_doc,
-".. function:: intersect_line_sphere(line_a, line_b, sphere_co, 
sphere_radius)\n"
+".. function:: intersect_line_sphere(line_a, line_b, sphere_co, sphere_radius, 
clip=True)\n"
 "\n"
 "   Takes a lines (as 2 vectors), a sphere as a point and a radius and\n"
 "   returns the intersection\n"
@@ -576,15 +576,17 @@
        PyObject *ret;
        VectorObject *line_a, *line_b, *sphere_co;
        float sphere_radius;
+       int clip= TRUE;
+       float lambda;
 
        float isect_a[3];
        float isect_b[3];
 
-       if(!PyArg_ParseTuple(args, "O!O!O!f:intersect_line_sphere",
+       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)
+         &sphere_radius, &clip)
        ) {
                return NULL;
        }
@@ -603,14 +605,33 @@
 
        ret= PyTuple_New(2);
 
-       switch(isect_seg_sphere_v3(line_a->vec, line_b->vec, sphere_co->vec, 
sphere_radius, isect_a, isect_b)) {
+       switch(isect_line_sphere_v3(line_a->vec, line_b->vec, sphere_co->vec, 
sphere_radius, isect_a, isect_b)) {
        case 1:
-               PyTuple_SET_ITEM(ret, 0,  newVectorObject(isect_a, 3, Py_NEW, 
NULL));
+               /* ret 1 */
+               if(!clip || (((lambda= line_point_factor_v3(isect_a, 
line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f))) {
+                       PyTuple_SET_ITEM(ret, 0,  newVectorObject(isect_a, 3, 
Py_NEW, NULL));
+               }
+               else {
+                       PyTuple_SET_ITEM(ret, 0,  Py_None); Py_INCREF(Py_None);
+               }
+               /* ret 2 */
                PyTuple_SET_ITEM(ret, 1,  Py_None); Py_INCREF(Py_None);
                break;
        case 2:
-               PyTuple_SET_ITEM(ret, 0,  newVectorObject(isect_a, 3, Py_NEW, 
NULL));
-               PyTuple_SET_ITEM(ret, 1,  newVectorObject(isect_b, 3, Py_NEW, 
NULL));
+               /* ret 1 */
+               if(!clip || (((lambda= line_point_factor_v3(isect_a, 
line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f))) {
+                       PyTuple_SET_ITEM(ret, 0,  newVectorObject(isect_a, 3, 
Py_NEW, NULL));
+               }
+               else {
+                       PyTuple_SET_ITEM(ret, 0,  Py_None); Py_INCREF(Py_None);
+               }
+               /* ret 2 */
+               if(!clip || (((lambda= line_point_factor_v3(isect_b, 
line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f))) {
+                       PyTuple_SET_ITEM(ret, 1,  newVectorObject(isect_b, 3, 
Py_NEW, NULL));
+               }
+               else {
+                       PyTuple_SET_ITEM(ret, 1,  Py_None); Py_INCREF(Py_None);
+               }
                break;
        default:
                PyTuple_SET_ITEM(ret, 0,  Py_None); Py_INCREF(Py_None);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to