diff options
author | Hans Goudey <h.goudey@me.com> | 2022-04-07 00:30:27 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-04-07 00:30:27 +0300 |
commit | 8551e890687de7185388eed9e77171b0df7943a3 (patch) | |
tree | 7833056784792f3a46ac8fb6bd9776f3ced33367 /source/blender/nodes | |
parent | 8b04308953adae983562026a2aa7bbd38e74174d (diff) |
Curves: Name mutable data retrieval functions explicitly
Add "for_write" on function names that retrieve mutable data arrays.
Though this makes function names longer, it's likely worth it because
it allows more easily using the const functions in a non-const context,
and reduces cases of mistakenly retrieving with edit access.
In the long term, this situation might change more if we implement
attributes storage that is accessible directly on `CurvesGeometry`
without duplicating the attribute API on geometry components,
which is currently the rough plan.
Differential Revision: https://developer.blender.org/D14562
Diffstat (limited to 'source/blender/nodes')
12 files changed, 43 insertions, 42 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc index 38d81c54933..ba8c9a893c2 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc @@ -171,7 +171,7 @@ static Curves *create_arc_curve_from_points(const int resolution, const int stepcount = resolution - 1; const int centerpoint = resolution; - MutableSpan<float3> positions = curves.positions(); + MutableSpan<float3> positions = curves.positions_for_write(); const bool is_colinear = colinear_f3_f3_f3(a, b, c); @@ -261,7 +261,7 @@ static Curves *create_arc_curve_from_points(const int resolution, } if (connect_center) { - curves.cyclic().first() = true; + curves.cyclic_for_write().first() = true; positions[centerpoint] = center; } @@ -289,7 +289,7 @@ static Curves *create_arc_curve_from_radius(const int resolution, const int stepcount = resolution - 1; const int centerpoint = resolution; - MutableSpan<float3> positions = curves.positions(); + MutableSpan<float3> positions = curves.positions_for_write(); const float sweep = (invert_arc) ? -(2.0f * M_PI - sweep_angle) : sweep_angle; @@ -302,7 +302,7 @@ static Curves *create_arc_curve_from_radius(const int resolution, } if (connect_center) { - curves.cyclic().first() = true; + curves.cyclic_for_write().first() = true; positions[centerpoint] = float3(0.0f, 0.0f, 0.0f); } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc index 297674e11f4..875664c41fa 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc @@ -64,17 +64,17 @@ static Curves *create_bezier_segment_curve(const float3 start, { Curves *curves_id = bke::curves_new_nomain_single(2, CURVE_TYPE_BEZIER); bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); - curves.resolution().fill(resolution); + curves.resolution_for_write().fill(resolution); - MutableSpan<float3> positions = curves.positions(); - curves.handle_types_left().fill(BEZIER_HANDLE_ALIGN); - curves.handle_types_right().fill(BEZIER_HANDLE_ALIGN); + MutableSpan<float3> positions = curves.positions_for_write(); + curves.handle_types_left_for_write().fill(BEZIER_HANDLE_ALIGN); + curves.handle_types_right_for_write().fill(BEZIER_HANDLE_ALIGN); positions.first() = start; positions.last() = end; - MutableSpan<float3> handles_right = curves.handle_positions_right(); - MutableSpan<float3> handles_left = curves.handle_positions_left(); + MutableSpan<float3> handles_right = curves.handle_positions_right_for_write(); + MutableSpan<float3> handles_left = curves.handle_positions_left_for_write(); if (mode == GEO_NODE_CURVE_PRIMITIVE_BEZIER_SEGMENT_POSITION) { handles_left.first() = 2.0f * start - start_handle_right; diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc index aa4b3a785f1..c33ba3e2a4c 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc @@ -111,9 +111,9 @@ static Curves *create_point_circle_curve( Curves *curves_id = bke::curves_new_nomain_single(resolution, CURVE_TYPE_POLY); bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); - curves.cyclic().first() = true; + curves.cyclic_for_write().first() = true; - MutableSpan<float3> positions = curves.positions(); + MutableSpan<float3> positions = curves.positions_for_write(); float3 center; /* Midpoints of `P1->P2` and `P2->P3`. */ @@ -164,9 +164,9 @@ static Curves *create_radius_circle_curve(const int resolution, const float radi { Curves *curves_id = bke::curves_new_nomain_single(resolution, CURVE_TYPE_POLY); bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); - curves.cyclic().first() = true; + curves.cyclic_for_write().first() = true; - MutableSpan<float3> positions = curves.positions(); + MutableSpan<float3> positions = curves.positions_for_write(); const float theta_step = (2.0f * M_PI) / float(resolution); for (int i : IndexRange(resolution)) { diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc index 62dbcc91cc6..4cfa606d8eb 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc @@ -73,8 +73,8 @@ static Curves *create_point_line_curve(const float3 start, const float3 end) Curves *curves_id = bke::curves_new_nomain_single(2, CURVE_TYPE_POLY); bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); - curves.positions().first() = start; - curves.positions().last() = end; + curves.positions_for_write().first() = start; + curves.positions_for_write().last() = end; return curves_id; } @@ -86,8 +86,8 @@ static Curves *create_direction_line_curve(const float3 start, Curves *curves_id = bke::curves_new_nomain_single(2, CURVE_TYPE_POLY); bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); - curves.positions().first() = start; - curves.positions().last() = math::normalize(direction) * length + start; + curves.positions_for_write().first() = start; + curves.positions_for_write().last() = math::normalize(direction) * length + start; return curves_id; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc index 37810ccaff5..9eae371d948 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc @@ -36,7 +36,7 @@ static Curves *create_quadratic_bezier_curve(const float3 p1, Curves *curves_id = bke::curves_new_nomain_single(resolution + 1, CURVE_TYPE_POLY); bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); - MutableSpan<float3> positions = curves.positions(); + MutableSpan<float3> positions = curves.positions_for_write(); const float step = 1.0f / resolution; for (const int i : IndexRange(resolution + 1)) { diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc index ad3123a6a4a..fec4e31701f 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc @@ -218,9 +218,9 @@ static void node_geo_exec(GeoNodeExecParams params) Curves *curves_id = bke::curves_new_nomain_single(4, CURVE_TYPE_POLY); bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); - curves.cyclic().first() = true; + curves.cyclic_for_write().first() = true; - MutableSpan<float3> positions = curves.positions(); + MutableSpan<float3> positions = curves.positions_for_write(); switch (mode) { case GEO_NODE_CURVE_PRIMITIVE_QUAD_MODE_RECTANGLE: diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc index 22619577d04..4aaf57d57cb 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc @@ -51,7 +51,7 @@ static Curves *create_spiral_curve(const float rotations, Curves *curves_id = bke::curves_new_nomain_single(totalpoints + 1, CURVE_TYPE_POLY); bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); - MutableSpan<float3> positions = curves.positions(); + MutableSpan<float3> positions = curves.positions_for_write(); for (const int i : IndexRange(totalpoints + 1)) { const float theta = i * delta_theta; diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc index e7e899881cf..91ba5f2845f 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc @@ -40,9 +40,9 @@ static Curves *create_star_curve(const float inner_radius, { Curves *curves_id = bke::curves_new_nomain_single(points * 2, CURVE_TYPE_POLY); bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); - curves.cyclic().first() = true; + curves.cyclic_for_write().first() = true; - MutableSpan<float3> positions = curves.positions(); + MutableSpan<float3> positions = curves.positions_for_write(); const float theta_step = (2.0f * M_PI) / float(points); for (const int i : IndexRange(points)) { diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc index 139b17138fa..fababfd027b 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc @@ -301,7 +301,7 @@ static Curves *resample_to_uniform_count(const CurveComponent &src_component, CD_MASK_ALL, CD_DUPLICATE, src_curves.curves_num()); - MutableSpan<int> dst_offsets = dst_curves.offsets(); + MutableSpan<int> dst_offsets = dst_curves.offsets_for_write(); GeometryComponentFieldContext field_context{src_component, ATTR_DOMAIN_CURVE}; fn::FieldEvaluator evaluator{field_context, src_curves.curves_num()}; @@ -318,12 +318,12 @@ static Curves *resample_to_uniform_count(const CurveComponent &src_component, dst_curves.resize(dst_offsets.last(), dst_curves.curves_num()); /* All resampled curves are poly curves. */ - dst_curves.curve_types().fill_indices(selection, CURVE_TYPE_POLY); + dst_curves.curve_types_for_write().fill_indices(selection, CURVE_TYPE_POLY); VArray<bool> curves_cyclic = src_curves.cyclic(); VArray<int8_t> curve_types = src_curves.curve_types(); Span<float3> evaluated_positions = src_curves.evaluated_positions(); - MutableSpan<float3> dst_positions = dst_curves.positions(); + MutableSpan<float3> dst_positions = dst_curves.positions_for_write(); AttributesForInterpolation attributes; gather_point_attributes_to_interpolate(src_component, dst_component, attributes); @@ -464,8 +464,8 @@ static Curves *resample_to_evaluated(const CurveComponent &src_component, CD_DUPLICATE, src_curves.curves_num()); /* All resampled curves are poly curves. */ - dst_curves.curve_types().fill_indices(selection, CURVE_TYPE_POLY); - MutableSpan<int> dst_offsets = dst_curves.offsets(); + dst_curves.curve_types_for_write().fill_indices(selection, CURVE_TYPE_POLY); + MutableSpan<int> dst_offsets = dst_curves.offsets_for_write(); src_curves.ensure_evaluated_offsets(); threading::parallel_for(selection.index_range(), 4096, [&](IndexRange range) { @@ -480,7 +480,7 @@ static Curves *resample_to_evaluated(const CurveComponent &src_component, /* Create the correct number of uniform-length samples for every selected curve. */ Span<float3> evaluated_positions = src_curves.evaluated_positions(); - MutableSpan<float3> dst_positions = dst_curves.positions(); + MutableSpan<float3> dst_positions = dst_curves.positions_for_write(); AttributesForInterpolation attributes; gather_point_attributes_to_interpolate(src_component, dst_component, attributes); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_set_handle_type.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_set_handle_type.cc index 169f808c473..469d8d8d13b 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_set_handle_type.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_set_handle_type.cc @@ -66,10 +66,10 @@ static void set_type_in_component(CurveComponent &component, const IndexMask selection = evaluator.get_evaluated_selection_as_mask(); if (mode & GEO_NODE_CURVE_HANDLE_LEFT) { - curves.handle_types_left().fill_indices(selection, new_handle_type); + curves.handle_types_left_for_write().fill_indices(selection, new_handle_type); } if (mode & GEO_NODE_CURVE_HANDLE_RIGHT) { - curves.handle_types_right().fill_indices(selection, new_handle_type); + curves.handle_types_right_for_write().fill_indices(selection, new_handle_type); } /* Eagerly calculate automatically derived handle positions if necessary. */ diff --git a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc index 2aa768129cd..1e170dd5350 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc @@ -365,7 +365,7 @@ static void duplicate_curves(GeometrySet &geometry_set, Curves *new_curves_id = bke::curves_new_nomain(dst_points_size, dst_curves_size); bke::CurvesGeometry &new_curves = bke::CurvesGeometry::wrap(new_curves_id->geometry); - MutableSpan<int> all_dst_offsets = new_curves.offsets(); + MutableSpan<int> all_dst_offsets = new_curves.offsets_for_write(); threading::parallel_for(selection.index_range(), 512, [&](IndexRange range) { for (const int i_selection : range) { @@ -818,7 +818,7 @@ static void duplicate_points_curve(GeometrySet &geometry_set, Curves *new_curves_id = bke::curves_new_nomain(dst_size, dst_size); bke::CurvesGeometry &new_curves = bke::CurvesGeometry::wrap(new_curves_id->geometry); - MutableSpan<int> new_curve_offsets = new_curves.offsets(); + MutableSpan<int> new_curve_offsets = new_curves.offsets_for_write(); for (const int i : new_curves.curves_range()) { new_curve_offsets[i] = i; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc index 31b9f1765a5..73e49c7d037 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc @@ -95,14 +95,15 @@ static void set_position_in_component(CurveComponent &component, Span<float3> positions = curves.positions(); const bool use_left = mode == GEO_NODE_CURVE_HANDLE_LEFT; - MutableSpan<int8_t> handle_types = use_left ? curves.handle_types_left() : - curves.handle_types_right(); - MutableSpan<int8_t> handle_types_other = use_left ? curves.handle_types_right() : - curves.handle_types_left(); - MutableSpan<float3> handle_positions = use_left ? curves.handle_positions_left() : - curves.handle_positions_right(); - MutableSpan<float3> handle_positions_other = use_left ? curves.handle_positions_right() : - curves.handle_positions_left(); + MutableSpan<int8_t> handle_types = use_left ? curves.handle_types_left_for_write() : + curves.handle_types_right_for_write(); + MutableSpan<int8_t> handle_types_other = use_left ? curves.handle_types_right_for_write() : + curves.handle_types_left_for_write(); + MutableSpan<float3> handle_positions = use_left ? curves.handle_positions_left_for_write() : + curves.handle_positions_right_for_write(); + MutableSpan<float3> handle_positions_other = use_left ? + curves.handle_positions_right_for_write() : + curves.handle_positions_left_for_write(); threading::parallel_for(selection.index_range(), 2048, [&](IndexRange range) { for (const int i : selection.slice(range)) { |