From d8dbd49a2f23b7637f05fc058f39bdf6ab706624 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 31 May 2019 22:51:19 +1000 Subject: Cleanup: style, use braces in source/ Automated using clang-tidy. --- source/blender/physics/intern/BPH_mass_spring.cpp | 49 +++++++++----- source/blender/physics/intern/hair_volume.cpp | 78 +++++++++++++++-------- source/blender/physics/intern/implicit_blender.c | 36 +++++++---- 3 files changed, 109 insertions(+), 54 deletions(-) (limited to 'source/blender/physics') diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp index f7a9cadc9cf..334959a7523 100644 --- a/source/blender/physics/intern/BPH_mass_spring.cpp +++ b/source/blender/physics/intern/BPH_mass_spring.cpp @@ -119,8 +119,9 @@ void BKE_cloth_solver_set_positions(ClothModifierData *clmd) ClothHairData *root = &cloth_hairdata[i]; BPH_mass_spring_set_rest_transform(id, i, root->rot); } - else + else { BPH_mass_spring_set_rest_transform(id, i, I3); + } BPH_mass_spring_set_motion_state(id, i, verts[i].x, verts[i].v); } @@ -145,12 +146,14 @@ static bool collision_response(ClothModifierData *clmd, zero_v3(r_impulse); - if (margin_distance > 0.0f) + if (margin_distance > 0.0f) { return false; /* XXX tested before already? */ + } /* only handle static collisions here */ - if (collpair->flag & COLLISION_IN_FUTURE) + if (collpair->flag & COLLISION_IN_FUTURE) { return false; + } /* velocity */ copy_v3_v3(v1, cloth->verts[index].v); @@ -238,18 +241,21 @@ static void cloth_setup_constraints(ClothModifierData *clmd, float impulse[3]; /* pinned verts handled separately */ - if (verts[v].flags & CLOTH_VERT_FLAG_PINNED) + if (verts[v].flags & CLOTH_VERT_FLAG_PINNED) { continue; + } /* XXX cheap way of avoiding instability from multiple collisions in the same step * this should eventually be supported ... */ - if (verts[v].impulse_count > 0) + if (verts[v].impulse_count > 0) { continue; + } /* calculate collision response */ - if (!collision_response(clmd, ct->collmd, collpair, dt, restitution, impulse)) + if (!collision_response(clmd, ct->collmd, collpair, dt, restitution, impulse)) { continue; + } BPH_mass_spring_add_constraint_ndof2(data, v, collpair->normal, impulse); ++verts[v].impulse_count; @@ -297,8 +303,10 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), float len, c, l, vec[3]; spring = (ClothSpring *)node->link; - if (spring->type != CLOTH_SPRING_TYPE_STRUCTURAL && spring->type != CLOTH_SPRING_TYPE_SHEAR) + if (spring->type != CLOTH_SPRING_TYPE_STRUCTURAL && + spring->type != CLOTH_SPRING_TYPE_SHEAR) { continue; + } v1 = spring->ij; v2 = spring->kl; @@ -310,8 +318,9 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), normalize_v3(vec); c = (len - spring->restlen); - if (c == 0.0f) + if (c == 0.0f) { continue; + } l = c / ((1.0f / masses[v1]) + (1.0f / masses[v2])); @@ -609,8 +618,9 @@ static void cloth_calc_force( ClothHairData *hair = &hairdata[i]; BPH_mass_spring_force_vertex_wind(data, i, hair->radius, winvec); } - else + else { BPH_mass_spring_force_vertex_wind(data, i, 1.0f, winvec); + } } #endif } @@ -650,8 +660,9 @@ BLI_INLINE LinkNode *hair_spring_next(LinkNode *spring_link) LinkNode *next = spring_link->next; if (next) { ClothSpring *next_spring = (ClothSpring *)next->link; - if (next_spring->type == CLOTH_SPRING_TYPE_STRUCTURAL && next_spring->kl == spring->ij) + if (next_spring->type == CLOTH_SPRING_TYPE_STRUCTURAL && next_spring->kl == spring->ij) { return next; + } } return NULL; } @@ -767,10 +778,12 @@ static void cloth_continuum_fill_grid(HairGrid *grid, Cloth *cloth) link = cloth->springs; while (link) { ClothSpring *spring = (ClothSpring *)link->link; - if (spring->type == CLOTH_SPRING_TYPE_STRUCTURAL) + if (spring->type == CLOTH_SPRING_TYPE_STRUCTURAL) { link = cloth_continuum_add_hair_segments(grid, cell_scale, cell_offset, cloth, link); - else + } + else { link = link->next; + } } #endif BPH_hair_volume_normalize_vertex_grid(grid); @@ -975,11 +988,13 @@ static void cloth_solve_collisions( int i; if (!(clmd->coll_parms->flags & - (CLOTH_COLLSETTINGS_FLAG_ENABLED | CLOTH_COLLSETTINGS_FLAG_SELF))) + (CLOTH_COLLSETTINGS_FLAG_ENABLED | CLOTH_COLLSETTINGS_FLAG_SELF))) { return; + } - if (!clmd->clothObject->bvhtree) + if (!clmd->clothObject->bvhtree) { return; + } BPH_mass_spring_solve_positions(id, dt); @@ -997,8 +1012,9 @@ static void cloth_solve_collisions( step / clmd->sim_parms->timescale, dt / clmd->sim_parms->timescale)) { for (i = 0; i < mvert_num; i++) { - if ((clmd->sim_parms->vgroup_mass > 0) && (verts[i].flags & CLOTH_VERT_FLAG_PINNED)) + if ((clmd->sim_parms->vgroup_mass > 0) && (verts[i].flags & CLOTH_VERT_FLAG_PINNED)) { continue; + } BPH_mass_spring_get_new_velocity(id, i, verts[i].tv); madd_v3_v3fl(verts[i].tv, verts[i].dcvel, time_multiplier); @@ -1069,9 +1085,10 @@ int BPH_cloth_solve( BKE_sim_debug_data_clear_category("collision"); - if (!clmd->solver_result) + if (!clmd->solver_result) { clmd->solver_result = (ClothSolverResult *)MEM_callocN(sizeof(ClothSolverResult), "cloth solver result"); + } cloth_clear_result(clmd); if (clmd->sim_parms->vgroup_mass > 0) { /* Do goal stuff. */ diff --git a/source/blender/physics/intern/hair_volume.cpp b/source/blender/physics/intern/hair_volume.cpp index a07d1fe8f75..1123924078c 100644 --- a/source/blender/physics/intern/hair_volume.cpp +++ b/source/blender/physics/intern/hair_volume.cpp @@ -321,8 +321,9 @@ BLI_INLINE float weights_sum(const float weights[8]) { float totweight = 0.0f; int i; - for (i = 0; i < 8; ++i) + for (i = 0; i < 8; ++i) { totweight += weights[i]; + } return totweight; } @@ -370,8 +371,9 @@ void BPH_hair_volume_add_vertex(HairGrid *grid, const float x[3], const float v[ int di, dj, dk; int offset; - if (!hair_grid_point_valid(x, grid->gmin, grid->gmax)) + if (!hair_grid_point_valid(x, grid->gmin, grid->gmax)) { return; + } offset = hair_grid_weights(res, grid->gmin, grid->inv_cellsize, x, weights); @@ -689,8 +691,9 @@ void BPH_hair_volume_normalize_vertex_grid(HairGrid *grid) /* divide velocity with density */ for (i = 0; i < size; i++) { float density = grid->verts[i].density; - if (density > 0.0f) + if (density > 0.0f) { mul_v3_fl(grid->verts[i].velocity, 1.0f / density); + } } } @@ -705,10 +708,12 @@ BLI_INLINE float hair_volume_density_divergence(float density, float target_density, float strength) { - if (density > density_threshold && density > target_density) + if (density > density_threshold && density > target_density) { return strength * logf(target_density / density); - else + } + else { return 0.0f; + } } bool BPH_hair_volume_solve_divergence(HairGrid *grid, @@ -771,18 +776,24 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, const float *v0 = vert->velocity; float dx = 0.0f, dy = 0.0f, dz = 0.0f; - if (!NEIGHBOR_MARGIN_i0) + if (!NEIGHBOR_MARGIN_i0) { dx += v0[0] - (vert - stride0)->velocity[0]; - if (!NEIGHBOR_MARGIN_i1) + } + if (!NEIGHBOR_MARGIN_i1) { dx += (vert + stride0)->velocity[0] - v0[0]; - if (!NEIGHBOR_MARGIN_j0) + } + if (!NEIGHBOR_MARGIN_j0) { dy += v0[1] - (vert - stride1)->velocity[1]; - if (!NEIGHBOR_MARGIN_j1) + } + if (!NEIGHBOR_MARGIN_j1) { dy += (vert + stride1)->velocity[1] - v0[1]; - if (!NEIGHBOR_MARGIN_k0) + } + if (!NEIGHBOR_MARGIN_k0) { dz += v0[2] - (vert - stride2)->velocity[2]; - if (!NEIGHBOR_MARGIN_k1) + } + if (!NEIGHBOR_MARGIN_k1) { dz += (vert + stride2)->velocity[2] - v0[2]; + } float divergence = -0.5f * flowfac * (dx + dy + dz); @@ -862,27 +873,35 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, * to get the correct number of neighbors, * needed for the diagonal element */ - if (!NEIGHBOR_MARGIN_k0 && (vert - stride2)->density > density_threshold) + if (!NEIGHBOR_MARGIN_k0 && (vert - stride2)->density > density_threshold) { neighbor_lo_index[neighbors_lo++] = u - strideA2; - if (!NEIGHBOR_MARGIN_j0 && (vert - stride1)->density > density_threshold) + } + if (!NEIGHBOR_MARGIN_j0 && (vert - stride1)->density > density_threshold) { neighbor_lo_index[neighbors_lo++] = u - strideA1; - if (!NEIGHBOR_MARGIN_i0 && (vert - stride0)->density > density_threshold) + } + if (!NEIGHBOR_MARGIN_i0 && (vert - stride0)->density > density_threshold) { neighbor_lo_index[neighbors_lo++] = u - strideA0; - if (!NEIGHBOR_MARGIN_i1 && (vert + stride0)->density > density_threshold) + } + if (!NEIGHBOR_MARGIN_i1 && (vert + stride0)->density > density_threshold) { neighbor_hi_index[neighbors_hi++] = u + strideA0; - if (!NEIGHBOR_MARGIN_j1 && (vert + stride1)->density > density_threshold) + } + if (!NEIGHBOR_MARGIN_j1 && (vert + stride1)->density > density_threshold) { neighbor_hi_index[neighbors_hi++] = u + strideA1; - if (!NEIGHBOR_MARGIN_k1 && (vert + stride2)->density > density_threshold) + } + if (!NEIGHBOR_MARGIN_k1 && (vert + stride2)->density > density_threshold) { neighbor_hi_index[neighbors_hi++] = u + strideA2; + } /*int liquid_neighbors = neighbors_lo + neighbors_hi;*/ non_solid_neighbors = 6; - for (n = 0; n < neighbors_lo; ++n) + for (n = 0; n < neighbors_lo; ++n) { A.insert(neighbor_lo_index[n], u) = -1.0f; + } A.insert(u, u) = (float)non_solid_neighbors; - for (n = 0; n < neighbors_hi; ++n) + for (n = 0; n < neighbors_hi; ++n) { A.insert(neighbor_hi_index[n], u) = -1.0f; + } } else { A.insert(u, u) = 1.0f; @@ -907,8 +926,9 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, int u = i * strideA0 + j * strideA1 + k * strideA2; bool is_margin = MARGIN_i0 || MARGIN_i1 || MARGIN_j0 || MARGIN_j1 || MARGIN_k0 || MARGIN_k1; - if (is_margin) + if (is_margin) { continue; + } vert = vert_start + i * stride0 + j * stride1 + k * stride2; if (vert->density > density_threshold) { @@ -1103,8 +1123,9 @@ HairGrid *BPH_hair_volume_create_vertex_grid(float cellsize, int i; /* sanity check */ - if (cellsize <= 0.0f) + if (cellsize <= 0.0f) { cellsize = 1.0f; + } scale = 1.0f / cellsize; sub_v3_v3v3(extent, gmax, gmin); @@ -1149,8 +1170,9 @@ HairGrid *BPH_hair_volume_create_vertex_grid(float cellsize, void BPH_hair_volume_free_vertex_grid(HairGrid *grid) { if (grid) { - if (grid->verts) + if (grid->verts) { MEM_freeN(grid->verts); + } MEM_freeN(grid); } } @@ -1158,14 +1180,18 @@ void BPH_hair_volume_free_vertex_grid(HairGrid *grid) void BPH_hair_volume_grid_geometry( HairGrid *grid, float *cellsize, int res[3], float gmin[3], float gmax[3]) { - if (cellsize) + if (cellsize) { *cellsize = grid->cellsize; - if (res) + } + if (res) { copy_v3_v3_int(res, grid->res); - if (gmin) + } + if (gmin) { copy_v3_v3(gmin, grid->gmin); - if (gmax) + } + if (gmax) { copy_v3_v3(gmax, grid->gmax); + } } #if 0 diff --git a/source/blender/physics/intern/implicit_blender.c b/source/blender/physics/intern/implicit_blender.c index d64846e4dcc..9952781b60f 100644 --- a/source/blender/physics/intern/implicit_blender.c +++ b/source/blender/physics/intern/implicit_blender.c @@ -1233,10 +1233,12 @@ void BPH_mass_spring_get_motion_state(struct Implicit_Data *data, float x[3], float v[3]) { - if (x) + if (x) { root_to_world_v3(data, index, x, data->X[index]); - if (v) + } + if (v) { root_to_world_v3(data, index, v, data->V[index]); + } } void BPH_mass_spring_get_position(struct Implicit_Data *data, int index, float x[3]) @@ -1595,10 +1597,12 @@ BLI_INLINE float fbstar(float length, float L, float kb, float cb) float tempfb_fl = kb * fb(length, L); float fbstar_fl = cb * (length - L); - if (tempfb_fl < fbstar_fl) + if (tempfb_fl < fbstar_fl) { return fbstar_fl; - else + } + else { return tempfb_fl; + } } // function to calculae bending spring force (taken from Choi & Co) @@ -1925,30 +1929,38 @@ BLI_INLINE void spring_hairbend_forces(Implicit_Data *data, zero_v3(fk); sub_v3_v3v3(edge_ij, data->X[j], data->X[i]); - if (q == i) + if (q == i) { sub_v3_v3(edge_ij, dx); - if (q == j) + } + if (q == j) { add_v3_v3(edge_ij, dx); + } normalize_v3_v3(dir_ij, edge_ij); sub_v3_v3v3(edge_jk, data->X[k], data->X[j]); - if (q == j) + if (q == j) { sub_v3_v3(edge_jk, dx); - if (q == k) + } + if (q == k) { add_v3_v3(edge_jk, dx); + } normalize_v3_v3(dir_jk, edge_jk); sub_v3_v3v3(vel_ij, data->V[j], data->V[i]); - if (q == i) + if (q == i) { sub_v3_v3(vel_ij, dv); - if (q == j) + } + if (q == j) { add_v3_v3(vel_ij, dv); + } sub_v3_v3v3(vel_jk, data->V[k], data->V[j]); - if (q == j) + if (q == j) { sub_v3_v3(vel_jk, dv); - if (q == k) + } + if (q == k) { add_v3_v3(vel_jk, dv); + } /* bending force */ sub_v3_v3v3(dist, goal, edge_jk); -- cgit v1.2.3