Skip to content
Snippets Groups Projects
Commit ecc8a155 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

assert rather than return meaningless default; simplify c'tor

parent eb64ea31
No related branches found
No related tags found
1 merge request!157rm unneeded c'tor deletions; copy edit in SlicedFormFactorList
......@@ -13,16 +13,24 @@
// ************************************************************************************************
#include "Sample/Particle/MesoCrystal.h"
#include "Base/Utils/Assert.h"
#include "Sample/Particle/Crystal.h"
#include "Sample/Particle/SlicedParticle.h"
#include "Sample/Scattering/FormFactorDecoratorPositionFactor.h"
#include "Sample/Scattering/FormFactorDecoratorRotation.h"
#include "Sample/Scattering/Rotations.h"
MesoCrystal::MesoCrystal(Crystal* particle_structure, IFormFactor* form_factor)
: m_particle_structure(particle_structure), m_meso_form_factor(form_factor)
{
setName("MesoCrystal");
registerChild(m_particle_structure.get());
registerChild(m_meso_form_factor.get());
}
MesoCrystal::MesoCrystal(const Crystal& particle_structure, const IFormFactor& form_factor)
: m_particle_structure(particle_structure.clone()), m_meso_form_factor(form_factor.clone())
: MesoCrystal(particle_structure.clone(), form_factor.clone())
{
initialize();
}
MesoCrystal::~MesoCrystal() = default;
......@@ -45,8 +53,7 @@ void MesoCrystal::accept(INodeVisitor* visitor) const
SlicedParticle MesoCrystal::createSlicedParticle(const ZLimits &limits) const
{
if (!m_particle_structure || !m_meso_form_factor)
return {};
ASSERT(m_particle_structure && m_meso_form_factor);
std::unique_ptr<IRotation> rotation(new IdentityRotation);
if (m_rotation)
rotation.reset(m_rotation->clone());
......@@ -69,16 +76,3 @@ std::vector<const INode*> MesoCrystal::getChildren() const
return std::vector<const INode*>()
<< IParticle::getChildren() << m_particle_structure << m_meso_form_factor;
}
MesoCrystal::MesoCrystal(Crystal* particle_structure, IFormFactor* form_factor)
: m_particle_structure(particle_structure), m_meso_form_factor(form_factor)
{
initialize();
}
void MesoCrystal::initialize()
{
setName("MesoCrystal");
registerChild(m_particle_structure.get());
registerChild(m_meso_form_factor.get());
}
......@@ -37,10 +37,9 @@ public:
private:
MesoCrystal(Crystal* p_particle_structure, IFormFactor* p_form_factor);
void initialize();
std::unique_ptr<Crystal> m_particle_structure; //!< Crystal structure
std::unique_ptr<IFormFactor> m_meso_form_factor; //!< Outer shape of this mesocrystal
const std::unique_ptr<Crystal> m_particle_structure; //!< Crystal structure
const std::unique_ptr<IFormFactor> m_meso_form_factor; //!< Outer shape of the mesocrystal
};
#endif // BORNAGAIN_SAMPLE_PARTICLE_MESOCRYSTAL_H
......@@ -13,6 +13,7 @@
// ************************************************************************************************
#include "Sample/Particle/Particle.h"
#include "Base/Utils/Assert.h"
#include "Base/Vector/Transform3D.h"
#include "Sample/Material/MaterialFactoryFuncs.h"
#include "Sample/Particle/SlicedParticle.h"
......@@ -57,8 +58,7 @@ Particle* Particle::clone() const
SlicedParticle Particle::createSlicedParticle(const ZLimits& limits) const
{
if (!m_form_factor)
return {};
ASSERT(m_form_factor);
std::unique_ptr<IRotation> rotation(new IdentityRotation);
if (m_rotation)
rotation.reset(m_rotation->clone());
......
......@@ -13,6 +13,7 @@
// ************************************************************************************************
#include "Sample/Particle/ParticleCoreShell.h"
#include "Base/Utils/Assert.h"
#include "Sample/Particle/FormFactorCoreShell.h"
#include "Sample/Particle/Particle.h"
#include "Sample/Particle/SlicedParticle.h"
......@@ -40,21 +41,20 @@ ParticleCoreShell* ParticleCoreShell::clone() const
SlicedParticle ParticleCoreShell::createSlicedParticle(const ZLimits &limits) const
{
if (!m_core || !m_shell)
return {};
std::unique_ptr<IRotation> P_rotation(new IdentityRotation);
ASSERT(m_core && m_shell);
std::unique_ptr<IRotation> rotation(new IdentityRotation);
if (m_rotation)
P_rotation.reset(m_rotation->clone());
rotation.reset(m_rotation->clone());
// core
std::unique_ptr<Particle> P_core(m_core->clone());
P_core->rotate(*P_rotation);
P_core->rotate(*rotation);
P_core->translate(m_position);
auto sliced_core = P_core->createSlicedParticle(limits);
// shell
std::unique_ptr<Particle> P_shell(m_shell->clone());
P_shell->rotate(*P_rotation);
P_shell->rotate(*rotation);
P_shell->translate(m_position);
auto sliced_shell = P_shell->createSlicedParticle(limits);
if (!sliced_shell.m_sliced_ff)
......
......@@ -31,18 +31,9 @@ ParticleCoreShellTest::~ParticleCoreShellTest()
TEST_F(ParticleCoreShellTest, InitialState)
{
EXPECT_EQ(nullptr, m_coreshell->createFormFactor());
EXPECT_EQ(nullptr, m_coreshell->rotation());
}
TEST_F(ParticleCoreShellTest, Clone)
{
ParticleCoreShell* p_clone = m_coreshell->clone();
EXPECT_EQ(nullptr, p_clone->createFormFactor());
EXPECT_EQ(nullptr, p_clone->rotation());
delete p_clone;
}
TEST_F(ParticleCoreShellTest, ComplexCoreShellClone)
{
Material mCore = HomogeneousMaterial("Ag", 1.245e-5, 5.419e-7);
......
......@@ -10,28 +10,12 @@
class ParticleTest : public ::testing::Test {
};
TEST_F(ParticleTest, Clone)
{
Material mat = HomogeneousMaterial("Any", 1e-4, 1e-6);
Particle particle(mat);
std::unique_ptr<Particle> clone(particle.clone());
EXPECT_EQ(mat, *clone->material());
EXPECT_EQ(nullptr, clone->createFormFactor());
EXPECT_EQ(nullptr, clone->rotation());
}
TEST_F(ParticleTest, Constructors)
{
Material mat = HomogeneousMaterial("Vacuum", 0, 0);
FormFactorFullSphere sphere(1.0);
RotationZ transform(45. * Units::deg);
// construction with material
std::unique_ptr<Particle> p1(new Particle(mat));
EXPECT_EQ(mat, *p1->material());
EXPECT_EQ(nullptr, p1->createFormFactor());
EXPECT_EQ(nullptr, p1->rotation());
// construction with form factor
std::unique_ptr<Particle> p2(new Particle(mat, sphere));
EXPECT_EQ(mat, *p2->material());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment