[Bf-blender-cvs] [8551e890687] master: Curves: Name mutable data retrieval functions explicitly

Hans Goudey noreply at git.blender.org
Wed Apr 6 23:38:23 CEST 2022


Commit: 8551e890687de7185388eed9e77171b0df7943a3
Author: Hans Goudey
Date:   Wed Apr 6 16:30:27 2022 -0500
Branches: master
https://developer.blender.org/rB8551e890687de7185388eed9e77171b0df7943a3

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

===================================================================

M	source/blender/blenkernel/BKE_curves.hh
M	source/blender/blenkernel/intern/curve_eval.cc
M	source/blender/blenkernel/intern/curves.cc
M	source/blender/blenkernel/intern/curves_geometry.cc
M	source/blender/blenkernel/intern/curves_geometry_test.cc
M	source/blender/editors/curves/intern/curves_add.cc
M	source/blender/editors/curves/intern/curves_ops.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_add.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_comb.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_delete.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_grow_shrink.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc
M	source/blender/geometry/intern/mesh_to_curve_convert.cc
M	source/blender/geometry/intern/realize_instances.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_set_handle_type.cc
M	source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
M	source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh
index 4117f8b9bdc..8d24b6136b2 100644
--- a/source/blender/blenkernel/BKE_curves.hh
+++ b/source/blender/blenkernel/BKE_curves.hh
@@ -141,7 +141,7 @@ class CurvesGeometry : public ::CurvesGeometry {
    * number of curves. Consider using #points_for_curve rather than using the offsets directly.
    */
   Span<int> offsets() const;
-  MutableSpan<int> offsets();
+  MutableSpan<int> offsets_for_write();
 
   /**
    * Access a range of indices of point data for a specific curve.
@@ -152,19 +152,19 @@ class CurvesGeometry : public ::CurvesGeometry {
   /** The type (#CurveType) of each curve, or potentially a single if all are the same type. */
   VArray<int8_t> curve_types() const;
   /** Mutable access to curve types. Call #tag_topology_changed after changing any type. */
-  MutableSpan<int8_t> curve_types();
+  MutableSpan<int8_t> curve_types_for_write();
 
   bool has_curve_with_type(const CurveType type) const;
   /** Return the number of curves with each type. */
   std::array<int, CURVE_TYPES_NUM> count_curve_types() const;
 
-  MutableSpan<float3> positions();
   Span<float3> positions() const;
+  MutableSpan<float3> positions_for_write();
 
   /** Whether the curve loops around to connect to itself, on the curve domain. */
   VArray<bool> cyclic() const;
   /** Mutable access to curve cyclic values. Call #tag_topology_changed after changes. */
-  MutableSpan<bool> cyclic();
+  MutableSpan<bool> cyclic_for_write();
 
   /**
    * How many evaluated points to create for each segment when evaluating Bezier,
@@ -172,15 +172,15 @@ class CurvesGeometry : public ::CurvesGeometry {
    */
   VArray<int> resolution() const;
   /** Mutable access to curve resolution. Call #tag_topology_changed after changes. */
-  MutableSpan<int> resolution();
+  MutableSpan<int> resolution_for_write();
 
   /**
    * Handle types for Bezier control points. Call #tag_topology_changed after changes.
    */
   VArray<int8_t> handle_types_left() const;
-  MutableSpan<int8_t> handle_types_left();
+  MutableSpan<int8_t> handle_types_left_for_write();
   VArray<int8_t> handle_types_right() const;
-  MutableSpan<int8_t> handle_types_right();
+  MutableSpan<int8_t> handle_types_right_for_write();
 
   /**
    * The positions of Bezier curve handles. Though these are really control points for the Bezier
@@ -189,36 +189,36 @@ class CurvesGeometry : public ::CurvesGeometry {
    * after changes.
    */
   Span<float3> handle_positions_left() const;
-  MutableSpan<float3> handle_positions_left();
+  MutableSpan<float3> handle_positions_left_for_write();
   Span<float3> handle_positions_right() const;
-  MutableSpan<float3> handle_positions_right();
+  MutableSpan<float3> handle_positions_right_for_write();
 
   /**
    * The order (degree plus one) of each NURBS curve, on the curve domain.
    * Call #tag_topology_changed after changes.
    */
   VArray<int8_t> nurbs_orders() const;
-  MutableSpan<int8_t> nurbs_orders();
+  MutableSpan<int8_t> nurbs_orders_for_write();
 
   /**
    * The automatic generation mode for each NURBS curve's knots vector, on the curve domain.
    * Call #tag_topology_changed after changes.
    */
   VArray<int8_t> nurbs_knots_modes() const;
-  MutableSpan<int8_t> nurbs_knots_modes();
+  MutableSpan<int8_t> nurbs_knots_modes_for_write();
 
   /**
    * The weight for each control point for NURBS curves. Call #tag_positions_changed after changes.
    */
   Span<float> nurbs_weights() const;
-  MutableSpan<float> nurbs_weights();
+  MutableSpan<float> nurbs_weights_for_write();
 
   /**
    * The index of a triangle (#MLoopTri) that a curve is attached to.
    * The index is -1, if the curve is not attached.
    */
   VArray<int> surface_triangle_indices() const;
-  MutableSpan<int> surface_triangle_indices();
+  MutableSpan<int> surface_triangle_indices_for_write();
 
   /**
    * Barycentric coordinates of the attachment point within a triangle.
@@ -229,7 +229,7 @@ class CurvesGeometry : public ::CurvesGeometry {
    * The span can be empty, when all triangle indices are -1.
    */
   Span<float2> surface_triangle_coords() const;
-  MutableSpan<float2> surface_triangle_coords();
+  MutableSpan<float2> surface_triangle_coords_for_write();
 
   /**
    * Calculate the largest and smallest position values, only including control points
diff --git a/source/blender/blenkernel/intern/curve_eval.cc b/source/blender/blenkernel/intern/curve_eval.cc
index 2cf83b57881..7761b7acc49 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -462,8 +462,8 @@ Curves *curve_eval_to_curves(const CurveEval &curve_eval)
   dst_component.replace(curves, GeometryOwnershipType::Editable);
 
   blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(curves->geometry);
-  geometry.offsets().copy_from(curve_eval.control_point_offsets());
-  MutableSpan<int8_t> curve_types = geometry.curve_types();
+  geometry.offsets_for_write().copy_from(curve_eval.control_point_offsets());
+  MutableSpan<int8_t> curve_types = geometry.curve_types_for_write();
 
   OutputAttribute_Typed<float> nurbs_weight;
   OutputAttribute_Typed<int> nurbs_order;
diff --git a/source/blender/blenkernel/intern/curves.cc b/source/blender/blenkernel/intern/curves.cc
index 82db1176759..ebbdff55a55 100644
--- a/source/blender/blenkernel/intern/curves.cc
+++ b/source/blender/blenkernel/intern/curves.cc
@@ -318,7 +318,7 @@ static Curves *curves_evaluate_modifiers(struct Depsgraph *depsgraph,
       /* Created deformed coordinates array on demand. */
       blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(
           curves->geometry);
-      MutableSpan<float3> positions = geometry.positions();
+      MutableSpan<float3> positions = geometry.positions_for_write();
 
       mti->deformVerts(md,
                        &mectx,
@@ -378,8 +378,8 @@ Curves *curves_new_nomain_single(const int points_num, const CurveType type)
 {
   Curves *curves = curves_new_nomain(points_num, 1);
   CurvesGeometry &geometry = CurvesGeometry::wrap(curves->geometry);
-  geometry.offsets().last() = points_num;
-  geometry.curve_types().first() = type;
+  geometry.offsets_for_write().last() = points_num;
+  geometry.curve_types_for_write().first() = type;
   return curves;
 }
 
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc
index 552d7622932..9296aeafd52 100644
--- a/source/blender/blenkernel/intern/curves_geometry.cc
+++ b/source/blender/blenkernel/intern/curves_geometry.cc
@@ -78,7 +78,7 @@ static void copy_curves_geometry(CurvesGeometry &dst, const CurvesGeometry &src)
 
   MEM_SAFE_FREE(dst.curve_offsets);
   dst.curve_offsets = (int *)MEM_calloc_arrayN(dst.point_size + 1, sizeof(int), __func__);
-  dst.offsets().copy_from(src.offsets());
+  dst.offsets_for_write().copy_from(src.offsets());
 
   dst.tag_topology_changed();
 
@@ -224,7 +224,7 @@ VArray<int8_t> CurvesGeometry::curve_types() const
       *this, ATTR_DOMAIN_CURVE, ATTR_CURVE_TYPE, CURVE_TYPE_CATMULL_ROM);
 }
 
