Cleanup: replace use of std::iota with more specific function
`iota` is name that has no meaning, it's not an acronym or initialism. It's usually very cryptic when I come across it. Replacing it with a specialized function makes the code more readible.
This commit is contained in:
parent
4cbcaf51cb
commit
144a5aa512
|
@ -16,6 +16,7 @@
|
|||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "BLI_array_utils.hh"
|
||||
#include "BLI_map.hh"
|
||||
#include "BLI_math_geom.h"
|
||||
#include "BLI_math_matrix.h"
|
||||
|
@ -2044,7 +2045,7 @@ void BKE_mesh_legacy_convert_polys_to_offsets(Mesh *mesh)
|
|||
else {
|
||||
/* Reorder mesh polygons to match the order of their loops. */
|
||||
Array<int> orig_indices(polys.size());
|
||||
std::iota(orig_indices.begin(), orig_indices.end(), 0);
|
||||
array_utils::fill_index_range<int>(orig_indices);
|
||||
std::stable_sort(orig_indices.begin(), orig_indices.end(), [polys](const int a, const int b) {
|
||||
return polys[a].loopstart < polys[b].loopstart;
|
||||
});
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <climits>
|
||||
|
||||
#include "BLI_array_utils.hh"
|
||||
#include "BLI_bitmap.h"
|
||||
#include "BLI_math_geom.h"
|
||||
#include "BLI_math_matrix.h"
|
||||
|
@ -647,7 +648,7 @@ static void pbvh_build(PBVH *pbvh,
|
|||
pbvh->nodes.clear_and_shrink();
|
||||
|
||||
pbvh->prim_indices.reinitialize(totprim);
|
||||
std::iota(pbvh->prim_indices.begin(), pbvh->prim_indices.end(), 0);
|
||||
blender::array_utils::fill_index_range<int>(pbvh->prim_indices);
|
||||
}
|
||||
|
||||
pbvh->nodes.resize(1);
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <numeric>
|
||||
|
||||
#include "BLI_generic_span.hh"
|
||||
#include "BLI_generic_virtual_array.hh"
|
||||
#include "BLI_index_mask.hh"
|
||||
|
@ -194,4 +196,13 @@ template<typename T> inline Vector<IndexRange> find_all_ranges(const Span<T> spa
|
|||
return ranges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the span with increasing indices: 0, 1, 2, ...
|
||||
* Optionally, the start value can be provided.
|
||||
*/
|
||||
template<typename T> inline void fill_index_range(MutableSpan<T> span, const T start = 0)
|
||||
{
|
||||
std::iota(span.begin(), span.end(), start);
|
||||
}
|
||||
|
||||
} // namespace blender::array_utils
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "BLI_array_utils.hh"
|
||||
#include "BLI_kdtree.h"
|
||||
#include "BLI_offset_indices.hh"
|
||||
#include "BLI_task.hh"
|
||||
|
@ -50,7 +51,7 @@ PointCloud *point_merge_by_distance(const PointCloud &src_points,
|
|||
* finding, converting from indices into the selection to indices into the full input point
|
||||
* cloud. */
|
||||
Array<int> merge_indices(src_size);
|
||||
std::iota(merge_indices.begin(), merge_indices.end(), 0);
|
||||
array_utils::fill_index_range<int>(merge_indices);
|
||||
|
||||
selection.foreach_index([&](const int src_index, const int pos) {
|
||||
const int merge_index = selection_merge_indices[pos];
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_array_utils.hh"
|
||||
#include "BLI_bitmap.h"
|
||||
#include "BLI_linklist.h"
|
||||
#include "BLI_math_vector.h"
|
||||
|
@ -246,8 +247,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
|
|||
start_item.curr_strength = FACE_STRENGTH_WEAK;
|
||||
items_data = Array<WeightedNormalDataAggregateItem>(verts_num, start_item);
|
||||
lnors_spacearr.corner_space_indices.reinitialize(corner_verts.size());
|
||||
std::iota(
|
||||
lnors_spacearr.corner_space_indices.begin(), lnors_spacearr.corner_space_indices.end(), 0);
|
||||
array_utils::fill_index_range<int>(lnors_spacearr.corner_space_indices);
|
||||
}
|
||||
wn_data->items_data = items_data;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "BKE_curves.hh"
|
||||
|
||||
#include "BLI_array_utils.hh"
|
||||
#include "BLI_task.hh"
|
||||
|
||||
#include "node_geometry_util.hh"
|
||||
|
@ -91,7 +92,7 @@ class PointsOfCurveInput final : public bke::CurvesFieldInput {
|
|||
* when accessing values in the sort weights. However, it means a separate array of
|
||||
* indices within the compressed array is necessary for sorting. */
|
||||
sort_indices.reinitialize(points.size());
|
||||
std::iota(sort_indices.begin(), sort_indices.end(), 0);
|
||||
array_utils::fill_index_range<int>(sort_indices);
|
||||
std::stable_sort(sort_indices.begin(), sort_indices.end(), [&](int a, int b) {
|
||||
return sort_weights[a] < sort_weights[b];
|
||||
});
|
||||
|
|
|
@ -536,8 +536,8 @@ static void duplicate_faces(GeometrySet &geometry_set,
|
|||
face_index++;
|
||||
}
|
||||
});
|
||||
std::iota(new_corner_verts.begin(), new_corner_verts.end(), 0);
|
||||
std::iota(new_corner_edges.begin(), new_corner_edges.end(), 0);
|
||||
array_utils::fill_index_range<int>(new_corner_verts);
|
||||
array_utils::fill_index_range<int>(new_corner_edges);
|
||||
|
||||
new_mesh->tag_loose_verts_none();
|
||||
new_mesh->tag_loose_edges_none();
|
||||
|
@ -762,7 +762,7 @@ static void duplicate_points_curve(GeometrySet &geometry_set,
|
|||
bke::curves_copy_parameters(src_curves_id, *new_curves_id);
|
||||
bke::CurvesGeometry &new_curves = new_curves_id->geometry.wrap();
|
||||
MutableSpan<int> new_curve_offsets = new_curves.offsets_for_write();
|
||||
std::iota(new_curve_offsets.begin(), new_curve_offsets.end(), 0);
|
||||
array_utils::fill_index_range(new_curve_offsets);
|
||||
|
||||
for (auto &attribute : bke::retrieve_attributes_for_transfer(src_curves.attributes(),
|
||||
new_curves.attributes_for_write(),
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include "UI_interface.hh"
|
||||
#include "UI_resources.hh"
|
||||
|
||||
#include "BLI_array_utils.hh"
|
||||
|
||||
#include "GEO_mesh_primitive_uv_sphere.hh"
|
||||
|
||||
#include "node_geometry_util.hh"
|
||||
|
@ -159,8 +161,8 @@ static Mesh *create_circle_mesh(const float radius,
|
|||
face_offsets.first() = 0;
|
||||
face_offsets.last() = corner_verts.size();
|
||||
|
||||
std::iota(corner_verts.begin(), corner_verts.end(), 0);
|
||||
std::iota(corner_edges.begin(), corner_edges.end(), 0);
|
||||
array_utils::fill_index_range<int>(corner_verts);
|
||||
array_utils::fill_index_range<int>(corner_edges);
|
||||
|
||||
mesh->tag_loose_edges_none();
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ class CornersOfEdgeInput final : public bke::MeshFieldInput {
|
|||
* when accessing values in the sort weights. However, it means a separate array of
|
||||
* indices within the compressed array is necessary for sorting. */
|
||||
sort_indices.reinitialize(corners.size());
|
||||
std::iota(sort_indices.begin(), sort_indices.end(), 0);
|
||||
array_utils::fill_index_range<int>(sort_indices);
|
||||
std::stable_sort(sort_indices.begin(), sort_indices.end(), [&](int a, int b) {
|
||||
return sort_weights[a] < sort_weights[b];
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "BLI_array_utils.hh"
|
||||
#include "BLI_task.hh"
|
||||
|
||||
#include "BKE_mesh.hh"
|
||||
|
@ -92,7 +93,7 @@ class CornersOfFaceInput final : public bke::MeshFieldInput {
|
|||
* when accessing values in the sort weights. However, it means a separate array of
|
||||
* indices within the compressed array is necessary for sorting. */
|
||||
sort_indices.reinitialize(corners.size());
|
||||
std::iota(sort_indices.begin(), sort_indices.end(), 0);
|
||||
array_utils::fill_index_range<int>(sort_indices);
|
||||
std::stable_sort(sort_indices.begin(), sort_indices.end(), [&](int a, int b) {
|
||||
return sort_weights[a] < sort_weights[b];
|
||||
});
|
||||
|
|
|
@ -99,7 +99,7 @@ class CornersOfVertInput final : public bke::MeshFieldInput {
|
|||
* when accessing values in the sort weights. However, it means a separate array of
|
||||
* indices within the compressed array is necessary for sorting. */
|
||||
sort_indices.reinitialize(corners.size());
|
||||
std::iota(sort_indices.begin(), sort_indices.end(), 0);
|
||||
array_utils::fill_index_range<int>(sort_indices);
|
||||
std::stable_sort(sort_indices.begin(), sort_indices.end(), [&](int a, int b) {
|
||||
return sort_weights[a] < sort_weights[b];
|
||||
});
|
||||
|
|
|
@ -103,7 +103,7 @@ class EdgesOfVertInput final : public bke::MeshFieldInput {
|
|||
* when accessing values in the sort weights. However, it means a separate array of
|
||||
* indices within the compressed array is necessary for sorting. */
|
||||
sort_indices.reinitialize(edges.size());
|
||||
std::iota(sort_indices.begin(), sort_indices.end(), 0);
|
||||
array_utils::fill_index_range<int>(sort_indices);
|
||||
std::stable_sort(sort_indices.begin(), sort_indices.end(), [&](int a, int b) {
|
||||
return sort_weights[a] < sort_weights[b];
|
||||
});
|
||||
|
|
|
@ -99,7 +99,7 @@ static Curves *curve_from_points(const AttributeAccessor attributes,
|
|||
return curves_id;
|
||||
}
|
||||
Array<int> indices(domain_size);
|
||||
std::iota(indices.begin(), indices.end(), 0);
|
||||
array_utils::fill_index_range<int>(indices);
|
||||
const VArraySpan<float> weights(weights_varray);
|
||||
grouped_sort(OffsetIndices<int>({0, domain_size}), weights, indices);
|
||||
bke::gather_attributes(
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "NOD_multi_function.hh"
|
||||
#include "NOD_node_declaration.hh"
|
||||
|
||||
#include "BLI_array_utils.hh"
|
||||
#include "BLI_bit_group_vector.hh"
|
||||
#include "BLI_bit_span_ops.hh"
|
||||
#include "BLI_cpp_types.hh"
|
||||
|
@ -1752,17 +1753,17 @@ class LazyFunctionForRepeatZone : public LazyFunction {
|
|||
* outside of this graph. */
|
||||
eval_storage.output_index_map.reinitialize(outputs_.size() - 1);
|
||||
eval_storage.input_index_map.resize(inputs_.size() - 1);
|
||||
std::iota(eval_storage.input_index_map.begin(), eval_storage.input_index_map.end(), 1);
|
||||
array_utils::fill_index_range<int>(eval_storage.input_index_map, 1);
|
||||
|
||||
Vector<const lf::GraphInputSocket *> lf_graph_inputs = lf_inputs.as_span().drop_front(1);
|
||||
|
||||
const int iteration_usage_index = zone_info_.indices.outputs.input_usages[0];
|
||||
std::iota(eval_storage.output_index_map.begin(),
|
||||
eval_storage.output_index_map.begin() + iteration_usage_index,
|
||||
0);
|
||||
std::iota(eval_storage.output_index_map.begin() + iteration_usage_index,
|
||||
eval_storage.output_index_map.end(),
|
||||
iteration_usage_index + 1);
|
||||
array_utils::fill_index_range<int>(
|
||||
eval_storage.output_index_map.as_mutable_span().take_front(iteration_usage_index));
|
||||
array_utils::fill_index_range<int>(
|
||||
eval_storage.output_index_map.as_mutable_span().drop_front(iteration_usage_index),
|
||||
iteration_usage_index + 1);
|
||||
|
||||
Vector<const lf::GraphOutputSocket *> lf_graph_outputs = lf_outputs.as_span().take_front(
|
||||
iteration_usage_index);
|
||||
lf_graph_outputs.extend(lf_outputs.as_span().drop_front(iteration_usage_index + 1));
|
||||
|
@ -2074,7 +2075,7 @@ struct GeometryNodesLazyFunctionBuilder {
|
|||
{
|
||||
/* Build nested zones first. */
|
||||
Array<int> zone_build_order(tree_zones_->zones.size());
|
||||
std::iota(zone_build_order.begin(), zone_build_order.end(), 0);
|
||||
array_utils::fill_index_range<int>(zone_build_order);
|
||||
std::sort(
|
||||
zone_build_order.begin(), zone_build_order.end(), [&](const int zone_a, const int zone_b) {
|
||||
return tree_zones_->zones[zone_a]->depth > tree_zones_->zones[zone_b]->depth;
|
||||
|
|
Loading…
Reference in New Issue