Transform: simplify proportional distance algorithm

The `TD_NOTCONNECTED` flag is not set in all cases.

In some cases, such as Meshes, the `FLT_MAX` value better determines
when the `TrasData` is not "connected".

Therefore, this commit removes the `TD_NOTCONNECTED` flag and adapts
the code to rely on the `FLT_MAX` value instead.

These TrasDatas shouldn't even be created in these cases.
This commit is contained in:
Germano Cavalcante 2023-08-03 12:34:04 -03:00
parent 2786680ad8
commit 87d04de418
7 changed files with 16 additions and 22 deletions

@ -434,7 +434,7 @@ void calc_distanceCurveVerts(TransData *head, TransData *tail, bool cyclic)
next_td = head;
}
if (next_td != nullptr && !(next_td->flag & TD_NOTCONNECTED)) {
if (next_td != nullptr) {
sub_v3_v3v3(vec, next_td->center, td->center);
mul_m3_v3(head->mtx, vec);
dist = len_v3(vec) + td->dist;
@ -454,7 +454,7 @@ void calc_distanceCurveVerts(TransData *head, TransData *tail, bool cyclic)
next_td = tail;
}
if (next_td != nullptr && !(next_td->flag & TD_NOTCONNECTED)) {
if (next_td != nullptr) {
sub_v3_v3v3(vec, next_td->center, td->center);
mul_m3_v3(head->mtx, vec);
dist = len_v3(vec) + td->dist;

@ -76,6 +76,12 @@ static void createTransCurveVerts(bContext * /*C*/, TransInfo *t)
* Needed for #transform_around_single_fallback_ex. */
int data_len_all_pt = 0;
const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
const bool is_prop_connected = (t->flag & T_PROP_CONNECTED) != 0;
View3D *v3d = static_cast<View3D *>(t->view);
short hide_handles = (v3d != nullptr) ? (v3d->overlay.handle_display == CURVE_HANDLE_NONE) :
false;
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
Curve *cu = static_cast<Curve *>(tc->obedit->data);
BLI_assert(cu->editnurb != nullptr);
@ -84,11 +90,6 @@ static void createTransCurveVerts(bContext * /*C*/, TransInfo *t)
int a;
int count = 0, countsel = 0;
int count_pt = 0, countsel_pt = 0;
const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
const bool is_prop_connected = (t->flag & T_PROP_CONNECTED) != 0;
View3D *v3d = static_cast<View3D *>(t->view);
short hide_handles = (v3d != nullptr) ? (v3d->overlay.handle_display == CURVE_HANDLE_NONE) :
false;
/* count total of vertices, check identical as in 2nd loop for making transdata! */
ListBase *nurbs = BKE_curve_editNurbs_get(cu);
@ -168,10 +169,6 @@ static void createTransCurveVerts(bContext * /*C*/, TransInfo *t)
BezTriple *bezt;
BPoint *bp;
int a;
const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
View3D *v3d = static_cast<View3D *>(t->view);
short hide_handles = (v3d != nullptr) ? (v3d->overlay.handle_display == CURVE_HANDLE_NONE) :
false;
bool use_around_origins_for_handles_test = ((t->around == V3D_AROUND_LOCAL_ORIGINS) &&
transform_mode_use_local_origins(t));
@ -394,13 +391,15 @@ static void createTransCurveVerts(bContext * /*C*/, TransInfo *t)
}
if (is_prop_edit && head != tail) {
tail -= 1;
if (!has_any_selected) {
if (is_prop_connected && has_any_selected) {
bool cyclic = (nu->flagu & CU_NURB_CYCLIC) != 0;
calc_distanceCurveVerts(head, tail, cyclic);
}
else {
for (td = head; td <= tail; td++) {
td->flag |= TD_NOTCONNECTED;
td->dist = FLT_MAX;
}
}
bool cyclic = (nu->flagu & CU_NURB_CYCLIC) != 0;
calc_distanceCurveVerts(head, tail, cyclic);
}
/* TODO: in the case of tilt and radius we can also avoid allocating the

@ -1658,7 +1658,6 @@ static void createTransEditVerts(bContext * /*C*/, TransInfo *t)
tob->dist = dists[a];
}
else {
tob->flag |= TD_NOTCONNECTED;
tob->dist = FLT_MAX;
}
}

@ -227,7 +227,6 @@ static void createTransMeshSkin(bContext * /*C*/, TransInfo *t)
td->dist = dists[a];
}
else {
td->flag |= TD_NOTCONNECTED;
td->dist = FLT_MAX;
}
}

@ -226,7 +226,6 @@ static void createTransMeshVertCData(bContext * /*C*/, TransInfo *t)
td->dist = dists[a];
}
else {
td->flag |= TD_NOTCONNECTED;
td->dist = FLT_MAX;
}
}

@ -142,7 +142,7 @@ struct TransData {
enum {
TD_SELECTED = 1 << 0,
TD_USEQUAT = 1 << 1,
TD_NOTCONNECTED = 1 << 2,
/* TD_NOTCONNECTED = 1 << 2, */
/** Used for scaling of #MetaElem.rad */
TD_SINGLESIZE = 1 << 3,
/** Scale relative to individual element center. */

@ -1256,9 +1256,7 @@ void calculatePropRatio(TransInfo *t)
if (td->flag & TD_SELECTED) {
td->factor = 1.0f;
}
else if ((connected && (td->flag & TD_NOTCONNECTED || td->dist > t->prop_size)) ||
(connected == 0 && td->rdist > t->prop_size))
{
else if ((connected ? td->dist : td->rdist) > t->prop_size) {
td->factor = 0.0f;
restoreElement(td);
}