[Bf-blender-cvs] [192a3f1a05d] master: Cleanup: Use copy constructor for CurveEval

Hans Goudey noreply at git.blender.org
Wed May 19 19:03:13 CEST 2021


Commit: 192a3f1a05d00f1f10f32861c098b66f78cff3e4
Author: Hans Goudey
Date:   Wed May 19 13:02:53 2021 -0400
Branches: master
https://developer.blender.org/rB192a3f1a05d00f1f10f32861c098b66f78cff3e4

Cleanup: Use copy constructor for CurveEval

There is no need for a special "copy" method with a copy constructor,
which will be necessary to explicitly copy attributes anyway.

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

M	source/blender/blenkernel/BKE_spline.hh
M	source/blender/blenkernel/intern/curve_eval.cc
M	source/blender/blenkernel/intern/geometry_component_curve.cc

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

diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh
index 35f21ccb897..c3386d12b02 100644
--- a/source/blender/blenkernel/BKE_spline.hh
+++ b/source/blender/blenkernel/BKE_spline.hh
@@ -482,14 +482,20 @@ class CurveEval {
   blender::Vector<SplinePtr> splines_;
 
  public:
+  CurveEval() = default;
+  CurveEval(const CurveEval &other)
+  {
+    for (const SplinePtr &spline : other.splines()) {
+      this->add_spline(spline->copy());
+    }
+  }
+
   blender::Span<SplinePtr> splines() const;
   blender::MutableSpan<SplinePtr> splines();
 
   void add_spline(SplinePtr spline);
   void remove_splines(blender::IndexMask mask);
 
-  CurveEval *copy();
-
   void translate(const blender::float3 &translation);
   void transform(const blender::float4x4 &matrix);
   void bounds_min_max(blender::float3 &min, blender::float3 &max, const bool use_evaluated) const;
diff --git a/source/blender/blenkernel/intern/curve_eval.cc b/source/blender/blenkernel/intern/curve_eval.cc
index 19bbd8178b7..1679f21516a 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -50,17 +50,6 @@ void CurveEval::remove_splines(blender::IndexMask mask)
   }
 }
 
-CurveEval *CurveEval::copy()
-{
-  CurveEval *new_curve = new CurveEval();
-
-  for (SplinePtr &spline : this->splines()) {
-    new_curve->add_spline(spline->copy());
-  }
-
-  return new_curve;
-}
-
 void CurveEval::translate(const float3 &translation)
 {
   for (SplinePtr &spline : this->splines()) {
diff --git a/source/blender/blenkernel/intern/geometry_component_curve.cc b/source/blender/blenkernel/intern/geometry_component_curve.cc
index 44c5cce92dd..d6c7cae2727 100644
--- a/source/blender/blenkernel/intern/geometry_component_curve.cc
+++ b/source/blender/blenkernel/intern/geometry_component_curve.cc
@@ -39,7 +39,7 @@ GeometryComponent *CurveComponent::copy() const
 {
   CurveComponent *new_component = new CurveComponent();
   if (curve_ != nullptr) {
-    new_component->curve_ = curve_->copy();
+    new_component->curve_ = new CurveEval(*curve_);
     new_component->ownership_ = GeometryOwnershipType::Owned;
   }
   return new_component;
@@ -87,7 +87,7 @@ CurveEval *CurveComponent::get_for_write()
 {
   BLI_assert(this->is_mutable());
   if (ownership_ == GeometryOwnershipType::ReadOnly) {
-    curve_ = curve_->copy();
+    curve_ = new CurveEval(*curve_);
     ownership_ = GeometryOwnershipType::Owned;
   }
   return curve_;
@@ -107,7 +107,7 @@ void CurveComponent::ensure_owns_direct_data()
 {
   BLI_assert(this->is_mutable());
   if (ownership_ != GeometryOwnershipType::Owned) {
-    curve_ = curve_->copy();
+    curve_ = new CurveEval(*curve_);
     ownership_ = GeometryOwnershipType::Owned;
   }
 }



More information about the Bf-blender-cvs mailing list