#ifndef MEDUSA_BITS_DOMAINS_SHAPEDIFFERENCE_FWD_HPP_ #define MEDUSA_BITS_DOMAINS_SHAPEDIFFERENCE_FWD_HPP_ #include #include "DomainShape_fwd.hpp" /** * @file * Declaration of ShapeDifference class. * * @example test/domains/ShapeDifference_test.cpp */ namespace mm { /** * A class representing a set-difference of two shapes. Used when constructing shapes * for later discretization or obtained implicitly with * DomainShape::operator-(), DomainShape::subtract() and DomainDiscretization::subtract(). * * Usage example: * @snippet domains/ShapeDifference_test.cpp ShapeDifference usage example * @sa ShapeUnion, DomainShape, DomainDiscretization * @ingroup domains */ template class ShapeDifference : public DomainShape { deep_copy_unique_ptr> sh1, ///< First shape. sh2; ///< Second shape. public: using typename DomainShape::scalar_t; using DomainShape::dim; using DomainShape::discretizeBoundaryWithDensity; using DomainShape::discretizeWithDensity; using DomainShape::discretizeBoundaryWithStep; using DomainShape::discretizeWithStep; /// Constructs a shape representing `shape1 - shape2`. ShapeDifference(const DomainShape& shape1, const DomainShape& shape2) : sh1(shape1), sh2(shape2) { sh2->setMargin(-sh2->margin()); } /// Access the first shape. const DomainShape& first() const { return *sh1; } /// Access the second shape. const DomainShape& second() const { return *sh2; } bool contains(const vec_t& point) const override { return sh1->contains(point) && !sh2->contains(point); } bool hasContains() const override { return sh1->hasContains() && sh2->hasContains(); } DomainDiscretization discretizeBoundaryWithStep(scalar_t step, int type) const override; DomainDiscretization discretizeWithStep( scalar_t step, int internal_type, int boundary_type) const override; DomainDiscretization discretizeBoundaryWithDensity( const std::function& dr, int type) const override; DomainDiscretization discretizeWithDensity( const std::function& dr, int internal_type, int boundary_type) const override; std::pair bbox() const override { return sh1->bbox(); } ShapeDifference* clone() const override { return new ShapeDifference(*this); } std::ostream& print(std::ostream& os) const override; }; } // namespace mm #endif // MEDUSA_BITS_DOMAINS_SHAPEDIFFERENCE_FWD_HPP_