diff options
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()) { |