OpaqueCoordinate rule of 3

This commit is contained in:
Thomas Krijnen
2023-12-19 12:40:16 +01:00
parent 89fd887d9a
commit 9fddb564b1
2 changed files with 41 additions and 17 deletions
+25 -1
View File
@@ -152,8 +152,15 @@ namespace IfcGeom {
template <size_t N>
struct IFC_GEOM_API OpaqueCoordinate {
private:
std::array<OpaqueNumber*, N> values;
static void copy_(std::array<OpaqueNumber*, N>& dest, const std::array<OpaqueNumber*, N>& src) {
for (size_t i = 0; i < N; ++i) {
dest[i] = (src[i] != nullptr) ? src[i]->clone() : nullptr;
}
}
public:
template <typename... Args>
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;
}
@@ -708,16 +708,16 @@ void ifcopenshell::geometry::CgalShapeHalfSpaceDecomposition::map(OpaqueCoordina
plane_map<Kernel_> mp;
mp.insert({
CGAL::Plane_3<Kernel_>(
static_cast<NumberEpeck*>(from.values[0])->value(),
static_cast<NumberEpeck*>(from.values[1])->value(),
static_cast<NumberEpeck*>(from.values[2])->value(),
static_cast<NumberEpeck*>(from.values[3])->value()
static_cast<NumberEpeck*>(from.get(0))->value(),
static_cast<NumberEpeck*>(from.get(1))->value(),
static_cast<NumberEpeck*>(from.get(2))->value(),
static_cast<NumberEpeck*>(from.get(3))->value()
),
CGAL::Plane_3<Kernel_>(
static_cast<NumberEpeck*>(to.values[0])->value(),
static_cast<NumberEpeck*>(to.values[1])->value(),
static_cast<NumberEpeck*>(to.values[2])->value(),
static_cast<NumberEpeck*>(to.values[3])->value()
static_cast<NumberEpeck*>(to.get(0))->value(),
static_cast<NumberEpeck*>(to.get(1))->value(),
static_cast<NumberEpeck*>(to.get(2))->value(),
static_cast<NumberEpeck*>(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<Kernel_>(
static_cast<NumberEpeck*>(from.values[0])->value(),
static_cast<NumberEpeck*>(from.values[1])->value(),
static_cast<NumberEpeck*>(from.values[2])->value(),
static_cast<NumberEpeck*>(from.values[3])->value()
static_cast<NumberEpeck*>(from.get(0))->value(),
static_cast<NumberEpeck*>(from.get(1))->value(),
static_cast<NumberEpeck*>(from.get(2))->value(),
static_cast<NumberEpeck*>(from.get(3))->value()
),
CGAL::Plane_3<Kernel_>(
static_cast<NumberEpeck*>(to.values[0])->value(),
static_cast<NumberEpeck*>(to.values[1])->value(),
static_cast<NumberEpeck*>(to.values[2])->value(),
static_cast<NumberEpeck*>(to.values[3])->value()
static_cast<NumberEpeck*>(to.get(0))->value(),
static_cast<NumberEpeck*>(to.get(1))->value(),
static_cast<NumberEpeck*>(to.get(2))->value(),
static_cast<NumberEpeck*>(to.get(3))->value()
)
});
}