Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Regular_Polygon::Segment_Iterator Class Reference

Iterator over the edges (segments) of a regular polygon. More...

#include <polygon.H>

Collaboration diagram for Regular_Polygon::Segment_Iterator:
[legend]

Public Member Functions

 Segment_Iterator (const Regular_Polygon &__poly)
 Construct segment iterator from a regular polygon.
 
bool has_curr () const
 Check if there is a current segment.
 
const Segment get_current_segment () const
 Get the current segment (edge).
 
void next_ne () noexcept
 Advance to next segment (no exception on overflow).
 
void next ()
 Advance to next segment.
 
void prev ()
 Move to previous segment.
 

Private Attributes

const Regular_Polygonpoly
 Reference to the polygon.
 
size_t curr
 Current segment index.
 

Detailed Description

Iterator over the edges (segments) of a regular polygon.

This iterator provides the same interface as Polygon::Segment_Iterator to enable generic code that works with both polygon types.

Regular_Polygon hex(Point(0, 0), 50, 6);
for (Regular_Polygon::Segment_Iterator it(hex); it.has_curr(); it.next())
std::cout << it.get_current_segment().to_string() << "\n";
Rectangular point in the plane.
Definition point.H:156
Iterator over the edges (segments) of a regular polygon.
Definition polygon.H:1010
bool has_curr() const
Check if there is a current segment.
Definition polygon.H:1025
A regular polygon defined by center, side length, and vertex count.
Definition polygon.H:829

Definition at line 1009 of file polygon.H.

Constructor & Destructor Documentation

◆ Segment_Iterator()

Regular_Polygon::Segment_Iterator::Segment_Iterator ( const Regular_Polygon __poly)
inline

Construct segment iterator from a regular polygon.

Parameters
__polyThe polygon to iterate over.

Definition at line 1017 of file polygon.H.

Member Function Documentation

◆ get_current_segment()

const Segment Regular_Polygon::Segment_Iterator::get_current_segment ( ) const
inline

Get the current segment (edge).

Returns
The segment from current vertex to the next.
Exceptions
std::overflow_errorIf no current segment exists.

Definition at line 1030 of file polygon.H.

References ah_overflow_error_if, curr, Regular_Polygon::get_vertex(), has_curr(), Aleph::maps(), poly, and Regular_Polygon::size().

Referenced by TEST_F(), and TEST_F().

◆ has_curr()

bool Regular_Polygon::Segment_Iterator::has_curr ( ) const
inline

Check if there is a current segment.

Returns
True if a current segment exists.

Definition at line 1025 of file polygon.H.

References curr, poly, and Regular_Polygon::size().

Referenced by get_current_segment(), next(), prev(), TEST_F(), and TEST_F().

◆ next()

void Regular_Polygon::Segment_Iterator::next ( )
inline

Advance to next segment.

Exceptions
std::overflow_errorIf already at end.

Definition at line 1044 of file polygon.H.

References ah_overflow_error_if, has_curr(), Aleph::maps(), and next_ne().

Referenced by TEST_F().

◆ next_ne()

void Regular_Polygon::Segment_Iterator::next_ne ( )
inlinenoexcept

Advance to next segment (no exception on overflow).

Definition at line 1040 of file polygon.H.

References curr.

Referenced by next(), TEST_F(), and TEST_F().

◆ prev()

void Regular_Polygon::Segment_Iterator::prev ( )
inline

Move to previous segment.

Exceptions
std::underflow_errorIf already at beginning.

Definition at line 1053 of file polygon.H.

References ah_underflow_error_if, curr, has_curr(), and Aleph::maps().

Member Data Documentation

◆ curr

size_t Regular_Polygon::Segment_Iterator::curr
private

Current segment index.

Definition at line 1012 of file polygon.H.

Referenced by get_current_segment(), has_curr(), next_ne(), and prev().

◆ poly

const Regular_Polygon& Regular_Polygon::Segment_Iterator::poly
private

Reference to the polygon.

Definition at line 1011 of file polygon.H.

Referenced by get_current_segment(), and has_curr().


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