diff options
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 7 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_knife.c | 6 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_select.c | 16 | ||||
-rw-r--r-- | source/blender/editors/mesh/mesh_intern.h | 3 |
4 files changed, 10 insertions, 22 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index cd726179f56..74abd7e8c7e 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -1453,9 +1453,16 @@ 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]) { 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' diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index babb79acb05..014eec744ac 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -1595,12 +1595,10 @@ static KnifeEdge *knife_find_closest_edge(KnifeTool_OpData *kcd, float p[3], flo 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) { diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index c159b50b077..3335f03ac17 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -450,20 +450,6 @@ BMVert *EDBM_vert_find_nearest(ViewContext *vc, float *r_dist, const short sel, } } -/* 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 @@ static void findnearestedge__doClosest(void *userData, BMEdge *eed, const float 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]); diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index 8e63bd74ece..e335c909e8e 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -80,9 +80,6 @@ int EDBM_op_finish(struct BMEditMesh *em, struct BMOperator *bmop, 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); |