//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sample/HardParticle/Polyhedra.h
//! @brief     Defines class Box.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_SAMPLE_HARDPARTICLE_POLYHEDRA_H
#define BORNAGAIN_SAMPLE_HARDPARTICLE_POLYHEDRA_H

#include "Sample/HardParticle/FormfactorPolyhedron.h"
#include "Sample/HardParticle/FormfactorPrism.h"

//  ************************************************************************************************
//  Prisms
//  ************************************************************************************************

//! A rectangular prism (parallelepiped).

class Box : public FormfactorPrism {
public:
    Box(double length, double width, double height);

#ifndef SWIG
    Box* clone() const override { return new Box(m_length, m_width, m_height); }
#endif // SWIG

    std::string className() const final { return "Box"; }

    double length() const { return m_length; }
    double width() const { return m_width; }
    double height() const override { return m_height; }

    bool contains(const R3& position) const override;

private:
    double m_length;
    double m_width;
    double m_height;
};

//! A prism based on an equilateral triangle.

class Prism3 : public FormfactorPrism {
public:
    Prism3(double base_edge, double height);

#ifndef SWIG
    Prism3* clone() const override { return new Prism3(m_base_edge, m_height); }
#endif // SWIG

    std::string className() const final { return "Prism3"; }

    double baseEdge() const { return m_base_edge; }
    double height() const override { return m_height; }

    bool contains(const R3& position) const override;

private:
    double m_base_edge;
    double m_height;
};

//! A prism based on a regular hexagonal.

class Prism6 : public FormfactorPrism {
public:
    Prism6(double base_edge, double height);

#ifndef SWIG
    Prism6* clone() const override { return new Prism6(m_base_edge, m_height); }
#endif // SWIG

    std::string className() const final { return "Prism6"; }

    double baseEdge() const { return m_base_edge; }
    double height() const override { return m_height; }

    bool contains(const R3& position) const override;

private:
    double m_base_edge;
    double m_height;
};

//  ************************************************************************************************
//  Platonic solids
//  ************************************************************************************************

//! A frustum with equilateral trigonal base.

class PlatonicTetrahedron : public FormfactorPolyhedron {
public:
    PlatonicTetrahedron(double edge);

#ifndef SWIG
    PlatonicTetrahedron* clone() const override { return new PlatonicTetrahedron(m_edge); }
#endif // SWIG

    std::string className() const final { return "PlatonicTetrahedron"; }

    double edge() const { return m_edge; }
    double height() const { return sqrt(2. / 3) * m_edge; }

    bool contains(const R3& position) const override;

private:
    double m_edge;
};

//! A truncated bifrustum with quadratic base.

class PlatonicOctahedron : public FormfactorPolyhedron {
public:
    PlatonicOctahedron(double edge);

#ifndef SWIG
    PlatonicOctahedron* clone() const override { return new PlatonicOctahedron(m_edge); }
#endif // SWIG

    std::string className() const final { return "PlatonicOctahedron"; }

    double edge() const { return m_edge; }
    double height() const { return sqrt(1 / 2.) * m_edge; }

    bool contains(const R3& position) const override;

private:
    double m_edge;
};

//! A regular dodecahedron.

class Dodecahedron : public FormfactorPolyhedron {
public:
    Dodecahedron(double edge);

#ifndef SWIG
    Dodecahedron* clone() const override { return new Dodecahedron(m_edge); }
#endif // SWIG

    std::string className() const final { return "Dodecahedron"; }

    double edge() const { return m_edge; }

    bool contains(const R3& position) const override;

private:
    double m_edge;
};

//! A regular icosahedron.

class Icosahedron : public FormfactorPolyhedron {
public:
    Icosahedron(double edge);

#ifndef SWIG
    Icosahedron* clone() const override { return new Icosahedron(m_edge); }
#endif // SWIG

    std::string className() const final { return "Icosahedron"; }

    double edge() const { return m_edge; }

    bool contains(const R3& position) const override;

private:
    double m_edge;
};

//  ************************************************************************************************
//  Pyramids
//  ************************************************************************************************

//! A frustum (truncated pyramid) with rectangular base.

class Pyramid2 : public FormfactorPolyhedron {
public:
    Pyramid2(double length, double width, double height, double alpha);

#ifndef SWIG
    Pyramid2* clone() const override { return new Pyramid2(m_length, m_width, m_height, m_alpha); }
#endif // SWIG

