Medusa  1.1
Coordinate Free Mehless Method implementation
PolygonShape_fwd.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_DOMAINS_POLYGONSHAPE_FWD_HPP_
2 #define MEDUSA_BITS_DOMAINS_POLYGONSHAPE_FWD_HPP_
3 
4 #include <medusa/Config.hpp>
5 #include "DomainShape_fwd.hpp"
6 
14 namespace mm {
15 
26 template <typename vec_t>
27 class PolygonShape : public DomainShape<vec_t> {
28  static_assert(vec_t::dim == 2, "Only available in 2 dimensions.");
30 
31  std::vector<vec_t> points_;
32  std::vector<vec_t> points_with_margin_;
36 
37  public:
38  using typename base_t::scalar_t;
39  using typename base_t::vector_t;
40  using base_t::dim;
43 
50  explicit PolygonShape(const std::vector<vec_t>& points);
51 
53  const std::vector<vec_t>& points() const { return points_; }
54 
56  void setMargin(scalar_t margin) override;
57 
62  bool contains(const vec_t& point) const override;
63 
64  std::pair<vec_t, vec_t> bbox() const override;
65 
72 
79  const std::function<scalar_t(vec_t)>& dr, int type) const override;
80 
81  PolygonShape<vec_t>* clone() const override { return new PolygonShape<vec_t>(*this); }
82 
83  std::ostream& print(std::ostream& os) const override {
84  return os << "Polygon shape with " << points_.size() << " points.";
85  }
86 
87  private:
94  static inline scalar_t isLeft(const vec_t& P0, const vec_t& P1, const vec_t& P2) {
95  return (P1[0] - P0[0]) * (P2[1] - P0[1]) - (P2[0] - P0[0]) * (P1[1] - P0[1]);
96  }
97 
99  void extendByMargin();
100 };
101 
102 } // namespace mm
103 
104 #endif // MEDUSA_BITS_DOMAINS_POLYGONSHAPE_FWD_HPP_
mm::PolygonShape::clone
PolygonShape< vec_t > * clone() const override
Polymorphic clone pattern.
Definition: PolygonShape_fwd.hpp:81
mm::PolygonShape::discretizeBoundaryWithDensity
DomainDiscretization< vec_t > discretizeBoundaryWithDensity(const std::function< scalar_t(vec_t)> &dr, int type) const override
Returns a discretization of the boundary of this shape with approximately uniform distance step betwe...
Definition: PolygonShape.hpp:118
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
scalar_t
Scalar scalar_t
Type of the elements, alias of Scalar.
Definition: MatrixBaseAddons.hpp:16
mm::DomainDiscretization
Class representing domain discretization along with an associated shape.
Definition: DomainDiscretization_fwd.hpp:46
mm::PolygonShape::discretizeBoundaryWithStep
DomainDiscretization< vec_t > discretizeBoundaryWithStep(scalar_t step, int type) const override
Returns a discretization of the boundary of this shape with approximately uniform distance step betwe...
Definition: PolygonShape.hpp:89
dim
@ dim
Number of elements of this matrix.
Definition: MatrixBaseAddons.hpp:14
mm::PolygonShape
Shape representing a simple (i.e. non self intersecting) nonempty polygon in 2D, which is given as a ...
Definition: PolygonShape_fwd.hpp:27
mm::DomainShape::dim
@ dim
Dimensionality of the domain.
Definition: DomainShape_fwd.hpp:57
mm::PolygonShape::PolygonShape
PolygonShape(const std::vector< vec_t > &points)
Create polygon given a sequence of points.
Definition: PolygonShape.hpp:17
mm::DomainShape
Base class for geometric shapes of domains.
Definition: DomainShape_fwd.hpp:52
Config.hpp
mm::PolygonShape::points_with_margin_
std::vector< vec_t > points_with_margin_
Polygon extended by margin_, for contains checks.
Definition: PolygonShape_fwd.hpp:34
mm::DomainShape::vector_t
vec_t vector_t
Vector data type used in computations.
Definition: DomainShape_fwd.hpp:54
mm::DomainShape::discretizeBoundaryWithDensity
virtual DomainDiscretization< vec_t > discretizeBoundaryWithDensity(const std::function< scalar_t(vec_t)> &dr, int type) const =0
Discretizes boundary with given density and fill engine.
mm::PolygonShape::points
const std::vector< vec_t > & points() const
Get points representing the polygon.
Definition: PolygonShape_fwd.hpp:53
mm::PolygonShape::points_
std::vector< vec_t > points_
The points that define the polygon, stored in CCW order.
Definition: PolygonShape_fwd.hpp:31
mm::DomainShape::discretizeBoundaryWithStep
virtual DomainDiscretization< vec_t > discretizeBoundaryWithStep(scalar_t step, int type) const
Returns a discretization of the boundary of this shape with approximately uniform distance step betwe...
Definition: DomainShape_fwd.hpp:118
mm::PolygonShape::extendByMargin
void extendByMargin()
Save a version of points extended by margin_ for later contains checks.
Definition: PolygonShape.hpp:39
mm::PolygonShape::contains
bool contains(const vec_t &point) const override
Winding number test for point in a polygon inclusion (paying respect to margin).
Definition: PolygonShape.hpp:54
mm::DomainShape::margin
scalar_t margin() const
Returns current margin.
Definition: DomainShape_fwd.hpp:72
mm::PolygonShape::setMargin
void setMargin(scalar_t margin) override
Computes the polygon extended by margin as well.
Definition: PolygonShape.hpp:33
mm::PolygonShape::bbox
std::pair< vec_t, vec_t > bbox() const override
Return the bounding box of the domain.
Definition: PolygonShape.hpp:76
mm::PolygonShape::isLeft
static scalar_t isLeft(const vec_t &P0, const vec_t &P1, const vec_t &P2)
Tests if a point is left, on, or right of an infinite line.
Definition: PolygonShape_fwd.hpp:94
mm::DomainShape::scalar_t
vec_t::Scalar scalar_t
Scalar data type used in computation.
Definition: DomainShape_fwd.hpp:55
DomainShape_fwd.hpp
mm::PolygonShape::print
std::ostream & print(std::ostream &os) const override
Output information about this shape to given output stream os.
Definition: PolygonShape_fwd.hpp:83