fix [#30897] UVEditor: Snap Cursor to Selected

was writing the 3rd component of a 2D vector.
This commit is contained in:
Campbell Barton
2012-04-11 07:47:09 +00:00
parent ff6867a768
commit 9ae0523921
3 changed files with 18 additions and 18 deletions

View File

@@ -154,6 +154,7 @@ void interp_v4_v4v4v4(float p[4], const float v1[4], const float v2[4], const fl
void interp_v4_v4v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float v4[4], const float w[4]);
void mid_v3_v3v3(float r[3], const float a[3], const float b[3]);
void mid_v2_v2v2(float r[2], const float a[2], const float b[2]);
/********************************* Comparison ********************************/

View File

@@ -109,6 +109,12 @@ void mid_v3_v3v3(float v[3], const float v1[3], const float v2[3])
v[2] = 0.5f * (v1[2] + v2[2]);
}
void mid_v2_v2v2(float v[2], const float v1[2], const float v2[2])
{
v[0] = 0.5f * (v1[0] + v2[0]);
v[1] = 0.5f * (v1[1] + v2[1]);
}
/********************************** Angles ***********************************/
/* Return the angle in radians between vecs 1-2 and 2-3 in radians

View File

@@ -614,7 +614,7 @@ int ED_uvedit_minmax(Scene *scene, Image *ima, Object *obedit, float *min, float
return sel;
}
static int ED_uvedit_median(Scene *scene, Image *ima, Object *obedit, float co[3])
static int ED_uvedit_median(Scene *scene, Image *ima, Object *obedit, float co[2])
{
BMEditMesh *em = BMEdit_FromObject(obedit);
BMFace *efa;
@@ -624,7 +624,7 @@ static int ED_uvedit_median(Scene *scene, Image *ima, Object *obedit, float co[3
MLoopUV *luv;
unsigned int sel= 0;
zero_v3(co);
zero_v2(co);
BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) {
tf= CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
if (!uvedit_face_visible(scene, ima, efa, tf))
@@ -639,36 +639,29 @@ static int ED_uvedit_median(Scene *scene, Image *ima, Object *obedit, float co[3
}
}
mul_v3_fl(co, 1.0f/(float)sel);
mul_v2_fl(co, 1.0f/(float)sel);
return (sel != 0);
}
static int uvedit_center(Scene *scene, Image *ima, Object *obedit, float *cent, char mode)
static int uvedit_center(Scene *scene, Image *ima, Object *obedit, float cent[2], char mode)
{
float min[2], max[2];
int change= 0;
int change = FALSE;
if (mode==V3D_CENTER) { /* bounding box */
if (mode == V3D_CENTER) { /* bounding box */
float min[2], max[2];
if (ED_uvedit_minmax(scene, ima, obedit, min, max)) {
change = 1;
cent[0]= (min[0]+max[0])/2.0f;
cent[1]= (min[1]+max[1])/2.0f;
mid_v2_v2v2(cent, min, max);
change = TRUE;
}
}
else {
if (ED_uvedit_median(scene, ima, obedit, cent)) {
change = 1;
change = TRUE;
}
}
if (change) {
return 1;
}
return 0;
return change;
}
/************************** find nearest ****************************/