The SKIRT project
advanced radiative transfer for astrophysics
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
ConvexPolygon Class Reference

#include <ConvexPolygon.hpp>

Public Member Functions

 ConvexPolygon ()
 
void add (double x, double y)
 
double bottom () const
 
size_t count () const
 
double leftFor (double y) const
 
double rightFor (double y) const
 
double top () const
 
double x (size_t i) const
 
double y (size_t i) const
 

Static Public Attributes

static constexpr size_t maxPoints
 

Private Attributes

size_t _botIndex
 
size_t _n
 
size_t _topIndex
 
std::array< double, maxPoints_xv
 
std::array< double, maxPoints_yv
 

Detailed Description

The ConvexPolygon class represents a planar convex polygon, and provides support for extracting specific properties such as the bottom-most and top-most points. There is a (fairly small) compile-time limit on the number of points to avoid memory allocation on the heap. The user should ensure that at least 3 and at most maxPoints points are added to the polygon, that they are added in consecutive clockwise order, that there is a nontrivial distance between all points, and that the resulting polygon is convex. If these restrictions are violated, the behavior of some of the functions in this class is undefined.

Constructor & Destructor Documentation

◆ ConvexPolygon()

ConvexPolygon::ConvexPolygon ( )

Constructs an empty polygon. Use the add() function to add points to the polygon.

Member Function Documentation

◆ add()

void ConvexPolygon::add ( double  x,
double  y 
)

Adds a point to the polygon. The user should ensure that at least 3 and at most 8 points are added to the polygon, that they are added in consecutive clockwise order, that there is a nontrivial distance between all points, and that the resulting polygon is convex.

◆ bottom()

double ConvexPolygon::bottom ( ) const
inline

Returns the bottom-most y-coordinate of the polygon.

◆ count()

size_t ConvexPolygon::count ( ) const
inline

Returns the number of points in the polygon.

◆ leftFor()

double ConvexPolygon::leftFor ( double  y) const

Returns the x-coordinate for the left-hand intersection point of the polygon with the horizontal line at the specified y-coordinate. If the specified y-coordinate is out of range, the x-coordinate of the top or bottom point is returned.

◆ rightFor()

double ConvexPolygon::rightFor ( double  y) const

Returns the x-coordinate for the right-hand intersection point of the polygon with the horizontal line at the specified y-coordinate. If the specified y-coordinate is out of range, the x-coordinate of the top or bottom point is returned.

◆ top()

double ConvexPolygon::top ( ) const
inline

Returns the top-most y-coordinate of the polygon.

◆ x()

double ConvexPolygon::x ( size_t  i) const
inline

Returns the x-coordinate of the point at the specified zero-based index.

◆ y()

double ConvexPolygon::y ( size_t  i) const
inline

Returns the y-coordinate of the point at the specified zero-based index.

Member Data Documentation

◆ maxPoints

constexpr size_t ConvexPolygon::maxPoints
staticconstexpr

The maximum number of points that can be held by a polygon object.


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