From 9fddb564b1e05dab9e845a58da7d09cee9d3ee88 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 19 Dec 2023 12:40:16 +0100 Subject: [PATCH] OpaqueCoordinate rule of 3 --- src/ifcgeom/ConversionResult.h | 26 ++++++++++++++- .../kernels/cgal/CgalConversionResult.cpp | 32 +++++++++---------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/ifcgeom/ConversionResult.h b/src/ifcgeom/ConversionResult.h index aa945bee82..487a23699f 100644 --- a/src/ifcgeom/ConversionResult.h +++ b/src/ifcgeom/ConversionResult.h @@ -152,8 +152,15 @@ namespace IfcGeom { template struct IFC_GEOM_API OpaqueCoordinate { + private: std::array values; + static void copy_(std::array& dest, const std::array& src) { + for (size_t i = 0; i < N; ++i) { + dest[i] = (src[i] != nullptr) ? src[i]->clone() : nullptr; + } + } + public: template OpaqueCoordinate(Args... args) { static_assert(sizeof...(args) == N, "Incorrect number of arguments provided"); @@ -166,7 +173,24 @@ namespace IfcGeom { } } - OpaqueNumber* get(size_t i) { + OpaqueCoordinate(const OpaqueCoordinate& other) { + copy_(values, other.values); + } + + OpaqueCoordinate& operator=(const OpaqueCoordinate& other) { + if (this != &other) { + copy_(values, other.values); + } + return *this; + } + + ~OpaqueCoordinate() { + for (auto it = values.begin(); it != values.end(); ++it) { + delete *it; + } + } + + OpaqueNumber* get(size_t i) const { if (i >= N) { return nullptr; } diff --git a/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp b/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp index 4947dea3d8..bcb4eac0ff 100644 --- a/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp +++ b/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp @@ -708,16 +708,16 @@ void ifcopenshell::geometry::CgalShapeHalfSpaceDecomposition::map(OpaqueCoordina plane_map mp; mp.insert({ CGAL::Plane_3( - static_cast(from.values[0])->value(), - static_cast(from.values[1])->value(), - static_cast(from.values[2])->value(), - static_cast(from.values[3])->value() + static_cast(from.get(0))->value(), + static_cast(from.get(1))->value(), + static_cast(from.get(2))->value(), + static_cast(from.get(3))->value() ), CGAL::Plane_3( - static_cast(to.values[0])->value(), - static_cast(to.values[1])->value(), - static_cast(to.values[2])->value(), - static_cast(to.values[3])->value() + static_cast(to.get(0))->value(), + static_cast(to.get(1))->value(), + static_cast(to.get(2))->value(), + static_cast(to.get(3))->value() ) }); auto nw = shape_->map(mp); @@ -736,16 +736,16 @@ void ifcopenshell::geometry::CgalShapeHalfSpaceDecomposition::map(const std::vec auto& to = *jt; mp.insert({ CGAL::Plane_3( - static_cast(from.values[0])->value(), - static_cast(from.values[1])->value(), - static_cast(from.values[2])->value(), - static_cast(from.values[3])->value() + static_cast(from.get(0))->value(), + static_cast(from.get(1))->value(), + static_cast(from.get(2))->value(), + static_cast(from.get(3))->value() ), CGAL::Plane_3( - static_cast(to.values[0])->value(), - static_cast(to.values[1])->value(), - static_cast(to.values[2])->value(), - static_cast(to.values[3])->value() + static_cast(to.get(0))->value(), + static_cast(to.get(1))->value(), + static_cast(to.get(2))->value(), + static_cast(to.get(3))->value() ) }); }