Recti 1.2.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
recti::Polygon< T > Class Template Reference

Polygon. More...

#include <polygon.hpp>

Public Member Functions

constexpr Polygon ()=default
 Default constructor.
 
constexpr Polygon (Point< T > origin, std::vector< Vector2< T > > vecs)
 Constructs a new Polygon object from origin and vectors.
 
constexpr Polygon (std::span< const Point< T > > pointset)
 Constructs a new Polygon object from a set of points.
 
constexpr bool operator== (const Polygon &rhs) const
 Equality comparison operator.
 
constexpr bool operator!= (const Polygon &rhs) const
 Inequality comparison operator.
 
constexpr auto operator+= (const Vector2< T > &rhs) -> Polygon &
 Adds a vector to the origin of the polygon, effectively translating the polygon.
 
constexpr auto operator-= (const Vector2< T > &rhs) -> Polygon &
 Subtracts a vector from the origin of the polygon, effectively translating the polygon.
 
constexpr auto signed_area_x2 () const -> T
 Calculates the signed area of the polygon multiplied by 2.
 
constexpr const Point< T > & origin () const
 Gets the origin point of the polygon.
 
constexpr const std::vector< Vector2< T > > & vectors () const
 Gets the displacement vectors of the polygon.
 
constexpr auto vertices () const -> std::vector< Point< T > >
 Gets all vertices of the polygon as points.
 
constexpr auto is_rectilinear () const -> bool
 Checks if the polygon is rectilinear.
 
constexpr auto is_convex () const -> bool
 Checks if the polygon is convex.
 

Detailed Description

template<typename T>
class recti::Polygon< T >

Polygon.

Polygon is a class template that represents an arbitrary polygon. It stores the origin point and a vector of edges that define the polygon. The template parameter T specifies the type of the coordinates of the points.

Template Parameters
T

Constructor & Destructor Documentation

◆ Polygon() [1/3]

template<typename T >
constexpr recti::Polygon< T >::Polygon ( )
constexprdefault

Default constructor.

◆ Polygon() [2/3]

template<typename T >
constexpr recti::Polygon< T >::Polygon ( Point< T >  origin,
std::vector< Vector2< T > >  vecs 
)
inlineconstexpr

Constructs a new Polygon object from origin and vectors.

Parameters
[in]originThe origin point of the polygon
[in]vecsVector of displacement vectors from origin

◆ Polygon() [3/3]

template<typename T >
constexpr recti::Polygon< T >::Polygon ( std::span< const Point< T > >  pointset)
inlineexplicitconstexpr

Constructs a new Polygon object from a set of points.

This constructor takes a std::span of Point<T> objects representing the vertices of the polygon. The first point in the span is used as the origin of the polygon, and the remaining points are used to construct the edges of the polygon as vectors relative to the origin.

Parameters
[in]pointsetA span of points representing the vertices of the polygon.

Member Function Documentation

◆ is_convex()

template<typename T >
constexpr auto recti::Polygon< T >::is_convex ( ) const -> bool
inlineconstexpr

Checks if the polygon is convex.

A polygon is convex if all its interior angles are less than or equal to 180 degrees.

Returns
true if the polygon is convex, false otherwise.

◆ is_rectilinear()

template<typename T >
constexpr auto recti::Polygon< T >::is_rectilinear ( ) const -> bool
inlineconstexpr

Checks if the polygon is rectilinear.

A polygon is rectilinear if all its edges are either horizontal or vertical.

Returns
true if the polygon is rectilinear, false otherwise.

◆ operator!=()

template<typename T >
constexpr bool recti::Polygon< T >::operator!= ( const Polygon< T > &  rhs) const
inlineconstexpr

Inequality comparison operator.

◆ operator+=()

template<typename T >
constexpr auto recti::Polygon< T >::operator+= ( const Vector2< T > &  rhs) -> Polygon&
inlineconstexpr

Adds a vector to the origin of the polygon, effectively translating the polygon.

Parameters
[in]rhsThe vector to add to the origin.
Returns
A reference to the modified polygon.

◆ operator-=()

template<typename T >
constexpr auto recti::Polygon< T >::operator-= ( const Vector2< T > &  rhs) -> Polygon&
inlineconstexpr

Subtracts a vector from the origin of the polygon, effectively translating the polygon.

Parameters
[in]rhsThe vector to subtract from the origin.
Returns
A reference to the modified polygon.

◆ operator==()

template<typename T >
constexpr bool recti::Polygon< T >::operator== ( const Polygon< T > &  rhs) const
inlineconstexpr

Equality comparison operator.

◆ origin()

template<typename T >
constexpr const Point< T > & recti::Polygon< T >::origin ( ) const
inlineconstexpr

Gets the origin point of the polygon.

◆ signed_area_x2()

template<typename T >
constexpr auto recti::Polygon< T >::signed_area_x2 ( ) const -> T
inlineconstexpr

Calculates the signed area of the polygon multiplied by 2.

This function calculates the signed area of the polygon by summing the cross products of adjacent edges. The result is multiplied by 2 to avoid the need for floating-point arithmetic.

Returns
The signed area of the polygon multiplied by 2.

◆ vectors()

template<typename T >
constexpr const std::vector< Vector2< T > > & recti::Polygon< T >::vectors ( ) const
inlineconstexpr

Gets the displacement vectors of the polygon.

◆ vertices()

template<typename T >
constexpr auto recti::Polygon< T >::vertices ( ) const -> std::vector<Point<T>>
inlineconstexpr

Gets all vertices of the polygon as points.


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