[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52835] trunk/blender/source/blender: de-duplicate labda_PdistVL2Dfl() & line_point_factor_v2()
Campbell Barton
ideasman42 at gmail.com
Mon Dec 10 07:14:50 CET 2012
Revision: 52835
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52835
Author: campbellbarton
Date: 2012-12-10 06:14:43 +0000 (Mon, 10 Dec 2012)
Log Message:
-----------
de-duplicate labda_PdistVL2Dfl() & line_point_factor_v2()
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/intern/math_geom.c
trunk/blender/source/blender/editors/mesh/editmesh_knife.c
trunk/blender/source/blender/editors/mesh/editmesh_select.c
trunk/blender/source/blender/editors/mesh/mesh_intern.h
Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c 2012-12-10 05:07:46 UTC (rev 52834)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c 2012-12-10 06:14:43 UTC (rev 52835)
@@ -1453,9 +1453,16 @@
float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2])
{
float h[2], u[2];
+ float dot;
sub_v2_v2v2(u, l2, l1);
sub_v2_v2v2(h, p, l1);
+#if 0
return (dot_v2v2(u, h) / dot_v2v2(u, u));
+#else
+ /* better check for zero */
+ dot = dot_v2v2(u, u);
+ return (dot != 0.0f) ? (dot_v2v2(u, h) / dot) : 0.0f;
+#endif
}
/* ensure the distance between these points is no greater then 'dist'
Modified: trunk/blender/source/blender/editors/mesh/editmesh_knife.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_knife.c 2012-12-10 05:07:46 UTC (rev 52834)
+++ trunk/blender/source/blender/editors/mesh/editmesh_knife.c 2012-12-10 06:14:43 UTC (rev 52835)
@@ -1595,12 +1595,10 @@
dis = dist_to_line_segment_v2(sco, kfe->v1->sco, kfe->v2->sco);
if (dis < curdis && dis < maxdist) {
if (kcd->vc.rv3d->rflag & RV3D_CLIPPING) {
- float labda = labda_PdistVL2Dfl(sco, kfe->v1->sco, kfe->v2->sco);
+ float labda = line_point_factor_v2(sco, kfe->v1->sco, kfe->v2->sco);
float vec[3];
- vec[0] = kfe->v1->cageco[0] + labda * (kfe->v2->cageco[0] - kfe->v1->cageco[0]);
- vec[1] = kfe->v1->cageco[1] + labda * (kfe->v2->cageco[1] - kfe->v1->cageco[1]);
- vec[2] = kfe->v1->cageco[2] + labda * (kfe->v2->cageco[2] - kfe->v1->cageco[2]);
+ interp_v3_v3v3(vec, kfe->v1->cageco, kfe->v2->cageco, labda);
mul_m4_v3(kcd->vc.obedit->obmat, vec);
if (ED_view3d_clipping_test(kcd->vc.rv3d, vec, TRUE) == 0) {
Modified: trunk/blender/source/blender/editors/mesh/editmesh_select.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_select.c 2012-12-10 05:07:46 UTC (rev 52834)
+++ trunk/blender/source/blender/editors/mesh/editmesh_select.c 2012-12-10 06:14:43 UTC (rev 52835)
@@ -450,20 +450,6 @@
}
}
-/* returns labda for closest distance v1 to line-piece v2 - v3 */
-float labda_PdistVL2Dfl(const float v1[2], const float v2[2], const float v3[2])
-{
- float rc[2], len;
-
- rc[0] = v3[0] - v2[0];
- rc[1] = v3[1] - v2[1];
- len = rc[0] * rc[0] + rc[1] * rc[1];
- if (len == 0.0f)
- return 0.0f;
-
- return (rc[0] * (v1[0] - v2[0]) + rc[1] * (v1[1] - v2[1])) / len;
-}
-
/* note; uses v3d, so needs active 3d window */
static void findnearestedge__doClosest(void *userData, BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2], int UNUSED(index))
{
@@ -478,7 +464,7 @@
if (distance < data->dist) {
if (data->vc.rv3d->rflag & RV3D_CLIPPING) {
- float labda = labda_PdistVL2Dfl(data->mval_fl, screen_co_a, screen_co_b);
+ float labda = line_point_factor_v2(data->mval_fl, screen_co_a, screen_co_b);
float vec[3];
vec[0] = eed->v1->co[0] + labda * (eed->v2->co[0] - eed->v1->co[0]);
Modified: trunk/blender/source/blender/editors/mesh/mesh_intern.h
===================================================================
--- trunk/blender/source/blender/editors/mesh/mesh_intern.h 2012-12-10 05:07:46 UTC (rev 52834)
+++ trunk/blender/source/blender/editors/mesh/mesh_intern.h 2012-12-10 06:14:43 UTC (rev 52835)
@@ -80,9 +80,6 @@
void EDBM_flag_disable_all(struct BMEditMesh *em, const char hflag);
void EDBM_stats_update(struct BMEditMesh *em);
-/* TODO, move to math_geometry.c */
-float labda_PdistVL2Dfl(const float v1[3], const float v2[3], const float v3[3]);
-
/* ******************** editface.c */
void MESH_OT_separate(struct wmOperatorType *ot);
More information about the Bf-blender-cvs
mailing list