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/blenkernel/intern/curves_geometry_test.cc | |
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/blenkernel/intern/curves_geometry_test.cc')
-rw-r--r-- | source/blender/blenkernel/intern/curves_geometry_test.cc | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/source/blender/blenkernel/intern/curves_geometry_test.cc b/source/blender/blenkernel/intern/curves_geometry_test.cc index baa47bb7cf6..56e488b9034 100644 --- a/source/blender/blenkernel/intern/curves_geometry_test.cc +++ b/source/blender/blenkernel/intern/curves_geometry_test.cc @@ -16,12 +16,12 @@ static CurvesGeometry create_basic_curves(const int points_size, const int curve const int curve_length = points_size / curves_size; for (const int i : curves.curves_range()) { - curves.offsets()[i] = points_size * curve_length; + curves.offsets_for_write()[i] = points_size * curve_length; } - curves.offsets().last() = points_size; + curves.offsets_for_write().last() = points_size; for (const int i : curves.points_range()) { - curves.positions()[i] = {float(i), float(i % curve_length), 0.0f}; + curves.positions_for_write()[i] = {float(i), float(i % curve_length), 0.0f}; } return curves; @@ -66,7 +66,7 @@ TEST(curves_geometry, Move) TEST(curves_geometry, TypeCount) { CurvesGeometry curves = create_basic_curves(100, 10); - curves.curve_types().copy_from({ + curves.curve_types_for_write().copy_from({ CURVE_TYPE_BEZIER, CURVE_TYPE_NURBS, CURVE_TYPE_NURBS, @@ -88,12 +88,12 @@ TEST(curves_geometry, TypeCount) TEST(curves_geometry, CatmullRomEvaluation) { CurvesGeometry curves(4, 1); - curves.curve_types().fill(CURVE_TYPE_CATMULL_ROM); - curves.resolution().fill(12); - curves.offsets().last() = 4; - curves.cyclic().fill(false); + curves.curve_types_for_write().fill(CURVE_TYPE_CATMULL_ROM); + curves.resolution_for_write().fill(12); + curves.offsets_for_write().last() = 4; + curves.cyclic_for_write().fill(false); - MutableSpan<float3> positions = curves.positions(); + MutableSpan<float3> positions = curves.positions_for_write(); positions[0] = {1, 1, 0}; positions[1] = {0, 1, 0}; positions[2] = {0, 0, 0}; @@ -156,7 +156,7 @@ TEST(curves_geometry, CatmullRomEvaluation) positions[1] = {1, 1, 0}; positions[2] = {0, 1, 0}; positions[3] = {0, 0, 0}; - curves.cyclic().fill(true); + curves.cyclic_for_write().fill(true); /* Tag topology changed because the new cyclic value is different. */ curves.tag_topology_changed(); @@ -221,10 +221,10 @@ TEST(curves_geometry, CatmullRomEvaluation) TEST(curves_geometry, CatmullRomTwoPointCyclic) { CurvesGeometry curves(2, 1); - curves.curve_types().fill(CURVE_TYPE_CATMULL_ROM); - curves.resolution().fill(12); - curves.offsets().last() = 2; - curves.cyclic().fill(true); + curves.curve_types_for_write().fill(CURVE_TYPE_CATMULL_ROM); + curves.resolution_for_write().fill(12); + curves.offsets_for_write().last() = 2; + curves.cyclic_for_write().fill(true); /* The curve should still be cyclic when there are only two control points. */ EXPECT_EQ(curves.evaluated_points_num(), 24); @@ -233,13 +233,13 @@ TEST(curves_geometry, CatmullRomTwoPointCyclic) TEST(curves_geometry, BezierPositionEvaluation) { CurvesGeometry curves(2, 1); - curves.curve_types().fill(CURVE_TYPE_BEZIER); - curves.resolution().fill(12); - curves.offsets().last() = 2; + curves.curve_types_for_write().fill(CURVE_TYPE_BEZIER); + curves.resolution_for_write().fill(12); + curves.offsets_for_write().last() = 2; - MutableSpan<float3> handles_left = curves.handle_positions_left(); - MutableSpan<float3> handles_right = curves.handle_positions_right(); - MutableSpan<float3> positions = curves.positions(); + MutableSpan<float3> handles_left = curves.handle_positions_left_for_write(); + MutableSpan<float3> handles_right = curves.handle_positions_right_for_write(); + MutableSpan<float3> positions = curves.positions_for_write(); positions.first() = {-1, 0, 0}; positions.last() = {1, 0, 0}; handles_right.first() = {-0.5f, 0.5f, 0.0f}; @@ -270,12 +270,12 @@ TEST(curves_geometry, BezierPositionEvaluation) } curves.resize(4, 2); - curves.curve_types().fill(CURVE_TYPE_BEZIER); - curves.resolution().fill(9); - curves.offsets().last() = 4; - handles_left = curves.handle_positions_left(); - handles_right = curves.handle_positions_right(); - positions = curves.positions(); + curves.curve_types_for_write().fill(CURVE_TYPE_BEZIER); + curves.resolution_for_write().fill(9); + curves.offsets_for_write().last() = 4; + handles_left = curves.handle_positions_left_for_write(); + handles_right = curves.handle_positions_right_for_write(); + positions = curves.positions_for_write(); positions[2] = {-1, 1, 0}; positions[3] = {1, 1, 0}; handles_right[2] = {-0.5f, 1.5f, 0.0f}; @@ -317,11 +317,11 @@ TEST(curves_geometry, BezierPositionEvaluation) TEST(curves_geometry, NURBSEvaluation) { CurvesGeometry curves(4, 1); - curves.curve_types().fill(CURVE_TYPE_NURBS); - curves.resolution().fill(10); - curves.offsets().last() = 4; + curves.curve_types_for_write().fill(CURVE_TYPE_NURBS); + curves.resolution_for_write().fill(10); + curves.offsets_for_write().last() = 4; - MutableSpan<float3> positions = curves.positions(); + MutableSpan<float3> positions = curves.positions_for_write(); positions[0] = {1, 1, 0}; positions[1] = {0, 1, 0}; positions[2] = {0, 0, 0}; @@ -345,7 +345,7 @@ TEST(curves_geometry, NURBSEvaluation) } /* Test a cyclic curve. */ - curves.cyclic().fill(true); + curves.cyclic_for_write().fill(true); curves.tag_topology_changed(); evaluated_positions = curves.evaluated_positions(); static const Array<float3> result_2{{ @@ -379,8 +379,8 @@ TEST(curves_geometry, NURBSEvaluation) positions[1] = {1, 1, 0}; positions[2] = {0, 1, 0}; positions[3] = {0, 0, 0}; - curves.nurbs_weights().fill(1.0f); - curves.nurbs_weights()[0] = 4.0f; + curves.nurbs_weights_for_write().fill(1.0f); + curves.nurbs_weights_for_write()[0] = 4.0f; curves.tag_positions_changed(); static const Array<float3> result_3{{ {0.888889, 0.555556, 0}, {0.837792, 0.643703, 0}, {0.773885, 0.727176, 0}, @@ -407,13 +407,13 @@ TEST(curves_geometry, NURBSEvaluation) TEST(curves_geometry, BezierGenericEvaluation) { CurvesGeometry curves(3, 1); - curves.curve_types().fill(CURVE_TYPE_BEZIER); - curves.resolution().fill(8); - curves.offsets().last() = 3; + curves.curve_types_for_write().fill(CURVE_TYPE_BEZIER); + curves.resolution_for_write().fill(8); + curves.offsets_for_write().last() = 3; - MutableSpan<float3> handles_left = curves.handle_positions_left(); - MutableSpan<float3> handles_right = curves.handle_positions_right(); - MutableSpan<float3> positions = curves.positions(); + MutableSpan<float3> handles_left = curves.handle_positions_left_for_write(); + MutableSpan<float3> handles_right = curves.handle_positions_right_for_write(); + MutableSpan<float3> positions = curves.positions_for_write(); positions.first() = {-1, 0, 0}; handles_right.first() = {-1, 1, 0}; handles_left[1] = {0, 0, 0}; |