From 6275541df7e02c40e8c8650bba3104b5df8d34ef Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 26 Sep 2022 13:58:49 +1000 Subject: Cleanup: use ELEM/STR_ELEM/STREQ macros --- source/blender/io/collada/AnimationImporter.cpp | 18 +++++++++++------- source/blender/io/collada/BCAnimationCurve.cpp | 3 +-- source/blender/io/collada/BCSampleData.cpp | 2 +- source/blender/io/collada/MeshImporter.cpp | 14 ++++++++------ source/blender/io/usd/intern/usd_reader_material.cc | 2 +- source/blender/io/usd/intern/usd_writer_material.cc | 4 ++-- .../io/wavefront_obj/tests/obj_importer_tests.cc | 2 +- 7 files changed, 25 insertions(+), 20 deletions(-) (limited to 'source/blender/io') diff --git a/source/blender/io/collada/AnimationImporter.cpp b/source/blender/io/collada/AnimationImporter.cpp index 2b56cf188f1..2d872377bbf 100644 --- a/source/blender/io/collada/AnimationImporter.cpp +++ b/source/blender/io/collada/AnimationImporter.cpp @@ -525,9 +525,9 @@ void AnimationImporter::Assign_transform_animations( bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE; /* to check if the no of curves are valid */ - bool xyz = ((tm_type == COLLADAFW::Transformation::TRANSLATE || - tm_type == COLLADAFW::Transformation::SCALE) && - binding->animationClass == COLLADAFW::AnimationList::POSITION_XYZ); + bool xyz = + (ELEM(tm_type, COLLADAFW::Transformation::TRANSLATE, COLLADAFW::Transformation::SCALE) && + binding->animationClass == COLLADAFW::AnimationList::POSITION_XYZ); if (!((!xyz && curves->size() == 1) || (xyz && curves->size() == 3) || is_matrix)) { fprintf(stderr, "expected %d curves, got %d\n", xyz ? 3 : 1, int(curves->size())); @@ -1510,8 +1510,9 @@ void AnimationImporter::find_frames_old(std::vector *frames, /* for each AnimationBinding get the fcurves which animate the transform */ for (uint j = 0; j < bindings.getCount(); j++) { std::vector &curves = curve_map[bindings[j].animation]; - bool xyz = ((nodeTmType == COLLADAFW::Transformation::TRANSLATE || - nodeTmType == COLLADAFW::Transformation::SCALE) && + bool xyz = (ELEM(nodeTmType, + COLLADAFW::Transformation::TRANSLATE, + COLLADAFW::Transformation::SCALE) && bindings[j].animationClass == COLLADAFW::AnimationList::POSITION_XYZ); if ((!xyz && curves.size() == 1) || (xyz && curves.size() == 3) || is_matrix) { @@ -1883,8 +1884,11 @@ bool AnimationImporter::evaluate_animation(COLLADAFW::Transformation *tm, const COLLADAFW::UniqueId &listid = tm->getAnimationList(); COLLADAFW::Transformation::TransformationType type = tm->getTransformationType(); - if (type != COLLADAFW::Transformation::ROTATE && type != COLLADAFW::Transformation::SCALE && - type != COLLADAFW::Transformation::TRANSLATE && type != COLLADAFW::Transformation::MATRIX) { + if (!ELEM(type, + COLLADAFW::Transformation::ROTATE, + COLLADAFW::Transformation::SCALE, + COLLADAFW::Transformation::TRANSLATE, + COLLADAFW::Transformation::MATRIX)) { fprintf(stderr, "animation of transformation %d is not supported yet\n", type); return false; } diff --git a/source/blender/io/collada/BCAnimationCurve.cpp b/source/blender/io/collada/BCAnimationCurve.cpp index 710758bd77b..ac7fa81883a 100644 --- a/source/blender/io/collada/BCAnimationCurve.cpp +++ b/source/blender/io/collada/BCAnimationCurve.cpp @@ -329,8 +329,7 @@ bool BCAnimationCurve::is_transform_curve() const bool BCAnimationCurve::is_rotation_curve() const { std::string channel_type = this->get_channel_type(); - return (channel_type == "rotation" || channel_type == "rotation_euler" || - channel_type == "rotation_quaternion"); + return ELEM(channel_type, "rotation", "rotation_euler", "rotation_quaternion"); } float BCAnimationCurve::get_value(const float frame) diff --git a/source/blender/io/collada/BCSampleData.cpp b/source/blender/io/collada/BCSampleData.cpp index 42b436ec6fb..422ecdc598f 100644 --- a/source/blender/io/collada/BCSampleData.cpp +++ b/source/blender/io/collada/BCSampleData.cpp @@ -51,7 +51,7 @@ bool BCSample::get_value(std::string channel_target, const int array_index, floa else if (channel_type == "scale") { *val = matrix->scale()[array_index]; } - else if (channel_type == "rotation" || channel_type == "rotation_euler") { + else if (ELEM(channel_type, "rotation", "rotation_euler")) { *val = matrix->rotation()[array_index]; } else if (channel_type == "rotation_quaternion") { diff --git a/source/blender/io/collada/MeshImporter.cpp b/source/blender/io/collada/MeshImporter.cpp index ce7eada84d6..6d7593afb8b 100644 --- a/source/blender/io/collada/MeshImporter.cpp +++ b/source/blender/io/collada/MeshImporter.cpp @@ -284,7 +284,7 @@ bool MeshImporter::is_nice_mesh(COLLADAFW::Mesh *mesh) const char *type_str = bc_primTypeToStr(type); /* OpenCollada passes POLYGONS type for */ - if (type == COLLADAFW::MeshPrimitive::POLYLIST || type == COLLADAFW::MeshPrimitive::POLYGONS) { + if (ELEM(type, COLLADAFW::MeshPrimitive::POLYLIST, COLLADAFW::MeshPrimitive::POLYGONS)) { COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons *)mp; COLLADAFW::Polygons::VertexCountArray &vca = mpvc->getGroupedVerticesVertexCountArray(); @@ -324,8 +324,9 @@ bool MeshImporter::is_nice_mesh(COLLADAFW::Mesh *mesh) /* TODO: Add Checker for line syntax here */ } - else if (type != COLLADAFW::MeshPrimitive::TRIANGLES && - type != COLLADAFW::MeshPrimitive::TRIANGLE_FANS) { + else if (!ELEM(type, + COLLADAFW::MeshPrimitive::TRIANGLES, + COLLADAFW::MeshPrimitive::TRIANGLE_FANS)) { fprintf(stderr, "ERROR: Primitive type %s is not supported.\n", type_str); return false; } @@ -688,9 +689,10 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, } } - if (collada_meshtype == COLLADAFW::MeshPrimitive::POLYLIST || - collada_meshtype == COLLADAFW::MeshPrimitive::POLYGONS || - collada_meshtype == COLLADAFW::MeshPrimitive::TRIANGLES) { + if (ELEM(collada_meshtype, + COLLADAFW::MeshPrimitive::POLYLIST, + COLLADAFW::MeshPrimitive::POLYGONS, + COLLADAFW::MeshPrimitive::TRIANGLES)) { COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons *)mp; uint start_index = 0; diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index 3546beb022c..d1af4553083 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -562,7 +562,7 @@ void USDMaterialReader::follow_connection(const pxr::UsdShadeInput &usd_input, /* For now, only convert UsdUVTexture and UsdPrimvarReader_float2 inputs. */ if (shader_id == usdtokens::UsdUVTexture) { - if (strcmp(dest_socket_name, "Normal") == 0) { + if (STREQ(dest_socket_name, "Normal")) { /* The normal texture input requires creating a normal map node. */ float locx = 0.0f; diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 6862f3835cf..c195bf0e0bd 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -455,7 +455,7 @@ static bNode *traverse_channel(bNodeSocket *input, const short target_type) static bNode *find_bsdf_node(Material *material) { LISTBASE_FOREACH (bNode *, node, &material->nodetree->nodes) { - if (node->type == SH_NODE_BSDF_PRINCIPLED || node->type == SH_NODE_BSDF_DIFFUSE) { + if (ELEM(node->type, SH_NODE_BSDF_PRINCIPLED, SH_NODE_BSDF_DIFFUSE)) { return node; } } @@ -707,7 +707,7 @@ static void export_texture(bNode *node, const pxr::UsdStageRefPtr stage, const bool allow_overwrite) { - if (node->type != SH_NODE_TEX_IMAGE && node->type != SH_NODE_TEX_ENVIRONMENT) { + if (!ELEM(node->type, SH_NODE_TEX_IMAGE, SH_NODE_TEX_ENVIRONMENT)) { return; } diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index e40f7db0b1f..cd97d5fb485 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -87,7 +87,7 @@ class obj_importer_test : public BlendfileLoadingBaseTest { ASSERT_STREQ(object->id.name, exp.name.c_str()); EXPECT_EQ(object->type, exp.type); EXPECT_V3_NEAR(object->loc, float3(0, 0, 0), 0.0001f); - if (strcmp(object->id.name, "OBCube") != 0) { + if (!STREQ(object->id.name, "OBCube")) { EXPECT_V3_NEAR(object->rot, float3(M_PI_2, 0, 0), 0.0001f); } EXPECT_V3_NEAR(object->scale, float3(1, 1, 1), 0.0001f); -- cgit v1.2.3