Fix T46503: Snap scale fails using corner pivot

This commit is contained in:
Campbell Barton 2015-10-16 14:45:05 +11:00
parent c62468aabb
commit 2f35217849
Notes: blender-bot 2023-02-14 11:18:07 +01:00
Referenced by issue #46503, snap seems broken when scaling
1 changed files with 17 additions and 6 deletions

View File

@ -85,6 +85,8 @@
#define TRANSFORM_DIST_MAX_PX 1000.0f
#define TRANSFORM_SNAP_MAX_PX 100.0f
#define TRANSFORM_DIST_INVALID NAN_FLT
/* use half of flt-max so we can scale up without an exception */
/********************* PROTOTYPES ***********************/
@ -897,7 +899,10 @@ static float ResizeBetween(TransInfo *t, const float p1[3], const float p2[3])
len_d1 = len_v3(d1);
return len_d1 != 0.0f ? len_v3(d2) / len_d1 : 1;
/* Use 'invalid' dist when `center == p1` (after projecting),
* in this case scale will _never_ move the point in relation to the center,
* so it makes no sense to take it into account when scaling. see: T46503 */
return len_d1 != 0.0f ? len_v3(d2) / len_d1 : TRANSFORM_DIST_INVALID;
}
/********************** CALC **************************/
@ -1177,8 +1182,10 @@ static void TargetSnapClosest(TransInfo *t)
mul_m4_v3(td->ext->obmat, loc);
dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint);
if (closest == NULL || fabsf(dist) < fabsf(t->tsnap.dist)) {
if ((dist != TRANSFORM_DIST_INVALID) &&
(closest == NULL || fabsf(dist) < fabsf(t->tsnap.dist)))
{
copy_v3_v3(t->tsnap.snapTarget, loc);
closest = td;
t->tsnap.dist = dist;
@ -1193,8 +1200,10 @@ static void TargetSnapClosest(TransInfo *t)
copy_v3_v3(loc, td->center);
dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint);
if (closest == NULL || fabsf(dist) < fabsf(t->tsnap.dist)) {
if ((dist != TRANSFORM_DIST_INVALID) &&
(closest == NULL || fabsf(dist) < fabsf(t->tsnap.dist)))
{
copy_v3_v3(t->tsnap.snapTarget, loc);
closest = td;
t->tsnap.dist = dist;
@ -1217,7 +1226,9 @@ static void TargetSnapClosest(TransInfo *t)
dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint);
if (closest == NULL || fabsf(dist) < fabsf(t->tsnap.dist)) {
if ((dist != TRANSFORM_DIST_INVALID) &&
(closest == NULL || fabsf(dist) < fabsf(t->tsnap.dist)))
{
copy_v3_v3(t->tsnap.snapTarget, loc);
closest = td;
t->tsnap.dist = dist;