Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
vulpes::geometry::dist2d::PolygonDistance< FloatType > Class Template Reference

Signed distance function for a polygon in 2D space. More...

#include <distance.hpp>

Inheritance diagram for vulpes::geometry::dist2d::PolygonDistance< FloatType >:
[legend]
Collaboration diagram for vulpes::geometry::dist2d::PolygonDistance< FloatType >:
[legend]

Public Member Functions

 PolygonDistance (const std::vector< Point< FloatType, 2 > > &vertices)
 Constructor for the polygon distance function.
void operator() (const Point< FloatType, 2 > &point, FloatType *distance_buffer) const
 Compute the signed distance between a point and the polygon.
std::array< Point< FloatType, 2 >, 2 > bbox () const
 Get the bounding box of the polygon.
void operator() (const Point< FloatType, Dim > &point, FloatType *distance_buffer) const
 Evaluate the distance function for the given point.

Static Public Member Functions

static constexpr size_t size ()
 Get the size of the distance buffer for this distance function.

Static Public Attributes

static constexpr size_t max_edges = 2000
 Largest number of edges: the buffer size is a compile-time constant.
static constexpr bool is_leaf = true
 A flag indicating that this is a leaf node in a composite expression. Indeed we give an explicit formula to compute the distance.

Private Member Functions

bool hasIntersectingEdges () const
 True if two edges that are not consecutive cross or touch.

Private Attributes

const std::vector< Point< FloatType, 2 > > m_vertices
 The vertices of the polygon.
FloatType m_outward_sign
 Makes the edge distances positive outward.

Detailed Description

template<typename FloatType>
class vulpes::geometry::dist2d::PolygonDistance< FloatType >

Signed distance function for a polygon in 2D space.

This class computes the signed distance between a point and a polygon, convex or concave, without holes and without self-intersections. The distance is negative inside the polygon and on its boundary, positive outside, and its magnitude is the distance to the closest point of the boundary.

The buffer also holds, for each edge, the signed distance to the line through that edge, negative on the inner side: VulPoly reflects the seeds across these lines, whose normal stays constant near the corners. The slots after the last edge hold the largest value, so that VulPoly ignores them.

Template Parameters
FloatTypeThe type of floating-point value.

Constructor & Destructor Documentation

◆ PolygonDistance()

template<typename FloatType>
vulpes::geometry::dist2d::PolygonDistance< FloatType >::PolygonDistance ( const std::vector< Point< FloatType, 2 > > & vertices)
inlineexplicit

Constructor for the polygon distance function.

Parameters
verticesThe vertices in order, in either orientation, without repeating the first one at the end.
Exceptions
std::invalid_argumentif there are fewer than 3 or more than max_edges vertices, if the enclosed area is zero, or if two edges that are not consecutive cross or touch.

Member Function Documentation

◆ bbox()

template<typename FloatType>
std::array< Point< FloatType, 2 >, 2 > vulpes::geometry::dist2d::PolygonDistance< FloatType >::bbox ( ) const
inline

Get the bounding box of the polygon.

Returns
The bounding box as an array of two points.

◆ hasIntersectingEdges()

template<typename FloatType>
bool vulpes::geometry::dist2d::PolygonDistance< FloatType >::hasIntersectingEdges ( ) const
inlineprivate

True if two edges that are not consecutive cross or touch.

◆ operator()() [1/2]

template<typename FloatType>
void vulpes::geometry::dist2d::PolygonDistance< FloatType >::operator() ( const Point< FloatType, 2 > & point,
FloatType * distance_buffer ) const
inline

Compute the signed distance between a point and the polygon.

Parameters
pointThe point for which the distance is to be computed.
distance_bufferThe buffer where the computed distances will be stored.

◆ operator()() [2/2]

void vulpes::geometry::DistanceExpression< FloatType, Dim, PolygonDistance< FloatType > >::operator() ( const Point< FloatType, Dim > & point,
FloatType * distance_buffer ) const
inlineinherited

Evaluate the distance function for the given point.

This function computes the signed distance between a point and the shape defined by the Distance type. The result is stored in the provided distance_buffer.

Parameters
pointThe point for which the distance needs to be computed.
distance_bufferThe buffer where the computed distances will be stored.

◆ size()

template<typename FloatType>
constexpr size_t vulpes::geometry::dist2d::PolygonDistance< FloatType >::size ( )
inlinestaticconstexpr

Get the size of the distance buffer for this distance function.

Returns
The size of the buffer (one entry per possible edge plus one for the polygon distance).

Member Data Documentation

◆ is_leaf

template<typename FloatType>
bool vulpes::geometry::dist2d::PolygonDistance< FloatType >::is_leaf = true
staticconstexpr

A flag indicating that this is a leaf node in a composite expression. Indeed we give an explicit formula to compute the distance.

◆ m_outward_sign

template<typename FloatType>
FloatType vulpes::geometry::dist2d::PolygonDistance< FloatType >::m_outward_sign
private

Makes the edge distances positive outward.

◆ m_vertices

template<typename FloatType>
const std::vector<Point<FloatType, 2> > vulpes::geometry::dist2d::PolygonDistance< FloatType >::m_vertices
private

The vertices of the polygon.

◆ max_edges

template<typename FloatType>
size_t vulpes::geometry::dist2d::PolygonDistance< FloatType >::max_edges = 2000
staticconstexpr

Largest number of edges: the buffer size is a compile-time constant.


The documentation for this class was generated from the following file: