RaidZeroLib
Coroutine robot framework for VEX V5
Loading...
Searching...
No Matches
rz::DiscretePath Class Reference

Immutable sequence of 2D waypoints with unit-safe geometry. More...

#include <DiscretePath.hpp>

Public Types

using value_type = Point
using const_reference = const Point&
using container_type = std::vector<Point>
using size_type = std::size_t
using const_iterator = std::vector<Point>::const_iterator
using const_reverse_iterator = std::vector<Point>::const_reverse_iterator

Public Member Functions

 DiscretePath (std::initializer_list< Point > waypoints)
 Constructs a path from a brace-initialized list of points.
template<std::ranges::input_range Range>
requires (!std::same_as<std::remove_cvref_t<Range>, DiscretePath> && std::convertible_to<std::ranges::range_reference_t<Range>,
Point>)
 DiscretePath (Range &&range)
 Constructs a path from any C++20 input range of points.
DiscretePath operator+ (const DiscretePath &rhs) const
 Concatenates two paths (this followed by rhs).
DiscretePath operator+ (const Point &rhs) const
 Appends a single waypoint to the end of the path.
const_iterator begin () const noexcept
 Forward begin iterator.
const_iterator end () const noexcept
 Forward end iterator (one past the last).
const_reverse_iterator rbegin () const noexcept
 Reverse begin iterator (last element).
const_reverse_iterator rend () const noexcept
 Reverse end iterator (one before the first).
const_reference operator[] (size_type index) const noexcept
 Random access without bounds checking.
const_reference front () const noexcept
 First waypoint.
const_reference back () const noexcept
 Last waypoint.
Curvature getCurvature (std::size_t index) const noexcept
 Signed curvature at vertex index using the circumcircle of three consecutive points.
size_type size () const noexcept
 Number of waypoints.

Detailed Description

Immutable sequence of 2D waypoints with unit-safe geometry.

DiscretePath stores a read-only ordered list of Point (meters). It supports:

  • Construction from an initializer list or any C++20 range of points,
  • Concatenation with another path or a single point,
  • Const iteration (forward and reverse),
  • Random access and front/back access,
  • Geometric queries such as signed curvature at an interior vertex.
Invariant
Paths are non-empty. All constructors assert size() > 0.
Note
This type is immutable: iteration returns const iterators and no mutating accessors are exposed.

Member Typedef Documentation

◆ const_iterator

using rz::DiscretePath::const_iterator = std::vector<Point>::const_iterator

◆ const_reference

◆ const_reverse_iterator

using rz::DiscretePath::const_reverse_iterator = std::vector<Point>::const_reverse_iterator

◆ container_type

◆ size_type

using rz::DiscretePath::size_type = std::size_t

◆ value_type

Constructor & Destructor Documentation

◆ DiscretePath() [1/2]

rz::DiscretePath::DiscretePath ( std::initializer_list< Point > waypoints)
explicit

Constructs a path from a brace-initialized list of points.

Parameters
waypointsNon-empty list of waypoints (meters).
Precondition
waypoints.size() > 0 (debug-checked).

◆ DiscretePath() [2/2]

template<std::ranges::input_range Range>
requires (!std::same_as<std::remove_cvref_t<Range>, DiscretePath> && std::convertible_to<std::ranges::range_reference_t<Range>,
Point>)
rz::DiscretePath::DiscretePath ( Range && range)
inlineexplicit

Constructs a path from any C++20 input range of points.

Accepts containers and views whose element/reference type is convertible to Point, e.g. std::vector<Point>, std::list<Point>, raw arrays, or range pipelines like points | std::views::filter(...).

Template Parameters
RangeA std::ranges::input_range whose reference is convertible to Point.
Parameters
rangeNon-empty range of waypoints (meters).
Precondition
std::ranges::distance(range) > 0 (debug-checked after construction).
Note
This constructor is disabled for Range = DiscretePath to avoid hijacking copy/move.

Member Function Documentation

◆ back()

const_reference rz::DiscretePath::back ( ) const
noexcept

Last waypoint.

◆ begin()

const_iterator rz::DiscretePath::begin ( ) const
noexcept

Forward begin iterator.

◆ end()

const_iterator rz::DiscretePath::end ( ) const
noexcept

Forward end iterator (one past the last).

◆ front()

const_reference rz::DiscretePath::front ( ) const
noexcept

First waypoint.

◆ getCurvature()

Curvature rz::DiscretePath::getCurvature ( std::size_t index) const
noexcept

Signed curvature at vertex index using the circumcircle of three consecutive points.

For an interior index i (i.e. 1 ≤ i ≤ size()-2), let R = circumradius(P[i-1], P[i], P[i+1]). The unsigned curvature is κ = 1/R. The sign follows the triangle orientation (left turn positive, right turn negative). Endpoints and collinear triples yield 0.

Parameters
indexVertex index at which to evaluate curvature.
Returns
Curvature in 1/meters (Curvature).

◆ operator+() [1/2]

DiscretePath rz::DiscretePath::operator+ ( const DiscretePath & rhs) const

Concatenates two paths (this followed by rhs).

Parameters
rhsPath to append.
Returns
New path containing *this then rhs.

◆ operator+() [2/2]

DiscretePath rz::DiscretePath::operator+ ( const Point & rhs) const

Appends a single waypoint to the end of the path.

Parameters
rhsPoint to append (meters).
Returns
New path with rhs appended.

◆ operator[]()

const_reference rz::DiscretePath::operator[] ( size_type index) const
noexcept

Random access without bounds checking.

Parameters
indexZero-based index in [0, size()).
Returns
Reference to the indexed point.

◆ rbegin()

const_reverse_iterator rz::DiscretePath::rbegin ( ) const
noexcept

Reverse begin iterator (last element).

◆ rend()

const_reverse_iterator rz::DiscretePath::rend ( ) const
noexcept

Reverse end iterator (one before the first).

◆ size()

size_type rz::DiscretePath::size ( ) const
noexcept

Number of waypoints.


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