From c3215724566a902517cf866c2835219b201ffaa3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 12 Aug 2022 11:18:00 +1000 Subject: Cleanup: screw modifier comments & naming Rename dist to dist_sq as it's the squared distance, also prefer __func__ in temporary allocated arrays. --- source/blender/modifiers/intern/MOD_screw.c | 69 ++++++++++++++++------------- 1 file changed, 37 insertions(+), 32 deletions(-) (limited to 'source/blender/modifiers') diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c index 109795df796..6095be48f8f 100644 --- a/source/blender/modifiers/intern/MOD_screw.c +++ b/source/blender/modifiers/intern/MOD_screw.c @@ -52,13 +52,18 @@ static void initData(ModifierData *md) #include "BLI_strict_flags.h" -/* used for gathering edge connectivity */ +/** Used for gathering edge connectivity. */ typedef struct ScrewVertConnect { - float dist; /* distance from the center axis */ - float co[3]; /* location relative to the transformed axis */ - float no[3]; /* calc normal of the vertex */ - uint v[2]; /* 2 verts on either side of this one */ - MEdge *e[2]; /* edges on either side, a bit of a waste since each edge ref's 2 edges */ + /** Distance from the center axis. */ + float dist_sq; + /** Location relative to the transformed axis. */ + float co[3]; + /** Calc normal of the vertex. */ + float no[3]; + /** 2 verts on either side of this one. */ + uint v[2]; + /** Edges on either side, a bit of a waste since each edge ref's 2 edges. */ + MEdge *e[2]; char flag; } ScrewVertConnect; @@ -270,18 +275,18 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * axis_vec[ltmd->axis] = 1.0f; if (ob_axis != NULL) { - /* calc the matrix relative to the axis object */ + /* Calculate the matrix relative to the axis object. */ invert_m4_m4(mtx_tmp_a, ctx->object->obmat); copy_m4_m4(mtx_tx_inv, ob_axis->obmat); mul_m4_m4m4(mtx_tx, mtx_tmp_a, mtx_tx_inv); - /* calc the axis vec */ + /* Calculate the axis vector. */ mul_mat3_m4_v3(mtx_tx, axis_vec); /* only rotation component */ normalize_v3(axis_vec); /* screw */ if (ltmd->flag & MOD_SCREW_OBJECT_OFFSET) { - /* find the offset along this axis relative to this objects matrix */ + /* Find the offset along this axis relative to this objects matrix. */ float totlen = len_v3(mtx_tx[3]); if (totlen != 0.0f) { @@ -330,7 +335,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * else { axis_char = (char)(axis_char + ltmd->axis); /* 'X' + axis */ - /* useful to be able to use the axis vec in some cases still */ + /* Useful to be able to use the axis vector in some cases still. */ zero_v3(axis_vec); axis_vec[ltmd->axis] = 1.0f; } @@ -441,7 +446,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * med_new->crease = med_orig->crease; med_new->flag = med_orig->flag & ~ME_LOOSEEDGE; - /* Tag mvert as not loose. */ + /* Tag #MVert as not loose. */ BLI_BITMAP_ENABLE(vert_tag, med_orig->v1); BLI_BITMAP_ENABLE(vert_tag, med_orig->v2); } @@ -481,8 +486,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * if (ltmd->flag & MOD_SCREW_NORMAL_CALC) { - /* - * Normal Calculation (for face flipping) + /* Normal Calculation (for face flipping) * Sort edge verts for correct face flipping * NOT REALLY NEEDED but face flipping is nice. */ @@ -490,19 +494,19 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * * * Since we are only ordering the edges here it can avoid mallocing the * extra space by abusing the vert array before its filled with new verts. - * The new array for vert_connect must be at least sizeof(ScrewVertConnect) * totvert - * and the size of our resulting meshes array is sizeof(MVert) * totvert * 3 - * so its safe to use the second 2 thirds of MVert the array for vert_connect, - * just make sure ScrewVertConnect struct is no more than twice as big as MVert, + * The new array for vert_connect must be at least `sizeof(ScrewVertConnect) * totvert` + * and the size of our resulting meshes array is `sizeof(MVert) * totvert * 3` + * so its safe to use the second 2 thirds of #MVert the array for vert_connect, + * just make sure #ScrewVertConnect struct is no more than twice as big as #MVert, * at the moment there is no chance of that being a problem, - * unless MVert becomes half its current size. + * unless #MVert becomes half its current size. * * once the edges are ordered, vert_connect is not needed and it can be used for verts * - * This makes the modifier faster with one less alloc. + * This makes the modifier faster with one less allocate. */ - vert_connect = MEM_malloc_arrayN(totvert, sizeof(ScrewVertConnect), "ScrewVertConnect"); + vert_connect = MEM_malloc_arrayN(totvert, sizeof(ScrewVertConnect), __func__); /* skip the first slice of verts. */ // vert_connect = (ScrewVertConnect *) &medge_new[totvert]; vc = vert_connect; @@ -512,7 +516,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * if (!totedge) { for (i = 0; i < totvert; i++, mv_orig++, mv_new++) { copy_v3_v3(mv_new->co, mv_orig->co); - normalize_v3_v3(vc->no, mv_new->co); /* no edges- this is really a dummy normal */ + /* No edges: this is really a dummy normal. */ + normalize_v3_v3(vc->no, mv_new->co); } } else { @@ -533,11 +538,11 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * vc->v[0] = vc->v[1] = SV_UNUSED; mul_m4_v3(mtx_tx, vc->co); - /* length in 2d, don't sqrt because this is only for comparison */ - vc->dist = vc->co[other_axis_1] * vc->co[other_axis_1] + - vc->co[other_axis_2] * vc->co[other_axis_2]; + /* Length in 2D, don't `sqrt` because this is only for comparison. */ + vc->dist_sq = vc->co[other_axis_1] * vc->co[other_axis_1] + + vc->co[other_axis_2] * vc->co[other_axis_2]; - // printf("location %f %f %f -- %f\n", vc->co[0], vc->co[1], vc->co[2], vc->dist); + // printf("location %f %f %f -- %f\n", vc->co[0], vc->co[1], vc->co[2], vc->dist_sq); } } else { @@ -550,11 +555,11 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * vc->e[0] = vc->e[1] = NULL; vc->v[0] = vc->v[1] = SV_UNUSED; - /* length in 2d, don't sqrt because this is only for comparison */ - vc->dist = vc->co[other_axis_1] * vc->co[other_axis_1] + - vc->co[other_axis_2] * vc->co[other_axis_2]; + /* Length in 2D, don't sqrt because this is only for comparison. */ + vc->dist_sq = vc->co[other_axis_1] * vc->co[other_axis_1] + + vc->co[other_axis_2] * vc->co[other_axis_2]; - // printf("location %f %f %f -- %f\n", vc->co[0], vc->co[1], vc->co[2], vc->dist); + // printf("location %f %f %f -- %f\n", vc->co[0], vc->co[1], vc->co[2], vc->dist_sq); } } @@ -622,9 +627,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } lt_iter.v_poin->flag = 1; vc_tot_linked++; - // printf("Testing 2 floats %f : %f\n", fl, lt_iter.v_poin->dist); - if (fl <= lt_iter.v_poin->dist) { - fl = lt_iter.v_poin->dist; + // printf("Testing 2 floats %f : %f\n", fl, lt_iter.v_poin->dist_sq); + if (fl <= lt_iter.v_poin->dist_sq) { + fl = lt_iter.v_poin->dist_sq; v_best = lt_iter.v; // printf("\t\t\tVERT BEST: %i\n", v_best); } -- cgit v1.2.3