-MutableSpan<int8_t> CurvesGeometry::curve_types()
+MutableSpan<int8_t> CurvesGeometry::curve_types_for_write()
 {
   return get_mutable_attribute<int8_t>(*this, ATTR_DOMAIN_CURVE, ATTR_CURVE_TYPE);
 }
@@ -277,22 +277,22 @@ std::array<int, CURVE_TYPES_NUM> CurvesGeometry::count_curve_types() const
       });
 }
 
-MutableSpan<float3> CurvesGeometry::positions()
+Span<float3> CurvesGeometry::positions() const
+{
+  return {(const float3 *)this->position, this->point_size};
+}
+MutableSpan<float3> CurvesGeometry::positions_for_write()
 {
   this->position = (float(*)[3])CustomData_duplicate_referenced_layer_named(
       &this->point_data, CD_PROP_FLOAT3, ATTR_POSITION.c_str(), this->point_size);
   return {(float3 *)this->position, this->point_size};
 }
-Span<float3> CurvesGeometry::positions() const
-{
-  return {(const float3 *)this->position, this->point_size};
-}
 
-MutableSpan<int> CurvesGeometry::offsets()
+Span<int> CurvesGeometry::offsets() const
 {
   return {this->curve_offsets, this->curve_size + 1};
 }
-Span<int> CurvesGeometry::offsets() const
+MutableSpan<int> CurvesGeometry::offsets_for_write()
 {
   return {this->curve_offsets, this->curve_size + 1};
 }
