libtcod
Loading...
Searching...
No Matches
tcod::BresenhamLine Class Reference

Encapsulates a Bresenham line drawing algorithm. More...

#include <bresenham.hpp>

Public Types

using Point2 = std::array<int, 2>
using iterator_category = std::random_access_iterator_tag
using value_type = Point2
using difference_type = int
using pointer = void
using reference = value_type

Public Member Functions

 BresenhamLine (Point2 begin, Point2 end) noexcept
 Construct a new Bresenham line from begin to end.
 BresenhamLine (Point2 begin, Point2 end, int error) noexcept
 Construct a new Bresenham line with a manually given error value.
BresenhamLineoperator++ () noexcept
BresenhamLine operator++ (int) noexcept
BresenhamLineoperator-- () noexcept
BresenhamLine operator-- (int) noexcept
value_type operator[] (int index) noexcept
 Return the world position of the Bresenham at the index relative to the current index.
value_type operator* () noexcept
 Return the world position of the Bresenham at the current index.
constexpr bool operator== (const BresenhamLine &rhs) const noexcept
constexpr bool operator!= (const BresenhamLine &rhs) const noexcept
constexpr difference_type operator- (const BresenhamLine &rhs) const noexcept
BresenhamLine adjust_range (int shift_begin, int shift_end) const noexcept
BresenhamLine without_start () const noexcept
BresenhamLine without_end () const noexcept
BresenhamLine without_endpoints () const noexcept
BresenhamLine begin () const noexcept
 Return the beginning iterator, which is a copy of the current object.
BresenhamLine end () const noexcept
 Return the past-the-end iterator.

Detailed Description

Encapsulates a Bresenham line drawing algorithm.

embed:rst:leading-asterisk 
.. versionadded:: 1.17

Constructor & Destructor Documentation

◆ BresenhamLine()

tcod::BresenhamLine::BresenhamLine ( Point2 begin,
Point2 end )
inlineexplicitnoexcept

Construct a new Bresenham line from begin to end.

Iterating over this instance will include both endpoints.

Member Function Documentation

◆ adjust_range()

BresenhamLine tcod::BresenhamLine::adjust_range ( int shift_begin,
int shift_end ) const
inlinenoexcept
  Return a new version of this BresenhamLine with an adjusted range.

  `shift_begin` and `shift_end` change the beginning and ending of the line
  when iterators over.

  Example::

Remove the endpoints of a bresenham line. auto line = tcod::BresenhamLine(from, to).adjust_range(1, -1);

◆ operator[]()

value_type tcod::BresenhamLine::operator[] ( int index)
inlinenoexcept

Return the world position of the Bresenham at the index relative to the current index.

BresenhamLine is not restricted by any bounds so you can freely give a index past the end or before zero.

The internal state must always seek to the position being indexed, this will affect performance depending on if successive indexes are close together or far apart.

◆ without_end()

BresenhamLine tcod::BresenhamLine::without_end ( ) const
inlinenoexcept
  Remove the final endpoint of a line.

  Example::

    for (auto&& [x, y] : tcod::BresenhamLine(from, to).without_end()) {

All positions excluding to. }

◆ without_endpoints()

BresenhamLine tcod::BresenhamLine::without_endpoints ( ) const
inlinenoexcept
  Remove both endpoints of a line.

  Example::

    for (auto&& [x, y] : tcod::BresenhamLine(from, to).without_endpoints()) {

All positions between and excluding from and to. }

◆ without_start()

BresenhamLine tcod::BresenhamLine::without_start ( ) const
inlinenoexcept
  Remove the staring endpoint of a line.

  Example::

    for (auto&& [x, y] : tcod::BresenhamLine(from, to).without_start()) {

All positions excluding from. }


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