Changeset View
Standalone View
source/blender/blenkernel/intern/deform.c
| Show First 20 Lines • Show All 439 Lines • ▼ Show 20 Lines | if (tot_weight > 0.0f) { | ||||
| CLAMP(dw->weight, 0.0f, 1.0f); | CLAMP(dw->weight, 0.0f, 1.0f); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void BKE_devert_normalize_gradient_paint(MDeformVert *dv, | |||||
campbellbarton: Regarding naming `BKE_devert_normalize_gradient_paint` isn't very informative, as it doesn't… | |||||
| MDeformWeight *dw, | |||||
campbellbartonUnsubmitted Done Inline ActionsNo reason to pass both dv and dw, as you can access both with dv. campbellbarton: No reason to pass both `dv` and `dw`, as you can access both with `dv`. | |||||
| const int vgroup_tot, | |||||
Not Done Inline ActionsFollow the naming style same as other variables in this module. tot is generally a prefix. ankitm: Follow the naming style same as other variables in this module. `tot` is generally a prefix. | |||||
| const int def_nr_lock) | |||||
Done Inline Actionsdef_nr_lock can be const too ankitm: def_nr_lock can be const too | |||||
| { | |||||
| if (dv->totweight == 0) { | |||||
| /*do nothing*/ | |||||
Not Done Inline ActionsMight want to early return here ? ankitm: Might want to early return here ? | |||||
| return; | |||||
| } | |||||
| if (dv->totweight == 1) { | |||||
| if ((dw->def_nr < vgroup_tot) && (def_nr_lock != dw->def_nr)) { | |||||
| dw->weight = 1; | |||||
Done Inline ActionsEarly return here, and then remove the else (and the scope & indent it created). ankitm: Early return here, and then remove the `else` (and the scope & indent it created). | |||||
| } | |||||
| return; | |||||
| } | |||||
Done Inline ActionsKeep the scope of i and other variables to the minimum. ankitm: Keep the scope of `i` and other variables to the minimum.
https://isocpp.github. | |||||
| MDeformWeight *dw_lock = NULL; | |||||
| unsigned int i; | |||||
Done Inline ActionsIs the first i in lock_iweight a typo? I'm not familiar with the code here, so ignore if I'm wrong here. ankitm: Is the first `i` in `lock_iweight` a typo? I'm not familiar with the code here, so ignore if… | |||||
Done Inline ActionsI keep code block related to calculation of vertex weight similar to other function (eg. see BKE_defvert_normalize_lock_single ,BKE_defvert_normalize_lock_map) . PratikPB2123: I keep code block related to calculation of vertex weight similar to other function (eg. see… | |||||
| float tot_weight = 0.0f; | |||||
| float lock_iweight = 1.0f; | |||||
| for (i = dv->totweight, dw = dv->dw; i != 0; i--, dw++) { | |||||
| if ((dw->def_nr < vgroup_tot)) { | |||||
| if (dw->def_nr != def_nr_lock) { | |||||
| tot_weight += dw->weight; | |||||
| } | |||||
| else { | |||||
| dw_lock = dw; | |||||
| lock_iweight = (1.0f - dw_lock->weight); | |||||
| CLAMP(lock_iweight, 0.0f, 1.0f); | |||||
| } | |||||
| } | |||||
| } | |||||
Done Inline ActionsComments should start with capital letter, and end with period. Same elsewhere. ankitm: Comments should start with capital letter, and end with period. Same elsewhere. | |||||
Done Inline Actionssee BKE_defvert_normalize_lock_single or BKE_defvert_normalize_lock_map PratikPB2123: see `BKE_defvert_normalize_lock_single` or `BKE_defvert_normalize_lock_map` | |||||
| if (tot_weight > 0.0f) { | |||||
| /* Paranoid, should be 1.0 but in case of float error clamp anyway */ | |||||
Done Inline Actionsankitm: `const float scalar`
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#con1-by… | |||||
| float scalar = (1.0f / tot_weight) * lock_iweight; | |||||
| for (i = dv->totweight, dw = dv->dw; i != 0; i--, dw++) { | |||||
| if (dw->def_nr < vgroup_tot) { | |||||
| if (dw != dw_lock) { | |||||
| dw->weight *= scalar; | |||||
| /* in case of division errors with very low weights */ | |||||
| CLAMP(dw->weight, 0.0f, 1.0f); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| void BKE_defvert_flip(MDeformVert *dvert, const int *flip_map, const int flip_map_len) | void BKE_defvert_flip(MDeformVert *dvert, const int *flip_map, const int flip_map_len) | ||||
| { | { | ||||
| MDeformWeight *dw; | MDeformWeight *dw; | ||||
| int i; | int i; | ||||
| for (dw = dvert->dw, i = 0; i < dvert->totweight; dw++, i++) { | for (dw = dvert->dw, i = 0; i < dvert->totweight; dw++, i++) { | ||||
| if (dw->def_nr < flip_map_len) { | if (dw->def_nr < flip_map_len) { | ||||
| if (flip_map[dw->def_nr] >= 0) { | if (flip_map[dw->def_nr] >= 0) { | ||||
| ▲ Show 20 Lines • Show All 992 Lines • Show Last 20 Lines | |||||
Regarding naming BKE_devert_normalize_gradient_paint isn't very informative, as it doesn't let developers know whats different. Also, if this is used in other situations, the name is likely to become meaningless.