refactor using pimpl and fix test
This commit is contained in:
@@ -85,10 +85,11 @@ public:
|
||||
* @param copy The ContainerBox instance to copy from.
|
||||
*/
|
||||
ContainerBox(const ContainerBox ©)
|
||||
: m_LocalT(this), // BaseClass is Parent of m_LocalTransform
|
||||
: m_LocalT(copy.m_LocalT), // Copy local transform state
|
||||
AffineTransform(copy),
|
||||
p_Size(this, "Size", copy.p_Size),
|
||||
p_Origin(this, "Origin", copy.p_Origin) {
|
||||
m_LocalT.SetParent(this); // Reset parent to the new object
|
||||
Object::connect(&p_Size, &Property<Vector3f>::PropertyChanged, this, &ContainerBox::SyncSize);
|
||||
Object::connect(&p_Origin, &Property<Vector3f>::PropertyChanged, this, &ContainerBox::SyncOrigin);
|
||||
}
|
||||
|
||||
@@ -109,8 +109,20 @@ public:
|
||||
|
||||
VoxImage(const Vector3i &size);
|
||||
|
||||
VoxImage(const VoxImage<T> ©) : BaseClass(copy) {
|
||||
this->m_Data = copy.m_Data;
|
||||
// Use compiler-generated copy constructor and assignment operator
|
||||
|
||||
VoxImage<T>& operator=(const VoxImage<T>& other) {
|
||||
if (this != &other) {
|
||||
// Copy the base class non-virtual parts (dims, spacing, position, etc.)
|
||||
// WITHOUT going through the virtual SetDims chain (which would call
|
||||
// m_Data.resize() THEN DataAllocator::operator= will resize again → double-free).
|
||||
// Instead, directly copy DataAllocator and update the StructuredGrid state.
|
||||
this->m_Data = other.m_Data;
|
||||
StructuredGrid::SetDims(other.GetDims());
|
||||
this->SetSpacing(other.GetSpacing());
|
||||
this->SetPosition(other.GetPosition());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline DataAllocator<T> &Data() { return this->m_Data; }
|
||||
|
||||
@@ -52,7 +52,7 @@ int main()
|
||||
|
||||
// Test 1: Basic identity transformation and cylinder parameters
|
||||
{
|
||||
Cylinder cyl(2.0, 10.0);
|
||||
Cylinder cyl(2.0, 10.0, 2);
|
||||
std::cout << "Cyl R=" << cyl.GetRadius() << " H=" << cyl.GetHeight() << std::endl;
|
||||
std::cout << "Cyl World Matrix:\n" << cyl.GetWorldMatrix() << std::endl;
|
||||
|
||||
@@ -82,7 +82,7 @@ int main()
|
||||
|
||||
// Test 2: Translation
|
||||
{
|
||||
Cylinder cyl(1.0, 2.0);
|
||||
Cylinder cyl(1.0, 2.0, 2);
|
||||
cyl.SetPosition(Vector3f(10, 20, 30));
|
||||
|
||||
// Local base origin (0, 0, 0) -> World (10, 20, 30)
|
||||
@@ -96,7 +96,7 @@ int main()
|
||||
|
||||
// Test 3: Rotation and complex mapping
|
||||
{
|
||||
Cylinder cyl(5.0, 20.0);
|
||||
Cylinder cyl(5.0, 20.0, 2);
|
||||
cyl.SetPosition(Vector3f(1.0, 2.0, 3.0));
|
||||
// Rotate 90 degrees around X: Local Y becomes World Z, Local Z becomes World -Y
|
||||
cyl.Rotate(M_PI/2.0, Vector3f(1, 0, 0));
|
||||
|
||||
Reference in New Issue
Block a user