    std::string className() const final { return "Pyramid2"; }

    double length() const { return m_length; }
    double width() const { return m_width; }
    double height() const { return m_height; }
    double alpha() const { return m_alpha; }

    bool contains(const R3& position) const override;

private:
    double m_length;
    double m_width;
    double m_height;
    double m_alpha;
};

//! A frustum with equilateral trigonal base.

class Pyramid3 : public FormfactorPolyhedron {
public:
    Pyramid3(double base_edge, double height, double alpha);

#ifndef SWIG
    Pyramid3* clone() const override { return new Pyramid3(m_base_edge, m_height, m_alpha); }
#endif // SWIG

    std::string className() const final { return "Pyramid3"; }

    double baseEdge() const { return m_base_edge; }
    double height() const { return m_height; }
    double alpha() const { return m_alpha; }

    bool contains(const R3& position) const override;

private:
    double m_base_edge;
    double m_height;
    double m_alpha;
};

//! A frustum with a quadratic base.

class Pyramid4 : public FormfactorPolyhedron {
public:
    Pyramid4(double base_edge, double height, double alpha);

#ifndef SWIG
    Pyramid4* clone() const override { return new Pyramid4(m_base_edge, m_height, m_alpha); }
#endif // SWIG

    std::string className() const final { return "Pyramid4"; }

    double height() const { return m_height; }
    double baseEdge() const { return m_base_edge; }
    double alpha() const { return m_alpha; }

    bool contains(const R3& position) const override;

private:
    double m_base_edge;
    double m_height;
    double m_alpha;
};

//! A frustum (truncated pyramid) with regular hexagonal base.

class Pyramid6 : public FormfactorPolyhedron {
public:
    Pyramid6(double base_edge, double height, double alpha);

#ifndef SWIG
    Pyramid6* clone() const override { return new Pyramid6(m_base_edge, m_height, m_alpha); }
#endif // SWIG

    std::string className() const final { return "Pyramid6"; }

    double baseEdge() const { return m_base_edge; }
    double height() const { return m_height; }
    double alpha() const { return m_alpha; }

    bool contains(const R3& position) const override;

private:
    double m_base_edge;
    double m_height;
    double m_alpha;
};

//! A truncated bifrustum with quadratic base.

class Bipyramid4 : public FormfactorPolyhedron {
public:
    Bipyramid4(double length, double base_height, double height_ratio, double alpha);

#ifndef SWIG
    Bipyramid4* clone() const override
    {
        return new Bipyramid4(m_length, m_base_height, m_height_ratio, m_alpha);
    }
#endif // SWIG

    std::string className() const final { return "Bipyramid4"; }
    double length() const { return m_length; }
    double base_height() const { return m_base_height; }
    double heightRatio() const { return m_height_ratio; }
    double alpha() const { return m_alpha; }
    double height() const { return (1 + m_height_ratio) * m_base_height; }

    bool contains(const R3& position) const override;

private:
    double m_length;
    double m_base_height;
    double m_height_ratio;
    double m_alpha;
};

//  ************************************************************************************************
//  Others
//  ************************************************************************************************

//! A cube, with truncation of all edges and corners, as in Croset (2017) Fig 7

class CantellatedCube : public FormfactorPolyhedron {
public:
    CantellatedCube(double length, double removed_length);

#ifndef SWIG
    CantellatedCube* clone() const override
    {
        return new CantellatedCube(m_length, m_removed_length);
    }
#endif // SWIG

    std::string className() const final { return "CantellatedCube"; }

    double length() const { return m_length; }
    double removedLength() const { return m_removed_length; }

    bool contains(const R3& position) const override;

private:
    double m_length;
    double m_removed_length;
};

//! A cube, with tetrahedral truncation of all corners

class TruncatedCube : public FormfactorPolyhedron {
public:
    TruncatedCube(double length, double removed_length);

#ifndef SWIG
    TruncatedCube* clone() const override { return new TruncatedCube(m_length, m_removed_length); }
#endif // SWIG

    std::string className() const final { return "TruncatedCube"; }

    double length() const { return m_length; }
    double removedLength() const { return m_removed_length; }

    bool contains(const R3& position) const override;

private:
    double m_length;
    double m_removed_length;
};

#endif // BORNAGAIN_SAMPLE_HARDPARTICLE_POLYHEDRA_H
