1
1

Cleanup: use ELEM macro

This commit is contained in:
2022-09-23 15:24:20 +10:00
parent c655bdfa31
commit fbd78a8d78
15 changed files with 37 additions and 36 deletions

View File

@@ -114,7 +114,7 @@ void *GHOST_DropTargetX11::getURIListGhostData(unsigned char *dropBuffer, int dr
/* Count total number of file paths in buffer. */
for (int i = 0; i <= dropBufferSize; i++) {
if (dropBuffer[i] == 0 || dropBuffer[i] == '\n' || dropBuffer[i] == '\r') {
if (ELEM(dropBuffer[i], 0, '\n', '\r')) {
if (curLength) {
totPaths++;
curLength = 0;
@@ -131,7 +131,7 @@ void *GHOST_DropTargetX11::getURIListGhostData(unsigned char *dropBuffer, int dr
curLength = 0;
for (int i = 0; i <= dropBufferSize; i++) {
if (dropBuffer[i] == 0 || dropBuffer[i] == '\n' || dropBuffer[i] == '\r') {
if (ELEM(dropBuffer[i], 0, '\n', '\r')) {
if (curLength) {
char *curPath = (char *)malloc(curLength + 1);
char *decodedPath;
@@ -182,7 +182,7 @@ void *GHOST_DropTargetX11::getGhostData(Atom dropType,
data = decodedPath;
}
}
else if (dropType == dndTypePlainText || dropType == dndTypeOctetStream) {
else if (ELEM(dropType, dndTypePlainText, dndTypeOctetStream)) {
m_draggedObjectType = GHOST_kDragnDropTypeString;
data = tmpBuffer;
needsFree = false;

View File

@@ -217,7 +217,7 @@ GHOST_WindowX11::GHOST_WindowX11(GHOST_SystemX11 *system,
* So, m_post_init indicate that we need wait for the MapNotify
* event and then set the Window state to the m_post_state.
*/
else if ((state != GHOST_kWindowStateNormal) && (state != GHOST_kWindowStateMinimized)) {
else if (!ELEM(state, GHOST_kWindowStateNormal, GHOST_kWindowStateMinimized)) {
m_post_init = True;
m_post_state = state;
}

View File

@@ -677,7 +677,7 @@ static void copy_frame_to_eval_cb(bGPDlayer *gpl,
* - When the frame is the layer's active frame (already handled in
* gpencil_copy_visible_frames_to_eval).
*/
if (gpf == NULL || gpf == gpl->actframe) {
if (ELEM(gpf, NULL, gpl->actframe)) {
return;
}

View File

@@ -5148,7 +5148,7 @@ bool BKE_image_has_alpha(Image *image)
const int planes = (ibuf ? ibuf->planes : 0);
BKE_image_release_ibuf(image, ibuf, lock);
if (planes == 32 || planes == 16) {
if (ELEM(planes, 32, 16)) {
return true;
}

View File

@@ -1228,7 +1228,7 @@ static void scene_blend_read_data(BlendDataReader *reader, ID *id)
}
/* Active channels root pointer. */
if (ed->displayed_channels == old_displayed_channels || ed->displayed_channels == nullptr) {
if (ELEM(ed->displayed_channels, old_displayed_channels, nullptr)) {
ed->displayed_channels = &ed->channels;
}
else {
@@ -1263,7 +1263,7 @@ static void scene_blend_read_data(BlendDataReader *reader, ID *id)
}
}
if (ms->old_channels == old_displayed_channels || ms->old_channels == nullptr) {
if (ELEM(ms->old_channels, old_displayed_channels, nullptr)) {
ms->old_channels = &ed->channels;
}
else {

View File

@@ -4799,7 +4799,7 @@ static float projected_boundary_area(BevVert *bv, BMFace *f)
find_face_internal_boundverts(bv, f, unsnapped);
do {
float *co = v->nv.v->co;
if (v == unsnapped[0] || v == unsnapped[1] || v == unsnapped[2]) {
if (ELEM(v, unsnapped[0], unsnapped[1], unsnapped[2])) {
mul_v2_m3v3(proj_co[i], axis_mat, co);
}
else {
@@ -4922,7 +4922,7 @@ static void build_center_ngon(BevelParams *bp, BMesh *bm, BevVert *bv, int mat_n
BLI_array_append(vv, mesh_vert(vm, i, ns2, ns2)->v);
if (frep) {
BLI_array_append(vf, frep);
if (v == frep_unsnapped[0] || v == frep_unsnapped[1] || v == frep_unsnapped[2]) {
if (ELEM(v, frep_unsnapped[0], frep_unsnapped[1], frep_unsnapped[2])) {
BLI_array_append(ve, NULL);
}
else {
@@ -5299,7 +5299,7 @@ static void snap_edges_for_vmesh_vert(int i,
int previ = (i + n_bndv - 1) % n_bndv;
/* Make jj and kk be the j and k indices for this corner. */
int jj = corner < 2 ? j : j + 1;
int kk = (corner == 0 || corner == 3) ? k : k + 1;
int kk = ELEM(corner, 0, 3) ? k : k + 1;
if (jj < ns2 && kk < ns2) {
; /* No snap. */
}
@@ -5765,7 +5765,7 @@ static BMFace *bevel_build_poly(BevelParams *bp, BMesh *bm, BevVert *bv)
BLI_array_append(bmverts, bndv->nv.v);
if (repface) {
BLI_array_append(bmfaces, repface);
if (bndv == unsnapped[0] || bndv == unsnapped[1] || bndv == unsnapped[2]) {
if (ELEM(bndv, unsnapped[0], unsnapped[1], unsnapped[2])) {
BLI_array_append(bmedges, NULL);
}
else {

View File

@@ -1366,12 +1366,10 @@ static bool make_cyclic_if_endpoints(ViewContext *vc,
BPoint *sel_bp)
{
if (sel_bezt || (sel_bp && sel_nu->pntsu > 2)) {
const bool is_bezt_endpoint = (sel_nu->type == CU_BEZIER &&
(sel_bezt == sel_nu->bezt ||
sel_bezt == sel_nu->bezt + sel_nu->pntsu - 1));
const bool is_bp_endpoint = (sel_nu->type != CU_BEZIER &&
(sel_bp == sel_nu->bp ||
sel_bp == sel_nu->bp + sel_nu->pntsu - 1));
const bool is_bezt_endpoint = ((sel_nu->type == CU_BEZIER) &&
ELEM(sel_bezt, sel_nu->bezt, sel_nu->bezt + sel_nu->pntsu - 1));
const bool is_bp_endpoint = ((sel_nu->type != CU_BEZIER) &&
ELEM(sel_bp, sel_nu->bp, sel_nu->bp + sel_nu->pntsu - 1));
if (!(is_bezt_endpoint || is_bp_endpoint)) {
return false;
}
@@ -1388,9 +1386,8 @@ static bool make_cyclic_if_endpoints(ViewContext *vc,
if (nu == sel_nu &&
((nu->type == CU_BEZIER && bezt != sel_bezt &&
(bezt == nu->bezt || bezt == nu->bezt + nu->pntsu - 1) && bezt_idx == 1) ||
(nu->type != CU_BEZIER && bp != sel_bp &&
(bp == nu->bp || bp == nu->bp + nu->pntsu - 1)))) {
ELEM(bezt, nu->bezt, nu->bezt + nu->pntsu - 1) && bezt_idx == 1) ||
(nu->type != CU_BEZIER && bp != sel_bp && ELEM(bp, nu->bp, nu->bp + nu->pntsu - 1)))) {
View3D *v3d = vc->v3d;
ListBase *nurbs = object_editcurve_get(vc->obedit);
curve_toggle_cyclic(v3d, nurbs, 0);

View File

@@ -334,7 +334,7 @@ static bool clip_uv_transform_rotate(const TransInfo *t, float *vec, float *vec_
for (int i = 0; i < max_i; i++) {
/* Binary search. */
const float angle_mid = (angle_inside_bounds + angle) / 2.0f;
if (angle_mid == angle_inside_bounds || angle_mid == angle) {
if (ELEM(angle_mid, angle_inside_bounds, angle)) {
break; /* float precision reached. */
}
if (uv_rotation_in_clip_bounds_test(t, angle_mid)) {

View File

@@ -1908,8 +1908,7 @@ static void lineart_load_tri_task(void *__restrict userdata,
else if (ob_info->usage == OBJECT_LRT_FORCE_INTERSECTION) {
tri->flags |= LRT_TRIANGLE_FORCE_INTERSECTION;
}
else if (ob_info->usage == OBJECT_LRT_NO_INTERSECTION ||
ob_info->usage == OBJECT_LRT_OCCLUSION_ONLY) {
else if (ELEM(ob_info->usage, OBJECT_LRT_NO_INTERSECTION, OBJECT_LRT_OCCLUSION_ONLY)) {
tri->flags |= LRT_TRIANGLE_NO_INTERSECTION;
}
@@ -2254,8 +2253,11 @@ static void lineart_geometry_object_load(LineartObjectInfo *ob_info,
}
}
if (usage == OBJECT_LRT_INHERIT || usage == OBJECT_LRT_INCLUDE ||
usage == OBJECT_LRT_NO_INTERSECTION || usage == OBJECT_LRT_FORCE_INTERSECTION) {
if (ELEM(usage,
OBJECT_LRT_INHERIT,
OBJECT_LRT_INCLUDE,
OBJECT_LRT_NO_INTERSECTION,
OBJECT_LRT_FORCE_INTERSECTION)) {
lineart_add_edge_to_array_thread(ob_info, la_edge);
}
@@ -2283,8 +2285,11 @@ static void lineart_geometry_object_load(LineartObjectInfo *ob_info,
la_edge->object_ref = orig_ob;
la_edge->edge_identifier = LRT_EDGE_IDENTIFIER(ob_info, la_edge);
BLI_addtail(&la_edge->segments, la_seg);
if (usage == OBJECT_LRT_INHERIT || usage == OBJECT_LRT_INCLUDE ||
usage == OBJECT_LRT_NO_INTERSECTION || usage == OBJECT_LRT_FORCE_INTERSECTION) {
if (ELEM(usage,
OBJECT_LRT_INHERIT,
OBJECT_LRT_INCLUDE,
OBJECT_LRT_NO_INTERSECTION,
OBJECT_LRT_FORCE_INTERSECTION)) {
lineart_add_edge_to_array_thread(ob_info, la_edge);
if (shadow_eln) {
LineartEdge *shadow_e = lineart_find_matching_edge(shadow_eln, la_edge->edge_identifier);

View File

@@ -109,8 +109,7 @@ struct GPUSource {
}
if ((source.find("drw_debug_") != StringRef::not_found) &&
/* Avoid these two files where it makes no sense to add the dependency. */
(filename != "common_debug_draw_lib.glsl" &&
filename != "draw_debug_draw_display_vert.glsl")) {
(!ELEM(filename, "common_debug_draw_lib.glsl", "draw_debug_draw_display_vert.glsl"))) {
builtins |= shader::BuiltinBits::USE_DEBUG_DRAW;
}
check_no_quotes();

View File

@@ -97,7 +97,7 @@ class StringBuffer {
start++;
}
fast_float::from_chars_result res = fast_float::from_chars(start, end, out);
if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) {
if (ELEM(res.ec, std::errc::invalid_argument, std::errc::result_out_of_range)) {
out = 0.0f;
}
start = const_cast<char *>(res.ptr);

View File

@@ -103,7 +103,7 @@ static void geom_add_mrgb_colors(const char *p, const char *end, GlobalVertices
while (p + mrgb_length <= end) {
uint32_t value = 0;
std::from_chars_result res = std::from_chars(p, p + mrgb_length, value, 16);
if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) {
if (ELEM(res.ec, std::errc::invalid_argument, std::errc::result_out_of_range)) {
return;
}
unsigned char srgb[4];

View File

@@ -123,7 +123,7 @@ static Image *load_texture_image(Main *bmain, const MTLTexMap &tex_map, bool rel
/* Try replacing underscores with spaces. */
std::string no_underscore_path{no_quote_path};
std::replace(no_underscore_path.begin(), no_underscore_path.end(), '_', ' ');
if (no_underscore_path != no_quote_path && no_underscore_path != tex_path) {
if (!ELEM(no_underscore_path, no_quote_path, tex_path)) {
image = load_image_at_path(bmain, no_underscore_path, relative_paths);
if (image != nullptr) {
return image;

View File

@@ -94,7 +94,7 @@ const char *parse_float(const char *p,
}
p = drop_plus(p, end);
fast_float::from_chars_result res = fast_float::from_chars(p, end, dst);
if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) {
if (ELEM(res.ec, std::errc::invalid_argument, std::errc::result_out_of_range)) {
dst = fallback;
}
else if (require_trailing_space && res.ptr < end && !is_whitespace(*res.ptr)) {
@@ -125,7 +125,7 @@ const char *parse_int(const char *p, const char *end, int fallback, int &dst, bo
}
p = drop_plus(p, end);
std::from_chars_result res = std::from_chars(p, end, dst);
if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) {
if (ELEM(res.ec, std::errc::invalid_argument, std::errc::result_out_of_range)) {
dst = fallback;
}
return res.ptr;

View File

@@ -1503,7 +1503,7 @@ static void surfacedeformModifier_do(ModifierData *md,
ob, md, "Target polygons changed from %u to %u", smd->target_polys_num, target_polys_num);
return;
}
if (smd->target_verts_num != 0 && smd->target_verts_num != target_verts_num) {
if (!ELEM(smd->target_verts_num, 0, target_verts_num)) {
if (smd->target_verts_num > target_verts_num) {
/* Number of vertices on the target did reduce. There is no usable recovery from this. */
BKE_modifier_set_error(ob,