//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Device/Mask/Shape2D.h
//! @brief     Defines and implements abstract base class for all 2D shapes.
//!
//! @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_DEVICE_MASK_ISHAPE2D_H
#define BORNAGAIN_DEVICE_MASK_ISHAPE2D_H

#include "Base/Type/Cloneable.h"
#include <iostream>

class Bin1D;

//! Abstract base class for all shapes in 2D.

class Shape2D : public Cloneable {
public:
    Shape2D(const char* name)
        : m_name(name)
    {
    }
    ~Shape2D() override = default;

#ifndef SWIG
    Shape2D* clone() const override = 0;
#endif // SWIG

    //! Returns true if point with given coordinates is inside or on border of the shape.
    virtual bool contains(double x, double y) const = 0;

    //! Returns true if area defined by two bins is inside or on border of polygon
    //! (more precisely, if mid point of two bins satisfy this condition).
    virtual bool contains(const Bin1D& binx, const Bin1D& biny) const = 0;

    friend std::ostream& operator<<(std::ostream& ostr, const Shape2D& shape)
    {
        shape.print(ostr);
        return ostr;
    }

protected:
    virtual void print(std::ostream& ostr) const { ostr << m_name; }

private:
    const char* const m_name;
};

#endif // BORNAGAIN_DEVICE_MASK_ISHAPE2D_H
