#ifndef MEDUSA_BITS_DOMAINS_TRANSLATEDSHAPE_FWD_HPP_ #define MEDUSA_BITS_DOMAINS_TRANSLATEDSHAPE_FWD_HPP_ #include #include #include "DomainShape_fwd.hpp" /** * @file * Declaration of class for translated domain shapes. * * @example test/domains/TranslatedShape_test.cpp */ namespace mm { /** * Class for working with translated domain shapes. An existing domain shape can be translated * to another point in the space, along with correctly working `contains` and discretization * methods. * * Usage example: * @snippet domains/TranslatedShape_test.cpp TranslatedShape usage example * @ingroup domains */ template class TranslatedShape : public DomainShape { deep_copy_unique_ptr> sh; ///< Shape to be translated. vec_t a; ///< Translation vector public: /** * Construct a translated shape by specifying a shape and a translation vector. * Can be easily constructed using DomainShape::translate or DomainDiscretization::translate. */ TranslatedShape(const DomainShape& sh, const vec_t& a); using typename DomainShape::scalar_t; using DomainShape::dim; using DomainShape::discretizeBoundaryWithDensity; using DomainShape::discretizeWithDensity; using DomainShape::discretizeBoundaryWithStep; using DomainShape::discretizeWithStep; bool contains(const vec_t& point) const override { return sh->contains(point-a); } bool hasContains() const override { return sh->hasContains(); } std::pair bbox() const override { auto bb = sh->bbox(); return {bb.first+a, bb.second+a}; } TranslatedShape* clone() const override { return new TranslatedShape(*this); } std::ostream& print(std::ostream& os) const override { return os << "Shape " << *sh << " translated by " << a; } DomainDiscretization discretizeBoundaryWithStep(scalar_t step, int type) const override; DomainDiscretization discretizeWithStep(scalar_t step, int internal_type, int boundary_type) const override; DomainDiscretization discretizeWithDensity( const std::function& dr, int internal_type, int boundary_type) const override; DomainDiscretization discretizeBoundaryWithDensity( const std::function& dr, int type) const override; /// Returns the underlying shape. const DomainShape& shape() const { return *sh; } /// Returns the translation vector. vec_t translation() const { return a; } }; } // namespace mm #endif // MEDUSA_BITS_DOMAINS_TRANSLATEDSHAPE_FWD_HPP_