Class BresenhamLine

Nested Relationships

Nested Types

Class Documentation

class BresenhamLine

Encapsulates a Bresenham line drawing algorithm.

New in version 1.17.

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 Functions

inline explicit BresenhamLine(Point2 begin, Point2 end) noexcept

Construct a new Bresenham line from begin to end.

Iterating over this instance will include both endpoints.

inline explicit BresenhamLine(Point2 begin, Point2 end, int error) noexcept

Construct a new Bresenham line with a manually given error value.

inline BresenhamLine &operator++() noexcept
inline BresenhamLine operator++(int) noexcept
inline BresenhamLine &operator--() noexcept
inline BresenhamLine operator--(int) noexcept
inline value_type operator[](int index) noexcept

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.

inline value_type operator*() noexcept

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

inline constexpr bool operator==(const BresenhamLine &rhs) const noexcept
inline constexpr bool operator!=(const BresenhamLine &rhs) const noexcept
inline constexpr difference_type operator-(const BresenhamLine &rhs) const noexcept
inline BresenhamLine adjust_range(int shift_begin, int shift_end) const noexcept

  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);

inline BresenhamLine without_start() const noexcept

  Remove the staring endpoint of a line.

  Example::

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

inline BresenhamLine without_end() const noexcept

  Remove the final endpoint of a line.

  Example::

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

inline BresenhamLine without_endpoints() const noexcept

  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. }

inline BresenhamLine begin() const noexcept

Return the beginning iterator, which is a copy of the current object.

inline BresenhamLine end() const noexcept

Return the past-the-end iterator.