de-duplicate labda_PdistVL2Dfl() & line_point_factor_v2()

This commit is contained in:
Campbell Barton
2012-12-10 06:14:43 +00:00
parent 27ddd17ef9
commit bc94b8300e
4 changed files with 10 additions and 22 deletions

View File

@@ -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'

View File

@@ -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) {

View File

@@ -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]);

View File

@@ -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);