diff options
author | Hans Goudey <h.goudey@me.com> | 2021-06-22 19:32:50 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-06-22 19:32:50 +0300 |
commit | f3eecfe386098cf0a18df7ff4d8ffda9a43e9495 (patch) | |
tree | 52a9429269c803ae3a4f0bb8a6c235850c12f124 /source/blender/blenkernel/intern/spline_base.cc | |
parent | 026de343e3528fe2b2f8d8daba7fa2fd4b807337 (diff) |
Cleanup: Refactor spline copying functions
Make the virtual functions protected and simpler, so that the logic is
better contained in the base class's implementation. Also introduce a
`copy_without_attributes` method to be used for realizing instances.
Diffstat (limited to 'source/blender/blenkernel/intern/spline_base.cc')
-rw-r--r-- | source/blender/blenkernel/intern/spline_base.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc index c18f44e07b2..aa0d95d4d61 100644 --- a/source/blender/blenkernel/intern/spline_base.cc +++ b/source/blender/blenkernel/intern/spline_base.cc @@ -40,6 +40,60 @@ Spline::Type Spline::type() const return type_; } +void Spline::copy_base_settings(const Spline &src, Spline &dst) +{ + dst.normal_mode = src.normal_mode; + dst.is_cyclic_ = src.is_cyclic_; +} + +static SplinePtr create_spline(const Spline::Type type) +{ + switch (type) { + case Spline::Type::Poly: + return std::make_unique<PolySpline>(); + case Spline::Type::Bezier: + return std::make_unique<BezierSpline>(); + case Spline::Type::NURBS: + return std::make_unique<NURBSpline>(); + } + BLI_assert_unreachable(); + return {}; +} + +/** + * Return a new spline with the same data, settings, and attributes. + */ +SplinePtr Spline::copy() const +{ + SplinePtr dst = this->copy_without_attributes(); + dst->attributes = this->attributes; + return dst; +} + +/** + * Return a new spline with the same type and settings like "cyclic", but without any data. + */ +SplinePtr Spline::copy_only_settings() const +{ + SplinePtr dst = create_spline(type_); + this->copy_base_settings(*this, *dst); + this->copy_settings(*dst); + return dst; +} + +/** + * The same as #copy, but skips copying dynamic attributes to the new spline. + */ +SplinePtr Spline::copy_without_attributes() const +{ + SplinePtr dst = this->copy_only_settings(); + this->copy_data(*dst); + + /* Though the attributes storage is empty, it still needs to know the correct size. */ + dst->attributes.reallocate(dst->size()); + return dst; +} + void Spline::translate(const blender::float3 &translation) { for (float3 &position : this->positions()) { |