Cleanup: Clang tidy

- Inconsistent parameter names
- Else after return
- Braces around statements
- Qualified auto
- Also (not clang tidy): Pass StringRef by value, unused parameter
This commit is contained in:
Hans Goudey 2022-04-18 12:36:37 -05:00
parent fc58368263
commit 98fc998c70
7 changed files with 65 additions and 63 deletions

View File

@ -594,9 +594,9 @@ void BKE_view_layer_rename_lightgroup(ViewLayer *view_layer,
ViewLayerLightgroup *lightgroup,
const char *name);
void BKE_lightgroup_membership_get(struct LightgroupMembership *lgm, char *value);
void BKE_lightgroup_membership_get(struct LightgroupMembership *lgm, char *name);
int BKE_lightgroup_membership_length(struct LightgroupMembership *lgm);
void BKE_lightgroup_membership_set(struct LightgroupMembership **lgm, const char *value);
void BKE_lightgroup_membership_set(struct LightgroupMembership **lgm, const char *name);
#ifdef __cplusplus
}

View File

@ -981,7 +981,7 @@ bool BKE_gpencil_stroke_shrink(bGPDstroke *gps, const float dist, const short mo
* \{ */
bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps,
int i,
int point_index,
float influence,
int iterations,
const bool smooth_caps,
@ -995,7 +995,7 @@ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps,
/* Overview of the algorithm here and in the following smooth functions:
* The smooth functions return the new attribute in question for a single point.
* The result is stored in r_gps->points[i], while the data is read from gps.
* The result is stored in r_gps->points[point_index], while the data is read from gps.
* To get a correct result, duplicate the stroke point data and read from the copy,
* while writing to the real stroke. Not doing that will result in acceptable, but
* asymmetric results.
@ -1004,16 +1004,16 @@ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps,
* the parameter "iterations" set to 1 or 2. (2 matches the old algorithm).
*/
const bGPDspoint *pt = &gps->points[i];
const bGPDspoint *pt = &gps->points[point_index];
const bool is_cyclic = (gps->flag & GP_STROKE_CYCLIC) != 0;
/* If smooth_caps is false, the caps will not be translated by smoothing. */
if (!smooth_caps && !is_cyclic && ELEM(i, 0, gps->totpoints - 1)) {
copy_v3_v3(&r_gps->points[i].x, &pt->x);
if (!smooth_caps && !is_cyclic && ELEM(point_index, 0, gps->totpoints - 1)) {
copy_v3_v3(&r_gps->points[point_index].x, &pt->x);
return true;
}
/* This function uses a binomial kernel, which is the discrete version of gaussian blur.
* The weight for a vertex at the relative index i is
* The weight for a vertex at the relative index point_index is
* w = nCr(n, j + n/2) / 2^n = (n/1 * (n-1)/2 * ... * (n-j-n/2)/(j+n/2)) / 2^n
* All weights together sum up to 1
* This is equivalent to doing multiple iterations of averaging neighbors,
@ -1044,8 +1044,8 @@ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps,
0.0;
double total_w = 0.0;
for (int step = iterations; step > 0; step--) {
int before = i - step;
int after = i + step;
int before = point_index - step;
int after = point_index + step;
float w_before = (float)(w - w2);
float w_after = (float)(w - w2);
@ -1056,13 +1056,13 @@ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps,
else {
if (before < 0) {
if (!smooth_caps) {
w_before *= -before / (float)i;
w_before *= -before / (float)point_index;
}
before = 0;
}
if (after > gps->totpoints - 1) {
if (!smooth_caps) {
w_after *= (after - (gps->totpoints - 1)) / (float)(gps->totpoints - 1 - i);
w_after *= (after - (gps->totpoints - 1)) / (float)(gps->totpoints - 1 - point_index);
}
after = gps->totpoints - 1;
}
@ -1089,7 +1089,7 @@ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps,
add_v3_v3(sco, &pt->x);
/* Based on influence factor, blend between original and optimal smoothed coordinate. */
interp_v3_v3v3(&r_gps->points[i].x, &pt->x, sco, influence);
interp_v3_v3v3(&r_gps->points[point_index].x, &pt->x, sco, influence);
return true;
}
@ -1101,7 +1101,7 @@ bool BKE_gpencil_stroke_smooth_point(bGPDstroke *gps,
* \{ */
bool BKE_gpencil_stroke_smooth_strength(
bGPDstroke *gps, int i, float influence, int iterations, bGPDstroke *r_gps)
bGPDstroke *gps, int point_index, float influence, int iterations, bGPDstroke *r_gps)
{
/* If nothing to do, return early */
if (gps->totpoints <= 2 || iterations <= 0) {
@ -1110,15 +1110,15 @@ bool BKE_gpencil_stroke_smooth_strength(
/* See BKE_gpencil_stroke_smooth_point for details on the algorithm. */
const bGPDspoint *pt = &gps->points[i];
const bGPDspoint *pt = &gps->points[point_index];
const bool is_cyclic = (gps->flag & GP_STROKE_CYCLIC) != 0;
float strength = 0.0f;
const int n_half = (iterations * iterations) / 4 + iterations;
double w = 1.0;
double total_w = 0.0;
for (int step = iterations; step > 0; step--) {
int before = i - step;
int after = i + step;
int before = point_index - step;
int after = point_index + step;
float w_before = (float)w;
float w_after = (float)w;
@ -1147,7 +1147,7 @@ bool BKE_gpencil_stroke_smooth_strength(
strength /= total_w;
/* Based on influence factor, blend between original and optimal smoothed value. */
r_gps->points[i].strength = pt->strength + strength * influence;
r_gps->points[point_index].strength = pt->strength + strength * influence;
return true;
}
@ -1159,7 +1159,7 @@ bool BKE_gpencil_stroke_smooth_strength(
* \{ */
bool BKE_gpencil_stroke_smooth_thickness(
bGPDstroke *gps, int i, float influence, int iterations, bGPDstroke *r_gps)
bGPDstroke *gps, int point_index, float influence, int iterations, bGPDstroke *r_gps)
{
/* If nothing to do, return early */
if (gps->totpoints <= 2 || iterations <= 0) {
@ -1168,15 +1168,15 @@ bool BKE_gpencil_stroke_smooth_thickness(
/* See BKE_gpencil_stroke_smooth_point for details on the algorithm. */
const bGPDspoint *pt = &gps->points[i];
const bGPDspoint *pt = &gps->points[point_index];
const bool is_cyclic = (gps->flag & GP_STROKE_CYCLIC) != 0;
float pressure = 0.0f;
const int n_half = (iterations * iterations) / 4 + iterations;
double w = 1.0;
double total_w = 0.0;
for (int step = iterations; step > 0; step--) {
int before = i - step;
int after = i + step;
int before = point_index - step;
int after = point_index + step;
float w_before = (float)w;
float w_after = (float)w;
@ -1205,7 +1205,7 @@ bool BKE_gpencil_stroke_smooth_thickness(
pressure /= total_w;
/* Based on influence factor, blend between original and optimal smoothed value. */
r_gps->points[i].pressure = pt->pressure + pressure * influence;
r_gps->points[point_index].pressure = pt->pressure + pressure * influence;
return true;
}
@ -1216,8 +1216,11 @@ bool BKE_gpencil_stroke_smooth_thickness(
/** \name Stroke Smooth UV
* \{ */
bool BKE_gpencil_stroke_smooth_uv(
struct bGPDstroke *gps, int i, float influence, int iterations, struct bGPDstroke *r_gps)
bool BKE_gpencil_stroke_smooth_uv(struct bGPDstroke *gps,
int point_index,
float influence,
int iterations,
struct bGPDstroke *r_gps)
{
/* If nothing to do, return early */
if (gps->totpoints <= 2 || iterations <= 0) {
@ -1226,13 +1229,13 @@ bool BKE_gpencil_stroke_smooth_uv(
/* See BKE_gpencil_stroke_smooth_point for details on the algorithm. */
const bGPDspoint *pt = &gps->points[i];
const bGPDspoint *pt = &gps->points[point_index];
const bool is_cyclic = (gps->flag & GP_STROKE_CYCLIC) != 0;
/* If don't change the caps. */
if (!is_cyclic && ELEM(i, 0, gps->totpoints - 1)) {
r_gps->points[i].uv_rot = pt->uv_rot;
r_gps->points[i].uv_fac = pt->uv_fac;
if (!is_cyclic && ELEM(point_index, 0, gps->totpoints - 1)) {
r_gps->points[point_index].uv_rot = pt->uv_rot;
r_gps->points[point_index].uv_fac = pt->uv_fac;
return true;
}
@ -1242,8 +1245,8 @@ bool BKE_gpencil_stroke_smooth_uv(
double w = 1.0;
double total_w = 0.0;
for (int step = iterations; step > 0; step--) {
int before = i - step;
int after = i + step;
int before = point_index - step;
int after = point_index + step;
float w_before = (float)w;
float w_after = (float)w;
@ -1253,11 +1256,11 @@ bool BKE_gpencil_stroke_smooth_uv(
}
else {
if (before < 0) {
w_before *= -before / (float)i;
w_before *= -before / (float)point_index;
before = 0;
}
if (after > gps->totpoints - 1) {
w_after *= (after - (gps->totpoints - 1)) / (float)(gps->totpoints - 1 - i);
w_after *= (after - (gps->totpoints - 1)) / (float)(gps->totpoints - 1 - point_index);
after = gps->totpoints - 1;
}
}
@ -1281,8 +1284,8 @@ bool BKE_gpencil_stroke_smooth_uv(
uv_fac /= total_w;
/* Based on influence factor, blend between original and optimal smoothed value. */
r_gps->points[i].uv_rot = pt->uv_rot + uv_rot * influence;
r_gps->points[i].uv_fac = pt->uv_fac + uv_fac * influence;
r_gps->points[point_index].uv_rot = pt->uv_rot + uv_rot * influence;
r_gps->points[point_index].uv_fac = pt->uv_fac + uv_fac * influence;
return true;
}

View File

@ -92,7 +92,7 @@ void eevee_shader_material_create_info_amend(GPUMaterial *gpumat,
const StageInterfaceInfo &iface = *info.vertex_out_interfaces_.first();
/* Globals the attrib_load() can write to when it is in the fragment shader. */
attr_load << "struct " << iface.name << " {\n";
for (auto &inout : iface.inouts) {
for (const auto &inout : iface.inouts) {
attr_load << " " << inout.type << " " << inout.name << ";\n";
}
attr_load << "};\n";

View File

@ -363,7 +363,7 @@ void ED_mesh_deform_bind_callback(struct Object *object,
struct MeshDeformModifierData *mmd,
struct Mesh *cagemesh,
float *vertexcos,
int totvert,
int verts_num,
float cagemat[4][4]);
/* Pose backups, pose_backup.c */

View File

@ -3298,7 +3298,7 @@ void OBJECT_OT_geometry_nodes_input_attribute_toggle(wmOperatorType *ot)
/** \name Copy and Assign Geometry Node Group operator
* \{ */
static int geometry_node_tree_copy_assign_exec(bContext *C, wmOperator *op)
static int geometry_node_tree_copy_assign_exec(bContext *C, wmOperator *UNUSED(op))
{
Main *bmain = CTX_data_main(C);
Object *ob = ED_object_active_context(C);

View File

@ -292,7 +292,7 @@ struct GPUSource {
const char whitespace_chars[] = " \r\n\t";
auto function_parse = [&](const StringRef &input,
auto function_parse = [&](const StringRef input,
int64_t &cursor,
StringRef &out_return_type,
StringRef &out_name,
@ -330,7 +330,7 @@ struct GPUSource {
return true;
};
auto keyword_parse = [&](const StringRef &str, int64_t &cursor) -> const StringRef {
auto keyword_parse = [&](const StringRef str, int64_t &cursor) -> StringRef {
int64_t keyword_start = str.find_first_not_of(whitespace_chars, cursor);
if (keyword_start == -1) {
/* No keyword found. */
@ -345,7 +345,7 @@ struct GPUSource {
return str.substr(keyword_start, keyword_end - keyword_start);
};
auto arg_parse = [&](const StringRef &str,
auto arg_parse = [&](const StringRef str,
int64_t &cursor,
StringRef &out_qualifier,
StringRef &out_type,
@ -416,55 +416,51 @@ struct GPUSource {
break;
}
auto parse_qualifier = [](StringRef &qualifier) -> GPUFunctionQual {
auto parse_qualifier = [](StringRef qualifier) -> GPUFunctionQual {
if (qualifier == "out") {
return FUNCTION_QUAL_OUT;
}
else if (qualifier == "inout") {
if (qualifier == "inout") {
return FUNCTION_QUAL_INOUT;
}
else {
return FUNCTION_QUAL_IN;
}
return FUNCTION_QUAL_IN;
};
auto parse_type = [](StringRef &type) -> eGPUType {
auto parse_type = [](StringRef type) -> eGPUType {
if (type == "float") {
return GPU_FLOAT;
}
else if (type == "vec2") {
if (type == "vec2") {
return GPU_VEC2;
}
else if (type == "vec3") {
if (type == "vec3") {
return GPU_VEC3;
}
else if (type == "vec4") {
if (type == "vec4") {
return GPU_VEC4;
}
else if (type == "mat3") {
if (type == "mat3") {
return GPU_MAT3;
}
else if (type == "mat4") {
if (type == "mat4") {
return GPU_MAT4;
}
else if (type == "sampler1DArray") {
if (type == "sampler1DArray") {
return GPU_TEX1D_ARRAY;
}
else if (type == "sampler2DArray") {
if (type == "sampler2DArray") {
return GPU_TEX2D_ARRAY;
}
else if (type == "sampler2D") {
if (type == "sampler2D") {
return GPU_TEX2D;
}
else if (type == "sampler3D") {
if (type == "sampler3D") {
return GPU_TEX3D;
}
else if (type == "Closure") {
if (type == "Closure") {
return GPU_CLOSURE;
}
else {
return GPU_NONE;
}
return GPU_NONE;
};
func->paramqual[func->totparam] = parse_qualifier(arg_qualifier);

View File

@ -360,8 +360,9 @@ void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
while (last_nl > 0) {
--last_nl;
if (buffer[last_nl] == '\n') {
if (last_nl < 1 || buffer[last_nl - 1] != '\\')
if (last_nl < 1 || buffer[last_nl - 1] != '\\') {
break;
}
}
}
if (buffer[last_nl] != '\n') {
@ -380,8 +381,9 @@ void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
while (!buffer_str.is_empty()) {
StringRef line = read_next_line(buffer_str);
++line_number;
if (line.is_empty())
if (line.is_empty()) {
continue;
}
/* Most common things that start with 'v': vertices, normals, UVs. */
if (line[0] == 'v') {
if (line.startswith("v ")) {
@ -643,8 +645,9 @@ void MTLParser::parse_and_store(Map<string, std::unique_ptr<MTLMaterial>> &r_mat
StringRef buffer_str{(const char *)buffer, (int64_t)buffer_len};
while (!buffer_str.is_empty()) {
StringRef line = read_next_line(buffer_str);
if (line.is_empty())
if (line.is_empty()) {
continue;
}
if (line.startswith("newmtl ")) {
line = line.drop_prefix(7);