@@ -301,8 +301,7 @@ VArray<bool> CurvesGeometry::cyclic() const
 {
   return get_varray_attribute<bool>(*this, ATTR_DOMAIN_CURVE, ATTR_CYCLIC, false);
 }
-
-MutableSpan<bool> CurvesGeometry::cyclic()
+MutableSpan<bool> CurvesGeometry::cyclic_for_write()
 {
   return get_mutable_attribute<bool>(*this, ATTR_DOMAIN_CURVE, ATTR_CYCLIC);
 }
@@ -311,8 +310,7 @@ VArray<int> CurvesGeometry::resolution() const
 {
   return get_varray_attribute<int>(*this, ATTR_DOMAIN_CURVE, ATTR_RESOLUTION, 12);
 }
-
-MutableSpan<int> CurvesGeometry::resolution()
+MutableSpan<int> CurvesGeometry::resolution_for_write()
 {
   return get_mutable_attribute<int>(*this, ATTR_DOMAIN_CURVE, ATTR_RESOLUTION);
 }
@@ -321,7 +319,7 @@ VArray<int8_t> CurvesGeometry::handle_types_left() const
 {
   return get_varray_attribute<int8_t>(*this, ATTR_DOMAIN_POINT, ATTR_HANDLE_TYPE_LEFT, 0);
 }
-MutableSpan<int8_t> CurvesGeometry::handle_types_left()
+MutableSpan<int8_t> CurvesGeometry::handle_types_left_for_write()
 {
   return get_mutable_attribute<int8_t>(*this, ATTR_DOMAIN_POINT, ATTR_HANDLE_TYPE_LEFT);
 }
@@ -330,7 +328,7 @@ VArray<int8_t> CurvesGeometry::handle_types_right() const
 {
   return get_varray_attribute<int8_t>(*this, ATTR_DOMAIN_POINT, ATTR_HANDLE_TYPE_RIGHT, 0);
 }
-MutableSpan<int8_t> CurvesGeometry::handle_types_right()
+MutableSpan<int8_t> CurvesGeometry::handle_types_right_for_write()
 {
   return get_mutable_attribute<int8_t>(*this, ATTR_DOMAIN_POINT, ATTR_HANDLE_TYPE_RIGHT);
 }
@@ -339,7 +337,7 @@ Span<float3> CurvesGeometry::handle_positions_left() const
 {
   return get_span_attribute<float3>(*this, ATTR_DOMAIN_POINT, ATTR_HANDLE_POSITION_LEFT);
 }
-MutableSpan<float3> CurvesGeometry::handle_positions_left()
+MutableSpan<float3> CurvesGeometry::handle_positions_left_for_write()
 {
   return get_mutable_attribute<float3>(*this, ATTR_DOMAIN_POINT, ATTR_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list